Compare commits

...

14 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
c1bab63ebd [maven-release-plugin] prepare release github-api-1.95 2018-11-06 08:42:18 -08:00
Kohsuke Kawaguchi
40f012b03c rtyler no longer has 50 people he follows 2018-11-06 08:35:48 -08:00
Kohsuke Kawaguchi
a380059389 Merge branch 'master' of github.com:kohsuke/github-api 2018-11-06 08:16:06 -08:00
Kohsuke Kawaguchi
24b998ba2d Merge pull request #461 2018-11-06 08:15:11 -08:00
Kohsuke Kawaguchi
9a1bb09c9f Massaging the changes.
In particular, avoid the kind of addLabel() method that has lots of side
effect and do multiple things.
2018-11-06 08:14:12 -08:00
Kohsuke Kawaguchi
3ad66f8937 Merge pull request #468 from KostyaSha/fixMemLeak
Fix memory leak.
2018-11-06 07:56:15 -08:00
Kohsuke Kawaguchi
a6f3e7df55 Merge pull request #464 2018-11-06 07:49:17 -08:00
Kohsuke Kawaguchi
9345d3be31 Follow the convention in this library 2018-11-06 07:49:02 -08:00
Kohsuke Kawaguchi
8e85bf8839 Merge pull request #470 from recena/archived-attr
Added archived attribute in GHRepository
2018-10-29 08:28:00 -07:00
Manuel Recena
1012dcd194 Added archived attribute in GHRepository. Updated the parent POM 2018-10-25 11:24:46 +02:00
Kanstantsin Shautsou
70251ea11e 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.
2018-10-20 19:13:47 +03:00
I329802 (Xeric)
9381471fbd add request reviewers as attribute of GHPullRequest 2018-10-11 17:30:25 +08:00
Even Holthe
1c4b716f1a Add methods for adding/removing labels to GHIssue
Fixes #456
2018-10-01 23:29:15 +02:00
Kohsuke Kawaguchi
c8b0584127 [maven-release-plugin] prepare for next development iteration 2018-08-29 21:05:31 -07:00
6 changed files with 104 additions and 14 deletions

View File

@@ -3,11 +3,11 @@
<parent>
<groupId>org.kohsuke</groupId>
<artifactId>pom</artifactId>
<version>17</version>
<version>20</version>
</parent>
<artifactId>github-api</artifactId>
<version>1.94</version>
<version>1.95</version>
<name>GitHub API for Java</name>
<url>http://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
@@ -16,7 +16,7 @@
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
<url>http://${project.artifactId}.kohsuke.org/</url>
<tag>github-api-1.94</tag>
<tag>github-api-1.95</tag>
</scm>
<distributionManagement>
@@ -36,6 +36,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>

View File

@@ -24,19 +24,21 @@
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.ArrayList;
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 +218,67 @@ public class GHIssue extends GHObject implements Reactable{
editIssue("labels",labels);
}
/**
* Adds labels to the issue.
*
* @param names Names of the label
*/
public void addLabels(String... names) throws IOException {
_addLabels(Arrays.asList(names));
}
public void addLabels(GHLabel... labels) throws IOException {
addLabels(Arrays.asList(labels));
}
public void addLabels(Collection<GHLabel> labels) throws IOException {
_addLabels(GHLabel.toNames(labels));
}
private void _addLabels(Collection<String> names) throws IOException {
List<String> newLabels = new ArrayList<String>();
for (GHLabel label : getLabels()) {
newLabels.add(label.getName());
}
for (String name : names) {
if (!newLabels.contains(name)) {
newLabels.add(name);
}
}
setLabels(newLabels.toArray(new String[0]));
}
/**
* Remove a given label by name from this issue.
*/
public void removeLabels(String... names) throws IOException {
_removeLabels(Arrays.asList(names));
}
/**
* @see #removeLabels(String...)
*/
public void removeLabels(GHLabel... labels) throws IOException {
removeLabels(Arrays.asList(labels));
}
public void removeLabels(Collection<GHLabel> labels) throws IOException {
_removeLabels(GHLabel.toNames(labels));
}
private void _removeLabels(Collection<String> names) throws IOException {
List<String> newLabels = new ArrayList<String>();
for (GHLabel l : getLabels()) {
if (!names.contains(l.getName())) {
newLabels.add(l.getName());
}
}
setLabels(newLabels.toArray(new String[0]));
}
/**
* Obtains all the comments associated with this issue.
*

View File

@@ -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 class GHLabel {
public void setColor(String newColor) throws IOException {
repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url);
}
/*package*/ static Collection<String> toNames(Collection<GHLabel> labels) {
List<String> r = new ArrayList<String>();
for (GHLabel l : labels) {
r.add(l.getName());
}
return r;
}
}

View File

@@ -28,6 +28,7 @@ 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.List;
@@ -58,6 +59,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 +80,7 @@ public class GHPullRequest extends GHIssue {
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 +224,11 @@ public class GHPullRequest extends GHIssue {
return merge_commit_sha;
}
public List<GHUser> getRequestedReviewers() throws IOException {
populate();
return Collections.unmodifiableList(Arrays.asList(requested_reviewers));
}
/**
* Fully populate the data by retrieving missing data.
*

View File

@@ -48,6 +48,7 @@ import java.util.List;
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.*;
@@ -74,15 +75,15 @@ 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;
private String pushed_at;
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
private Map<Integer,GHMilestone> milestones = new WeakHashMap<Integer, GHMilestone>();
private String default_branch,language;
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
private Map<String,GHCommit> commits = new WeakHashMap<String, GHCommit>();
@SkipFromToString
private GHRepoPermission permissions;
@@ -393,6 +394,10 @@ public class GHRepository extends GHObject {
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.

View File

@@ -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<GHUser> count50(PagedIterable<GHUser> l) {
private Set<GHUser> count30(PagedIterable<GHUser> l) {
Set<GHUser> users = new HashSet<GHUser>();
PagedIterator<GHUser> 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;
}
}