Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues pull requests apiv3 #17

Merged
merged 8 commits into from
Sep 6, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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()
  • Loading branch information
janinko committed Aug 31, 2012
commit 6aabaea96cca726bbd8b64fca24edec397191ade
77 changes: 77 additions & 0 deletions src/main/java/org/kohsuke/github/GHDetailedPullRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
69 changes: 65 additions & 4 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,29 @@
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;
}

Expand Down Expand Up @@ -112,6 +126,10 @@ public Date getUpdatedAt() {
return GitHub.parseDate(updated_at);
}

public Date getClosedAt() {
return GitHub.parseDate(closed_at);
}

/**
* Updates the issue by adding a comment.
*/
Expand Down Expand Up @@ -182,4 +200,47 @@ protected void wrapUp(GHIssueComment[] page) {
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);
}
}
}
75 changes: 41 additions & 34 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.kohsuke.github;

import java.net.URL;
import java.util.Collection;
import java.util.Date;

/**
Expand All @@ -33,25 +34,38 @@
*/
@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
*/
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);
}

/**
Expand All @@ -69,16 +83,9 @@ public GHCommitPointer getHead() {
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();
}

/**
Expand All @@ -89,22 +96,22 @@ public URL getDiffUrl() {
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 changes: 66 additions & 0 deletions src/main/java/org/kohsuke/github/GHSmallUser.java
Original file line number Diff line number Diff line change
@@ -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);
}
}