diff --git a/pom.xml b/pom.xml index b54c58bc47..992c9ef281 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.67 + 1.68 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.67 + github-api-1.68 diff --git a/src/main/java/org/kohsuke/github/GHCommitPointer.java b/src/main/java/org/kohsuke/github/GHCommitPointer.java index 7aaf4f01e1..b9716366b5 100644 --- a/src/main/java/org/kohsuke/github/GHCommitPointer.java +++ b/src/main/java/org/kohsuke/github/GHCommitPointer.java @@ -23,6 +23,8 @@ */ package org.kohsuke.github; +import java.io.IOException; + /** * Identifies a commit in {@link GHPullRequest}. * @@ -69,6 +71,13 @@ public String getLabel() { return label; } + /** + * Obtains the commit that this pointer is referring to. + */ + public GHCommit getCommit() throws IOException { + return getRepository().getCommit(getSha()); + } + void wrapUp(GitHub root) { if (user!=null) user.root = root; if (repo!=null) repo.wrap(root); diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 7c46a9c1c5..909110b727 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -27,7 +27,6 @@ import java.net.URL; import java.util.Collection; import java.util.Date; -import java.util.Locale; /** * A pull request. @@ -197,6 +196,39 @@ private void populate() throws IOException { root.retrieve().to(url, this).wrapUp(owner); } + /** + * Retrieves all the commits associated to this pull request. + */ + public PagedIterable listFiles() { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(root.retrieve().asIterator(String.format("%s/files", getApiURL()), + GHPullRequestFileDetail[].class)) { + @Override + protected void wrapUp(GHPullRequestFileDetail[] page) { + } + }; + } + }; + } + + /** + * Obtains all the review comments associated with this pull request. + */ + public PagedIterable listReviewComments() throws IOException { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(root.retrieve().asIterator(getApiRoute() + "/comments", + GHPullRequestReviewComment[].class)) { + protected void wrapUp(GHPullRequestReviewComment[] page) { + for (GHPullRequestReviewComment c : page) + c.wrapUp(GHPullRequest.this); + } + }; + } + }; + } + /** * Retrieves all the commits associated to this pull request. */ @@ -208,12 +240,23 @@ public PagedIterator iterator() { GHPullRequestCommitDetail[].class)) { @Override protected void wrapUp(GHPullRequestCommitDetail[] page) { + for (GHPullRequestCommitDetail c : page) + c.wrapUp(GHPullRequest.this); } }; } }; } + public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException { + return new Requester(root).method("POST") + .with("body", body) + .with("commit_id", sha) + .with("path", path) + .with("position", position) + .to(getApiRoute() + "/comments", GHPullRequestReviewComment.class).wrapUp(this); + } + /** * Merge this pull request. * @@ -223,7 +266,21 @@ protected void wrapUp(GHPullRequestCommitDetail[] page) { * Commit message. If null, the default one will be used. */ public void merge(String msg) throws IOException { - new Requester(root).method("PUT").with("commit_message",msg).to(getApiRoute()+"/merge"); + merge(msg,null); + } + + /** + * Merge this pull request. + * + * The equivalent of the big green "Merge pull request" button. + * + * @param msg + * Commit message. If null, the default one will be used. + * @param sha + * SHA that pull request head must match to allow merge. + */ + public void merge(String msg, String sha) throws IOException { + new Requester(root).method("PUT").with("commit_message",msg).with("sha",sha).to(getApiRoute()+"/merge"); } private void fetchIssue() throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java index 0ec7fff486..3568550904 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java @@ -31,99 +31,111 @@ * Commit detail inside a {@link GHPullRequest}. * * @author Luca Milanesio + * @see GHPullRequest#listCommits() */ public class GHPullRequestCommitDetail { + private GHPullRequest owner; + + /*package*/ void wrapUp(GHPullRequest owner) { + this.owner = owner; + } /** * @deprecated Use {@link GitUser} */ - public static class Authorship extends GitUser {} + public static class Authorship extends GitUser { + } public static class Tree { - String sha; - String url; + String sha; + String url; - public String getSha() { - return sha; - } + public String getSha() { + return sha; + } - public URL getUrl() { - return GitHub.parseURL(url); + public URL getUrl() { + return GitHub.parseURL(url); + } } - } - public static class Commit { - Authorship author; - Authorship committer; - String message; - Tree tree; - String url; - int comment_count; - - @WithBridgeMethods(value=Authorship.class,castRequired=true) - public GitUser getAuthor() { - return author; + public static class Commit { + Authorship author; + Authorship committer; + String message; + Tree tree; + String url; + int comment_count; + + @WithBridgeMethods(value = Authorship.class, castRequired = true) + public GitUser getAuthor() { + return author; + } + + @WithBridgeMethods(value = Authorship.class, castRequired = true) + public GitUser getCommitter() { + return committer; + } + + public String getMessage() { + return message; + } + + public URL getUrl() { + return GitHub.parseURL(url); + } + + public int getComment_count() { + return comment_count; + } } - @WithBridgeMethods(value=Authorship.class,castRequired=true) - public GitUser getCommitter() { - return committer; - } + public static class CommitPointer { + String sha; + String url; + String html_url; - public String getMessage() { - return message; - } + public URL getUrl() { + return GitHub.parseURL(url); + } - public URL getUrl() { - return GitHub.parseURL(url); - } + public URL getHtml_url() { + return GitHub.parseURL(html_url); + } - public int getComment_count() { - return comment_count; + public String getSha() { + return sha; + } } - } - public static class CommitPointer { String sha; + Commit commit; String url; String html_url; + String comments_url; + CommitPointer[] parents; + + public String getSha() { + return sha; + } + + public Commit getCommit() { + return commit; + } + + public URL getApiUrl() { + return GitHub.parseURL(url); + } public URL getUrl() { - return GitHub.parseURL(url); + return GitHub.parseURL(html_url); } - public URL getHtml_url() { - return GitHub.parseURL(html_url); + public URL getCommentsUrl() { + return GitHub.parseURL(comments_url); } - public String getSha() { - return sha; + public CommitPointer[] getParents() { + return parents; } - } - - String sha; - Commit commit; - String url; - String html_url; - String comments_url; - CommitPointer[] parents; - - public String getSha() { - return sha; - } - public Commit getCommit() { - return commit; - } - public URL getApiUrl() { - return GitHub.parseURL(url); - } - public URL getUrl() { - return GitHub.parseURL(html_url); - } - public URL getCommentsUrl() { - return GitHub.parseURL(comments_url); - } - public CommitPointer[] getParents() { - return parents; - } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestFileDetail.java b/src/main/java/org/kohsuke/github/GHPullRequestFileDetail.java new file mode 100644 index 0000000000..1ee55d37cc --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHPullRequestFileDetail.java @@ -0,0 +1,86 @@ +/* + * The MIT License + * + * Copyright (c) 2015, Julien Henry + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.kohsuke.github; + +import java.net.URL; + +/** + * File detail inside a {@link GHPullRequest}. + * + * @author Julien Henry + * @see GHPullRequest#listFiles() + */ +public class GHPullRequestFileDetail { + + String sha; + String filename; + String status; + int additions; + int deletions; + int changes; + String blob_url; + String raw_url; + String contents_url; + String patch; + + public String getSha() { + return sha; + } + + public String getFilename() { + return filename; + } + + public String getStatus() { + return status; + } + + public int getAdditions() { + return additions; + } + + public int getDeletions() { + return deletions; + } + + public int getChanges() { + return changes; + } + + public URL getBlobUrl() { + return GitHub.parseURL(blob_url); + } + + public URL getRawUrl() { + return GitHub.parseURL(raw_url); + } + + public URL getContentsUrl() { + return GitHub.parseURL(contents_url); + } + + public String getPatch() { + return patch; + } +} diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java new file mode 100644 index 0000000000..09863f78cf --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -0,0 +1,105 @@ +/* + * The MIT License + * + * Copyright (c) 2010, Kohsuke Kawaguchi + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.URL; + +/** + * Review comment to the pull request + * + * @author Julien Henry + * @see GHPullRequest#listReviewComments() + * @see GHPullRequest#createReviewComment(String, String, String, int) + */ +public class GHPullRequestReviewComment extends GHObject { + GHPullRequest owner; + + private String body; + private GHUser user; + private String path; + private int position; + private int originalPosition; + + /*package*/ GHPullRequestReviewComment wrapUp(GHPullRequest owner) { + this.owner = owner; + return this; + } + + /** + * Gets the pull request to which this review comment is associated. + */ + public GHPullRequest getParent() { + return owner; + } + + /** + * The comment itself. + */ + public String getBody() { + return body; + } + + /** + * Gets the user who posted this comment. + */ + public GHUser getUser() throws IOException { + return owner.root.getUser(user.getLogin()); + } + + public String getPath() { + return path; + } + + public int getPosition() { + return position; + } + + public int getOriginalPosition() { + return originalPosition; + } + + @Override + public URL getHtmlUrl() { + return null; + } + + protected String getApiRoute() { + return "/repos/"+owner.getRepository().getFullName()+"/comments/"+id; + } + + /** + * Updates the comment. + */ + public void update(String body) throws IOException { + new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(),this); + } + + /** + * Deletes this review comment. + */ + public void delete() throws IOException { + new Requester(owner.root).method("DELETE").to(getApiRoute()); + } +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 744a6d36e9..d196481bc2 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -133,10 +133,11 @@ public class GitHub { } } + this.rateLimitHandler = rateLimitHandler; + if (login==null && encodedAuthorization!=null) login = getMyself().getLogin(); this.login = login; - this.rateLimitHandler = rateLimitHandler; } /**