From c8b0584127303533f9918cacdcb6eafb72e6c270 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 29 Aug 2018 21:05:31 -0700 Subject: [PATCH 1/9] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a0428a8a09..3de2dfea24 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.94 + 1.95-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - github-api-1.94 + HEAD From 1c4b716f1a5f83f285b8a2029b334f3c942ddd71 Mon Sep 17 00:00:00 2001 From: Even Holthe Date: Mon, 1 Oct 2018 23:24:42 +0200 Subject: [PATCH 2/9] Add methods for adding/removing labels to GHIssue Fixes #456 --- src/main/java/org/kohsuke/github/GHIssue.java | 74 ++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index f7cfd9245c..2fde68a672 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -24,19 +24,20 @@ package org.kohsuke.github; +import static org.kohsuke.github.Previews.SQUIRREL_GIRL; + import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - import java.io.IOException; import java.net.URL; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Locale; - -import static org.kohsuke.github.Previews.*; +import java.util.Set; /** * Represents an issue on GitHub. @@ -216,6 +217,73 @@ public void setLabels(String... labels) throws IOException { editIssue("labels",labels); } + /** + * Adds a label to the issue. If it does not exist in the {@link GHRepository}, it will be + * created with the specified color. If either {@code name} or {@code color} is null, it will + * be a NOP. + * + * @param name Name of the label + * @param color Hex code of the label, without # + */ + public void addLabel(String name, String color) throws IOException { + if (name != null && color != null) { + // All labels that we have seen + Set repoLabels = new HashSet(); + Set seenLabels = new HashSet(); + + // Check if label already exists + for (GHLabel repoLabel : getRepository().listLabels().asSet()) { + repoLabels.add(repoLabel.getName()); + } + + // Label does not exist + if (!repoLabels.contains(name)) { + GHLabel newLabel = getRepository().createLabel(name, color); + repoLabels.add(newLabel.getName()); + seenLabels.add(newLabel.getName()); + } + + // See if label exists on issue already + boolean foundInIssue = false; + + for (GHLabel existingIssueLabel : getLabels()) { + if (existingIssueLabel.getName().equalsIgnoreCase(name)) { + foundInIssue = true; + } + + seenLabels.add(existingIssueLabel.getName()); + } + + // If the label doesn't exist in the issue, add it + if (!foundInIssue) { + seenLabels.add(name); + setLabels(seenLabels.toArray(new String[0])); + } + } + } + + /** + * @see #removeLabel(String) + */ + public void removeLabel(Label label) throws IOException { + removeLabel(label.getName()); + } + + /** + * Remove a given label by name from this issue. + */ + public void removeLabel(String name) throws IOException { + Set newLabels = new HashSet(); + + for (Label existingLabel : labels) { + if (!existingLabel.getName().equalsIgnoreCase(name)) { + newLabels.add(existingLabel.getName()); + } + } + + setLabels(newLabels.toArray(new String[0])); + } + /** * Obtains all the comments associated with this issue. * From 9381471fbdc83f6d5e44dd54d101f8f36b2c07f2 Mon Sep 17 00:00:00 2001 From: "I329802 (Xeric)" Date: Thu, 11 Oct 2018 17:30:25 +0800 Subject: [PATCH 3/9] add request reviewers as attribute of GHPullRequest --- src/main/java/org/kohsuke/github/GHPullRequest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 16c3f953c6..53025f18cf 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -58,6 +58,9 @@ public class GHPullRequest extends GHIssue { private int changed_files; private String merge_commit_sha; + // pull request reviewers + private GHUser[] requested_reviewers; + /** * GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API * route as opposed to 'issues' API route. This flag remembers whether we made the GET call on the 'issues' route @@ -76,6 +79,7 @@ GHPullRequest wrapUp(GitHub root) { if (base != null) base.wrapUp(root); if (head != null) head.wrapUp(root); if (merged_by != null) merged_by.wrapUp(root); + if (requested_reviewers != null) GHUser.wrap(requested_reviewers, root); return this; } @@ -219,6 +223,11 @@ public String getMergeCommitSha() throws IOException { return merge_commit_sha; } + public GHUser[] getRequestedReviewers() throws IOException { + populate(); + return requested_reviewers; + } + /** * Fully populate the data by retrieving missing data. * From 70251ea11e9cff37ce23901f5181be11756d690e Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sat, 20 Oct 2018 19:06:15 +0300 Subject: [PATCH 4/9] Fix memory leak. While repository object is active and code requests commits they are stored in Map. GHCommit.files contains huge String[]/char[] amount of data. The same could be applied to Milestones. --- src/main/java/org/kohsuke/github/GHRepository.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 2acc864123..f29181b02b 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -48,6 +48,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.WeakHashMap; import static java.util.Arrays.*; import static org.kohsuke.github.Previews.*; @@ -79,10 +80,10 @@ public class GHRepository extends GHObject { private boolean _private; private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count; private String pushed_at; - private Map milestones = new HashMap(); + private Map milestones = new WeakHashMap(); private String default_branch,language; - private Map commits = new HashMap(); + private Map commits = new WeakHashMap(); @SkipFromToString private GHRepoPermission permissions; From 1012dcd1942932291e93cebe600b1cbcef52a81a Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Thu, 25 Oct 2018 11:24:46 +0200 Subject: [PATCH 5/9] Added archived attribute in GHRepository. Updated the parent POM --- pom.xml | 3 ++- src/main/java/org/kohsuke/github/GHRepository.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3de2dfea24..524901ec0d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.kohsuke pom - 17 + 20 github-api @@ -36,6 +36,7 @@ maven-surefire-plugin + 2.22.1 2 diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 2acc864123..af9380a7bc 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -74,7 +74,7 @@ public class GHRepository extends GHObject { private String git_url, ssh_url, clone_url, svn_url, mirror_url; private GHUser owner; // not fully populated. beware. - private boolean has_issues, has_wiki, fork, has_downloads, has_pages; + private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived; @JsonProperty("private") private boolean _private; private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count; @@ -393,6 +393,10 @@ public boolean isFork() { return fork; } + public boolean isArchived() { + return archived; + } + /** * Returns the number of all forks of this repository. * This not only counts direct forks, but also forks of forks, and so on. From 9345d3be31ddd8542a89786a4155b639bfd7d9cf Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 6 Nov 2018 07:49:02 -0800 Subject: [PATCH 6/9] Follow the convention in this library --- src/main/java/org/kohsuke/github/GHPullRequest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 53025f18cf..b4098829b9 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -28,6 +28,7 @@ import java.net.URL; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -223,9 +224,9 @@ public String getMergeCommitSha() throws IOException { return merge_commit_sha; } - public GHUser[] getRequestedReviewers() throws IOException { + public List getRequestedReviewers() throws IOException { populate(); - return requested_reviewers; + return Collections.unmodifiableList(Arrays.asList(requested_reviewers)); } /** From 9a1bb09c9fe12b2b66ee9ae768a9b810beca07bb Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 6 Nov 2018 08:14:12 -0800 Subject: [PATCH 7/9] Massaging the changes. In particular, avoid the kind of addLabel() method that has lots of side effect and do multiple things. --- src/main/java/org/kohsuke/github/GHIssue.java | 85 +++++++++---------- src/main/java/org/kohsuke/github/GHLabel.java | 11 +++ 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 2fde68a672..55cf54b81f 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -30,6 +30,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -218,70 +219,64 @@ public void setLabels(String... labels) throws IOException { } /** - * Adds a label to the issue. If it does not exist in the {@link GHRepository}, it will be - * created with the specified color. If either {@code name} or {@code color} is null, it will - * be a NOP. + * Adds labels to the issue. * - * @param name Name of the label - * @param color Hex code of the label, without # + * @param names Names of the label */ - public void addLabel(String name, String color) throws IOException { - if (name != null && color != null) { - // All labels that we have seen - Set repoLabels = new HashSet(); - Set seenLabels = new HashSet(); - - // Check if label already exists - for (GHLabel repoLabel : getRepository().listLabels().asSet()) { - repoLabels.add(repoLabel.getName()); - } + public void addLabels(String... names) throws IOException { + _addLabels(Arrays.asList(names)); + } - // Label does not exist - if (!repoLabels.contains(name)) { - GHLabel newLabel = getRepository().createLabel(name, color); - repoLabels.add(newLabel.getName()); - seenLabels.add(newLabel.getName()); - } + public void addLabels(GHLabel... labels) throws IOException { + addLabels(Arrays.asList(labels)); + } - // See if label exists on issue already - boolean foundInIssue = false; + public void addLabels(Collection labels) throws IOException { + _addLabels(GHLabel.toNames(labels)); + } - for (GHLabel existingIssueLabel : getLabels()) { - if (existingIssueLabel.getName().equalsIgnoreCase(name)) { - foundInIssue = true; - } + private void _addLabels(Collection names) throws IOException { + List newLabels = new ArrayList(); - seenLabels.add(existingIssueLabel.getName()); + for (GHLabel label : getLabels()) { + newLabels.add(label.getName()); } - - // If the label doesn't exist in the issue, add it - if (!foundInIssue) { - seenLabels.add(name); - setLabels(seenLabels.toArray(new String[0])); + for (String name : names) { + if (!newLabels.contains(name)) { + newLabels.add(name); + } } - } + setLabels(newLabels.toArray(new String[0])); } /** - * @see #removeLabel(String) + * Remove a given label by name from this issue. */ - public void removeLabel(Label label) throws IOException { - removeLabel(label.getName()); + public void removeLabels(String... names) throws IOException { + _removeLabels(Arrays.asList(names)); } /** - * Remove a given label by name from this issue. + * @see #removeLabels(String...) */ - public void removeLabel(String name) throws IOException { - Set newLabels = new HashSet(); + public void removeLabels(GHLabel... labels) throws IOException { + removeLabels(Arrays.asList(labels)); + } - for (Label existingLabel : labels) { - if (!existingLabel.getName().equalsIgnoreCase(name)) { - newLabels.add(existingLabel.getName()); + public void removeLabels(Collection labels) throws IOException { + _removeLabels(GHLabel.toNames(labels)); + } + + private void _removeLabels(Collection names) throws IOException { + List newLabels = new ArrayList(); + + for (GHLabel l : getLabels()) { + if (!names.contains(l.getName())) { + newLabels.add(l.getName()); + } } - } - setLabels(newLabels.toArray(new String[0])); + setLabels(newLabels.toArray(new String[0])); } /** diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 3792fdcca3..9210bb5f5c 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -1,6 +1,9 @@ package org.kohsuke.github; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; /** * @author Kohsuke Kawaguchi @@ -42,4 +45,12 @@ public void delete() throws IOException { public void setColor(String newColor) throws IOException { repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url); } + + /*package*/ static Collection toNames(Collection labels) { + List r = new ArrayList(); + for (GHLabel l : labels) { + r.add(l.getName()); + } + return r; + } } From 40f012b03c25398c4336edfb1fdbcc7a1944e2e7 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 6 Nov 2018 08:35:48 -0800 Subject: [PATCH 8/9] rtyler no longer has 50 people he follows --- src/test/java/org/kohsuke/github/UserTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/kohsuke/github/UserTest.java b/src/test/java/org/kohsuke/github/UserTest.java index d35632fda2..9d1cfcbbac 100644 --- a/src/test/java/org/kohsuke/github/UserTest.java +++ b/src/test/java/org/kohsuke/github/UserTest.java @@ -14,17 +14,17 @@ public class UserTest extends AbstractGitHubApiTestBase { public void listFollowsAndFollowers() throws IOException { GHUser u = gitHub.getUser("rtyler"); assertNotEquals( - count50(u.listFollowers()), - count50(u.listFollows())); + count30(u.listFollowers()), + count30(u.listFollows())); } - private Set count50(PagedIterable l) { + private Set count30(PagedIterable l) { Set users = new HashSet(); PagedIterator itr = l.iterator(); - for (int i=0; i<50 && itr.hasNext(); i++) { + for (int i=0; i<30 && itr.hasNext(); i++) { users.add(itr.next()); } - assertEquals(50, users.size()); + assertEquals(30, users.size()); return users; } } From c1bab63ebdd9c93e49a5879331234de488e91590 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 6 Nov 2018 08:42:18 -0800 Subject: [PATCH 9/9] [maven-release-plugin] prepare release github-api-1.95 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 524901ec0d..9d599f2ade 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.95-SNAPSHOT + 1.95 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - HEAD + github-api-1.95