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

Added apis to list commits by author and list the repos of an organization (including private ones) #77

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 21 additions & 0 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,25 @@ protected void wrapUp(GHEventInfo[] page) {
}
};
}

/**
* Lists up all the repositories of an organization using the specified page size. (this
* includes private repos if the caller is authenticated accordingly)
*
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
*
*/
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
c.wrap(root);
}
};
}
};
}
}
62 changes: 62 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,68 @@ protected void wrapUp(GHCommit[] page) {
}
};
}

/**
* Lists all the commit by author
*/
public PagedIterable<GHCommit> listCommitsByAuthor(final String author) {
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits?author=%s", owner.login, name, author), GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(GHRepository.this);
}
};
}
};
}

/**
* Lists all the commit by author for the given branch from the startCommitSha (startCommitSha is optional)
*/
public PagedIterable<GHCommit> listCommitsByAuthorAndBranch(final String author, final String branch, final String startCommitSha) {
String url =String.format("/repos/%s/%s/commits?author=%s", owner.login, name, author);
url = url + String.format("&sha=%s", branch);
if (startCommitSha != null && !startCommitSha.isEmpty()) {
url = url + String.format("&sha=%s", startCommitSha);
}
final String finalUrl = url;
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(finalUrl, GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(GHRepository.this);
}
};
}
};
}

/**
* Lists all the commit by author for the given branch from the startCommitSha (startCommitSha is optional)
*/
public PagedIterable<GHCommit> listCommitsByAuthorAndBranch(final String author, final String branch,
final String startCommitSha, int pageSize) {
String url =String.format("/repos/%s/%s/commits?author=%s", owner.login, name, author);
url = url + String.format("&sha=%s", branch);
if (startCommitSha != null && !startCommitSha.isEmpty()) {
url = url + String.format("&sha=%s", startCommitSha);
}
url = url + String.format("&per_page=%s", pageSize);
final String finalUrl = url;
return new PagedIterable<GHCommit>() {
public PagedIterator<GHCommit> iterator() {
return new PagedIterator<GHCommit>(root.retrieve().asIterator(finalUrl, GHCommit[].class)) {
protected void wrapUp(GHCommit[] page) {
for (GHCommit c : page)
c.wrapUp(GHRepository.this);
}
};
}
};
}

/**
* Lists up all the commit comments in this repository.
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
*/
package org.kohsuke.github;

import org.apache.commons.io.IOUtils;
import static org.kohsuke.github.GitHub.MAPPER;

import javax.net.ssl.HttpsURLConnection;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -48,7 +47,7 @@
import java.util.Set;
import java.util.zip.GZIPInputStream;

import static org.kohsuke.github.GitHub.MAPPER;
import org.apache.commons.io.IOUtils;

/**
* A builder pattern for making HTTP call and parsing its output.
Expand Down Expand Up @@ -294,7 +293,7 @@ private void findNextURL(HttpURLConnection uc) throws MalformedURLException {


private HttpURLConnection setupConnection(URL url) throws IOException {
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
HttpURLConnection uc = (HttpURLConnection) url.openConnection();

// if the authentication is needed but no credential is given, try it anyway (so that some calls
// that do work with anonymous access in the reduced form should still work.)
Expand Down