From f78530636e375c1eefe8a7907fd5d46fece65310 Mon Sep 17 00:00:00 2001 From: khoa-nd Date: Thu, 5 Mar 2015 15:53:02 +0700 Subject: [PATCH 1/2] Add method to get the list of languages using in repository --- src/main/java/org/kohsuke/github/GHRepository.java | 12 ++++++++++++ src/test/java/org/kohsuke/github/RepositoryTest.java | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 8570a09bb1..a89fe11569 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -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 listLanguages() throws IOException { + return root.retrieve().to(getApiTailUrl("languages"), HashMap.class); + } + public String getOwnerName() { return owner.login; } diff --git a/src/test/java/org/kohsuke/github/RepositoryTest.java b/src/test/java/org/kohsuke/github/RepositoryTest.java index 6862ace7be..61cdc09dca 100644 --- a/src/test/java/org/kohsuke/github/RepositoryTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryTest.java @@ -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)); + } } From 374fdb37e181e8e0236636a1b4516f97b1e2dd11 Mon Sep 17 00:00:00 2001 From: khoa-nd Date: Fri, 6 Mar 2015 09:11:03 +0700 Subject: [PATCH 2/2] Change type of language bytes from Integer to Long --- src/main/java/org/kohsuke/github/GHRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index a89fe11569..1c62c6c4d5 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -293,7 +293,7 @@ protected void wrapUp(GHTag[] page) { "Python": 7769 } */ - public Map listLanguages() throws IOException { + public Map listLanguages() throws IOException { return root.retrieve().to(getApiTailUrl("languages"), HashMap.class); }