Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get the list of languages using in repository #161

Merged
merged 2 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ protected void wrapUp(GHTag[] page) {
};
}

/**
* List languages for the specified repository.
* The value on the right of a language is the number of bytes of code written in that language.
* {
"C": 78769,
"Python": 7769
}
*/
public Map<String,Integer> listLanguages() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size in bytes, max Integer will be 2Gb, i think some crazy repo may have such number. Long looks better.

return root.retrieve().to(getApiTailUrl("languages"), HashMap.class);
}

public String getOwnerName() {
return owner.login;
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/kohsuke/github/RepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public void listContributors() throws IOException {
private GHRepository getRepository() throws IOException {
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
}

@Test
public void listLanguages() throws IOException {
GHRepository r = gitHub.getRepository("kohsuke/github-api");
String mainLanguage = r.getLanguage();
assertTrue(r.listLanguages().containsKey(mainLanguage));
}
}