diff --git a/pom.xml b/pom.xml
index 4d026c5a83..46d97188c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
github-api
- 1.45
+ 1.46
GitHub API for Java
http://github-api.kohsuke.org/
GitHub API for Java
@@ -34,7 +34,7 @@
com.infradna.tool
bridge-method-injector
- 1.2
+ 1.8
@@ -76,7 +76,7 @@
com.infradna.tool
bridge-method-annotation
- 1.4
+ 1.8
true
@@ -98,6 +98,12 @@
http://repo.jenkins-ci.org/public/
+
+
+ repo.jenkins-ci.org
+ http://repo.jenkins-ci.org/public/
+
+
@@ -107,4 +113,5 @@
+
diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java
index 0c02684215..75f084c8ea 100644
--- a/src/main/java/org/kohsuke/github/GHCommit.java
+++ b/src/main/java/org/kohsuke/github/GHCommit.java
@@ -1,11 +1,12 @@
package org.kohsuke.github;
+import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
+
import java.io.IOException;
import java.net.URL;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
/**
@@ -31,11 +32,13 @@ public static class ShortInfo {
private int comment_count;
- public GHAuthor getAuthor() {
+ @WithBridgeMethods(value=GHAuthor.class,castRequired=true)
+ public GitUser getAuthor() {
return author;
}
- public GHAuthor getCommitter() {
+ @WithBridgeMethods(value=GHAuthor.class,castRequired=true)
+ public GitUser getCommitter() {
return committer;
}
@@ -50,21 +53,11 @@ public int getCommentCount() {
return comment_count;
}
}
-
- public static class GHAuthor {
- private String name,email,date;
- public String getName() {
- return name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public Date getDate() {
- return GitHub.parseDate(date);
- }
+ /**
+ * @deprecated Use {@link GitUser} instead.
+ */
+ public static class GHAuthor extends GitUser {
}
public static class Stats {
diff --git a/src/main/java/org/kohsuke/github/GHCommitPointer.java b/src/main/java/org/kohsuke/github/GHCommitPointer.java
index c4d67f6410..7aaf4f01e1 100644
--- a/src/main/java/org/kohsuke/github/GHCommitPointer.java
+++ b/src/main/java/org/kohsuke/github/GHCommitPointer.java
@@ -31,11 +31,11 @@
public class GHCommitPointer {
private String ref, sha, label;
private GHUser user;
- private GHRepository repository/*V2*/,repo/*V3*/;
+ private GHRepository repo;
/**
* This points to the user who owns
- * the {@link #repository}.
+ * the {@link #getRepository()}.
*/
public GHUser getUser() {
return user;
@@ -45,7 +45,7 @@ public GHUser getUser() {
* The repository that contains the commit.
*/
public GHRepository getRepository() {
- return repo!=null ? repo : repository;
+ return repo;
}
/**
@@ -72,6 +72,5 @@ public String getLabel() {
void wrapUp(GitHub root) {
if (user!=null) user.root = root;
if (repo!=null) repo.wrap(root);
- if (repository!=null) repository.wrap(root);
}
}
diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java
index 31d5a07bd5..0435116995 100644
--- a/src/main/java/org/kohsuke/github/GHCompare.java
+++ b/src/main/java/org/kohsuke/github/GHCompare.java
@@ -1,5 +1,7 @@
package org.kohsuke.github;
+import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
+
import java.net.URL;
import java.util.Date;
@@ -109,11 +111,13 @@ public String getMessage() {
return message;
}
- public User getAuthor() {
+ @WithBridgeMethods(value=User.class,castRequired=true)
+ public GitUser getAuthor() {
return author;
}
- public User getCommitter() {
+ @WithBridgeMethods(value=User.class,castRequired=true)
+ public GitUser getCommitter() {
return committer;
}
@@ -134,23 +138,13 @@ public String getSha() {
}
}
- public static class User {
- private String name, email, date;
-
- public String getName() {
- return name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public Date getDate() {
- return GitHub.parseDate(date);
- }
+ /**
+ * @deprecated use {@link GitUser} instead.
+ */
+ public static class User extends GitUser {
}
public static enum Status {
- behind, ahead, identical;
+ behind, ahead, identical
}
}
diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java
index b3dfba0238..09db42aa0f 100644
--- a/src/main/java/org/kohsuke/github/GHEventInfo.java
+++ b/src/main/java/org/kohsuke/github/GHEventInfo.java
@@ -63,6 +63,13 @@ public GHUser getActor() throws IOException {
return root.getUser(actor.getLogin());
}
+ /**
+ * Quick way to just get the actor of the login.
+ */
+ public String getActorLogin() throws IOException {
+ return actor.getLogin();
+ }
+
public GHOrganization getOrganization() throws IOException {
return (org==null || org.getLogin()==null) ? null : root.getOrganization(org.getLogin());
}
diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java
index 0e0b7054e3..e805ef7eb4 100644
--- a/src/main/java/org/kohsuke/github/GHEventPayload.java
+++ b/src/main/java/org/kohsuke/github/GHEventPayload.java
@@ -1,6 +1,7 @@
package org.kohsuke.github;
import java.io.Reader;
+import java.util.List;
/**
* Base type for types used in databinding of the event payload.
@@ -8,6 +9,7 @@
* @see GitHub#parseEventPayload(Reader, Class)
* @see GHEventInfo#getPayload(Class)
*/
+@SuppressWarnings("UnusedDeclaration")
public abstract class GHEventPayload {
protected GitHub root;
@@ -21,7 +23,7 @@ public abstract class GHEventPayload {
/**
* A pull request status has changed.
*
- * @see http://developer.github.com/v3/activity/events/types/#pullrequestevent
+ * @see authoritative source
*/
public static class PullRequest extends GHEventPayload {
private String action;
@@ -61,7 +63,7 @@ void wrapUp(GitHub root) {
/**
* A comment was added to an issue
*
- * @see http://developer.github.com/v3/activity/events/types/#issuecommentevent
+ * @see authoritative source
*/
public static class IssueComment extends GHEventPayload {
private String action;
@@ -105,4 +107,88 @@ void wrapUp(GitHub root) {
comment.wrapUp(issue);
}
}
+
+ /**
+ * A commit was pushed.
+ *
+ * @see authoritative source
+ */
+ public static class Push extends GHEventPayload {
+ private String head, before;
+ private String ref;
+ private int size;
+ private List commits;
+
+ /**
+ * The SHA of the HEAD commit on the repository
+ */
+ public String getHead() {
+ return head;
+ }
+
+ /**
+ * This is undocumented, but it looks like this captures the commit that the ref was pointing to
+ * before the push.
+ */
+ public String getBefore() {
+ return before;
+ }
+
+ /**
+ * The full Git ref that was pushed. Example: “refs/heads/master”
+ */
+ public String getRef() {
+ return ref;
+ }
+
+ /**
+ * The number of commits in the push.
+ * Is this always the same as {@code getCommits().size()}?
+ */
+ public int getSize() {
+ return size;
+ }
+
+ /**
+ * The list of pushed commits.
+ */
+ public List getCommits() {
+ return commits;
+ }
+
+ /**
+ * Commit in a push
+ */
+ public static class PushCommit {
+ private GitUser author;
+ private String url, sha, message;
+ private boolean distinct;
+
+ public GitUser getAuthor() {
+ return author;
+ }
+
+ /**
+ * Points to the commit API resource.
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ public String getSha() {
+ return sha;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Whether this commit is distinct from any that have been pushed before.
+ */
+ public boolean isDistinct() {
+ return distinct;
+ }
+ }
+ }
}
diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java
index e02eccd6ee..ec899c0538 100644
--- a/src/main/java/org/kohsuke/github/GHOrganization.java
+++ b/src/main/java/org/kohsuke/github/GHOrganization.java
@@ -156,4 +156,21 @@ public List getPullRequests() throws IOException {
}
return all;
}
+
+ /**
+ * Lists events performed by a user (this includes private events if the caller is authenticated.
+ */
+ public PagedIterable listEvents() throws IOException {
+ return new PagedIterable() {
+ public PagedIterator iterator() {
+ return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/events", login), GHEventInfo[].class)) {
+ @Override
+ protected void wrapUp(GHEventInfo[] page) {
+ for (GHEventInfo c : page)
+ c.wrapUp(root);
+ }
+ };
+ }
+ };
+ }
}
diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java
index 92a2b90d2b..fbabd1dcb6 100644
--- a/src/main/java/org/kohsuke/github/GHPerson.java
+++ b/src/main/java/org/kohsuke/github/GHPerson.java
@@ -135,6 +135,11 @@ public GHRepository getRepository(String name) throws IOException {
}
}
+ /**
+ * Lists events for an organization or an user.
+ */
+ public abstract PagedIterable listEvents() throws IOException;
+
/**
* Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105
*
diff --git a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
index 8820bc3d32..0ec7fff486 100644
--- a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
+++ b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
@@ -23,8 +23,9 @@
*/
package org.kohsuke.github;
+import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
+
import java.net.URL;
-import java.util.Date;
/**
* Commit detail inside a {@link GHPullRequest}.
@@ -33,25 +34,12 @@
*/
public class GHPullRequestCommitDetail {
- public static class Authorship {
- String name;
- String email;
- String date;
-
- public String getName() {
- return name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public Date getDate() {
- return GitHub.parseDate(date);
- }
- }
+ /**
+ * @deprecated Use {@link GitUser}
+ */
+ public static class Authorship extends GitUser {}
- public static class Tree {
+ public static class Tree {
String sha;
String url;
@@ -72,11 +60,13 @@ public static class Commit {
String url;
int comment_count;
- public Authorship getAuthor() {
+ @WithBridgeMethods(value=Authorship.class,castRequired=true)
+ public GitUser getAuthor() {
return author;
}
- public Authorship getCommitter() {
+ @WithBridgeMethods(value=Authorship.class,castRequired=true)
+ public GitUser getCommitter() {
return committer;
}
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index 93748037f8..dc897dfa68 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -528,6 +528,22 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin
.to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root);
}
+ /**
+ * Lists repository events.
+ */
+ public PagedIterable listEvents() throws IOException {
+ return new PagedIterable() {
+ public PagedIterator iterator() {
+ return new PagedIterator(root.retrieve().asIterator(String.format("/repos/%s/%s/events", owner.login, name), GHEventInfo[].class)) {
+ @Override
+ protected void wrapUp(GHEventInfo[] page) {
+ for (GHEventInfo c : page)
+ c.wrapUp(root);
+ }
+ };
+ }
+ };
+ }
/**
*
diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java
index fb43cbd6d3..42ec16c5cd 100644
--- a/src/main/java/org/kohsuke/github/GHUser.java
+++ b/src/main/java/org/kohsuke/github/GHUser.java
@@ -103,6 +103,23 @@ public GHPersonSet getOrganizations() throws IOException {
return orgs;
}
+ /**
+ * Lists events performed by a user (this includes private events if the caller is authenticated.
+ */
+ public PagedIterable listEvents() throws IOException {
+ return new PagedIterable() {
+ public PagedIterator iterator() {
+ return new PagedIterator(root.retrieve().asIterator(String.format("/users/%s/events", login), GHEventInfo[].class)) {
+ @Override
+ protected void wrapUp(GHEventInfo[] page) {
+ for (GHEventInfo c : page)
+ c.wrapUp(root);
+ }
+ };
+ }
+ };
+ }
+
@Override
public String toString() {
return "User:"+login;
diff --git a/src/main/java/org/kohsuke/github/GitUser.java b/src/main/java/org/kohsuke/github/GitUser.java
new file mode 100644
index 0000000000..fc97ef8882
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/GitUser.java
@@ -0,0 +1,38 @@
+package org.kohsuke.github;
+
+import java.util.Date;
+
+/**
+ * Represents a user in Git who authors/commits a commit.
+ *
+ * In contrast, {@link GHUser} is an user of GitHub. Because Git allows a person to
+ * use multiple e-mail addresses and names when creating a commit, there's generally
+ * no meaningful mapping between {@link GHUser} and {@link GitUser}.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public class GitUser {
+ private String name, email, date;
+
+ /**
+ * Human readable name of the user, such as "Kohsuke Kawaguchi"
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * E-mail address, such as "foo@example.com"
+ */
+ public String getEmail() {
+ return email;
+ }
+
+ /**
+ * This field doesn't appear to be consistently available in all the situations where this class
+ * is used.
+ */
+ public Date getDate() {
+ return GitHub.parseDate(date);
+ }
+}