mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 15:49:57 +00:00
Clean up GHIssue and GHPullRequest and make them relevant to api v3.
Added SmallUser representing reference to user. Added DetailedPullRequest - when retrieving pull request by id, it has more attributes then pull requests obtained by GHRepository.getPullRequests()
This commit is contained in:
77
src/main/java/org/kohsuke/github/GHDetailedPullRequest.java
Normal file
77
src/main/java/org/kohsuke/github/GHDetailedPullRequest.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
66
src/main/java/org/kohsuke/github/GHSmallUser.java
Normal file
66
src/main/java/org/kohsuke/github/GHSmallUser.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user