Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit f785306

Browse files
committed
Add method to get the list of languages using in repository
1 parent dcc3b7f commit f785306

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ protected void wrapUp(GHTag[] page) {
285285
};
286286
}
287287

288+
/**
289+
* List languages for the specified repository.
290+
* The value on the right of a language is the number of bytes of code written in that language.
291+
* {
292+
"C": 78769,
293+
"Python": 7769
294+
}
295+
*/
296+
public Map<String,Integer> listLanguages() throws IOException {
297+
return root.retrieve().to(getApiTailUrl("languages"), HashMap.class);
298+
}
299+
288300
public String getOwnerName() {
289301
return owner.login;
290302
}

src/test/java/org/kohsuke/github/RepositoryTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ public void listContributors() throws IOException {
4343
private GHRepository getRepository() throws IOException {
4444
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
4545
}
46+
47+
@Test
48+
public void listLanguages() throws IOException {
49+
GHRepository r = gitHub.getRepository("kohsuke/github-api");
50+
String mainLanguage = r.getLanguage();
51+
assertTrue(r.listLanguages().containsKey(mainLanguage));
52+
}
4653
}

0 commit comments

Comments
 (0)