Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Kohsuke Kawaguchi
*/
public abstract class GHPerson {
public class GHPerson {
/*package almost final*/ GitHub root;

// core data fields that exist even for "small" user data (such as the user info in pull request)
Expand Down Expand Up @@ -55,14 +55,25 @@ public synchronized Map<String,GHRepository> getRepositories() throws IOExceptio
}

/**
* Lists up all the repositories.
* Lists up all the repositories using a 30 items page size.
*
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
*/
public PagedIterable<GHRepository> listRepositories() {
return listRepositories(30);
}

/**
* Lists up all the repositories using the specified page size.
*
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
*
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
*/
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos", GHRepository[].class)) {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;

/**
* A pull request.
Expand Down Expand Up @@ -186,4 +187,22 @@ private void populate() throws IOException {

root.retrieve().to(url, this);
}

/**
* Retrieves all the commits associated to this pull request.
*/
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
return new PagedIterable<GHPullRequestCommitDetail>() {
public PagedIterator<GHPullRequestCommitDetail> iterator() {
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
String.format("%s/commits", getApiURL().getPath()),
GHPullRequestCommitDetail[].class)) {
@Override
protected void wrapUp(GHPullRequestCommitDetail[] page) {
}
};
}
};
}

}
139 changes: 139 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* The MIT License
*
* Copyright (c) 2013, Luca Milanesio
*
* 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;
import java.util.Date;

/**
* Commit detail inside a {@link GHPullRequest}.
*
* @author Luca Milanesio
*/
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);
}
}

public static class Tree {
String sha;
String url;

public String getSha() {
return sha;
}

public URL getUrl() {
return GitHub.parseURL(url);
}
}

public static class Commit {
Authorship author;
Authorship committer;
String message;
Tree tree;
String url;
int comment_count;

public Authorship getAuthor() {
return author;
}

public Authorship getCommitter() {
return committer;
}

public String getMessage() {
return message;
}

public URL getUrl() {
return GitHub.parseURL(url);
}

public int getComment_count() {
return comment_count;
}
}

public static class CommitPointer {
String sha;
String url;
String html_url;

public URL getUrl() {
return GitHub.parseURL(url);
}

public URL getHtml_url() {
return GitHub.parseURL(html_url);
}

public String getSha() {
return sha;
}
}

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;
}
}
13 changes: 12 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class GHRepository {
private String description, homepage, name;
private String url; // this is the API url
private String html_url; // this is the UI
private GHUser owner; // not fully populated. beware.
private GHPerson owner; // not fully populated. beware.
private boolean has_issues, has_wiki, fork, _private, has_downloads;
private int watchers,forks,open_issues,size;
private String created_at, pushed_at;
Expand Down Expand Up @@ -378,6 +378,17 @@ protected void wrapUp(GHPullRequest[] page) {
};
}

/**
* Retrieves all the pull requests of a particular state by knowing organisation and repository
*/
public static PagedIterable<GHPullRequest> listPullRequests(final GitHub root, final GHPerson owner, final String repositoryName, final GHIssueState state) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I know why you wanted methods like this (to avoid unnecessary REST API calls to getRepository()), but I don't want the library to become full of these short-cuts.

To address this without cluttering the API, I think we need to defer the REST call to retrieve the state of the repository. So I tweaked your commits and removed this method. I hope you are OK with this for the time being.

GHRepository repo = new GHRepository();
repo.root = root;
repo.name = repositoryName;
repo.owner = owner;
return repo.listPullRequests(state);
}

/**
* Retrieves the currently configured hooks.
*/
Expand Down