diff --git a/src/main/java/org/kohsuke/github/GHDetailedPullRequest.java b/src/main/java/org/kohsuke/github/GHDetailedPullRequest.java new file mode 100644 index 000000000..0fa4ebfc7 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHDetailedPullRequest.java @@ -0,0 +1,77 @@ +/* + * The MIT License + * + * Copyright 2012 Honza Brázdil. + * + * 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; + +/** + * + * @author Honza Brázdil + */ +public class GHDetailedPullRequest extends GHPullRequest { + private GHSmallUser merged_by; + private int review_comments, additions; + private boolean merged; + private Boolean mergeable; + private int deletions; + private String mergeable_state; + private int changed_files; + + @Override + GHDetailedPullRequest wrapUp(GHRepository owner){ + super.wrapUp(owner); + if(merged_by != null) merged_by.wrapUp(root); + return this; + } + + public GHSmallUser getMerged_by() { + return merged_by; + } + + public int getReview_comments() { + return review_comments; + } + + public int getAdditions() { + return additions; + } + + public boolean isMerged() { + return merged; + } + + public Boolean getMergeable() { + return mergeable; + } + + public int getDeletions() { + return deletions; + } + + public String getMergeable_state() { + return mergeable_state; + } + + public int getChanged_files() { + return changed_files; + } +} diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 3224e76f2..35eb9b9a6 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -42,15 +42,29 @@ import java.util.Locale; public class GHIssue { GitHub root; GHRepository owner; - - private String gravatar_id,body,title,state,created_at,updated_at,html_url; + + // API v3 + private GHSmallUser assignee; + private String state; + private int number; + private String closed_at; + private int comments; + private String body; private List labels; - private int number,votes,comments; - private int position; + private GHSmallUser user; + private String title, created_at, html_url; + private GHIssue.PullRequest pull_request; + // GHIssue milestone + private String url, updated_at; + private int id; + private GHSmallUser closed_by; /*package*/ GHIssue wrap(GHRepository owner) { this.owner = owner; this.root = owner.root; + if(assignee != null) assignee.wrapUp(root); + if(user != null) user.wrapUp(root); + if(closed_by != null) closed_by.wrapUp(root); return this; } @@ -112,6 +126,10 @@ public class GHIssue { return GitHub.parseDate(updated_at); } + public Date getClosedAt() { + return GitHub.parseDate(closed_at); + } + /** * Updates the issue by adding a comment. */ @@ -182,4 +200,47 @@ public class GHIssue { private String getApiRoute() { return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number; } + + public GHSmallUser getAssignee() { + return assignee; + } + + /** + * User who submitted the issue. + */ + public GHSmallUser getUser() { + return user; + } + + public GHSmallUser getClosedBy() { + if(!"closed".equals(state)) return null; + if(closed_by != null) return closed_by; + + //TODO closed_by = owner.getIssue(number).getClosed_by(); + return closed_by; + } + + public int getCommentsCount(){ + return comments; + } + + public PullRequest getPullRequest() { + return pull_request; + } + + public class PullRequest{ + private String diff_url, patch_url, html_url; + + public URL getDiffUrl() { + return GitHub.parseURL(diff_url); + } + + public URL getPatchUrl() { + return GitHub.parseURL(patch_url); + } + + public URL getUrl() { + return GitHub.parseURL(html_url); + } + } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 1f86981e0..86ae49f7d 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -24,6 +24,7 @@ package org.kohsuke.github; import java.net.URL; +import java.util.Collection; import java.util.Date; /** @@ -33,12 +34,24 @@ import java.util.Date; */ @SuppressWarnings({"UnusedDeclaration"}) public class GHPullRequest extends GHIssue { - private String closed_at, patch_url, issue_updated_at; - private GHUser issue_user, user; - // labels?? - private GHCommitPointer base, head; - private String mergeable, diff_url; + + private String patch_url, diff_url, issue_url; + private GHCommitPointer base; + private String merged_at; + private GHCommitPointer head; + GHPullRequest wrapUp(GHRepository owner) { + this.wrap(owner); + return wrapUp(owner.root); + } + + GHPullRequest wrapUp(GitHub root) { + if (owner!=null) owner.wrap(root); + if (base!=null) base.wrapUp(root); + if (head!=null) head.wrapUp(root); + return this; + } + /** * The URL of the patch file. * like https://github.com/jenkinsci/jenkins/pull/100.patch @@ -46,12 +59,13 @@ public class GHPullRequest extends GHIssue { public URL getPatchUrl() { return GitHub.parseURL(patch_url); } - - /** - * User who submitted a pull request. + + /** + * The URL of the patch file. + * like https://github.com/jenkinsci/jenkins/pull/100.patch */ - public GHUser getUser() { - return user; + public URL getIssueUrl() { + return GitHub.parseURL(issue_url); } /** @@ -69,16 +83,9 @@ public class GHPullRequest extends GHIssue { return head; } + @Deprecated public Date getIssueUpdatedAt() { - return GitHub.parseDate(issue_updated_at); - } - - /** - * The HTML page of this pull request, - * like https://github.com/jenkinsci/jenkins/pull/100 - */ - public URL getUrl() { - return super.getUrl(); + return super.getUpdatedAt(); } /** @@ -89,22 +96,22 @@ public class GHPullRequest extends GHIssue { return GitHub.parseURL(diff_url); } - public Date getClosedAt() { - return GitHub.parseDate(closed_at); + public Date getMergedAt() { + return GitHub.parseDate(merged_at); } - GHPullRequest wrapUp(GHRepository owner) { - this.owner = owner; - return wrapUp(owner.root); - } + @Override + public Collection getLabels() { + return super.getLabels(); + } - GHPullRequest wrapUp(GitHub root) { - this.root = root; - if (owner!=null) owner.wrap(root); - if (issue_user!=null) issue_user.root=root; - if (user!=null) user.root=root; - if (base!=null) base.wrapUp(root); - if (head!=null) head.wrapUp(root); - return this; - } + @Override + public GHSmallUser getClosedBy() { + return null; + } + + @Override + public PullRequest getPullRequest() { + return null; + } } diff --git a/src/main/java/org/kohsuke/github/GHSmallUser.java b/src/main/java/org/kohsuke/github/GHSmallUser.java new file mode 100644 index 000000000..5725bf406 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHSmallUser.java @@ -0,0 +1,66 @@ +/* + * The MIT License + * + * Copyright 2012 Honza Brázdil. + * + * 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; + +/** + * + * @author Honza Brázdil + */ +public class GHSmallUser { + private GitHub root; + private String avatar_url, login, url, gravatar_id; + private Long id; + + /*package*/ GHSmallUser wrapUp(GitHub root) { + this.root = root; + return this; + } + + + public String getAvatar_url() { + return avatar_url; + } + + public String getLogin() { + return login; + } + + public String getUrl() { + return url; + } + + public String getGravatar_id() { + return gravatar_id; + } + + public Long getId() { + return id; + } + + public GHUser getUser() throws IOException{ + return root.getUser(login); + } +}