-
Notifications
You must be signed in to change notification settings - Fork 97
Add RepositoryClient.listPullRequestsForCommit #100
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import static com.spotify.github.v3.clients.GitHubClient.LIST_BRANCHES; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_FOLDERCONTENT_TYPE_REFERENCE; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_REPOSITORY; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_STATUS_TYPE_REFERENCE; | ||
|
||
|
@@ -34,6 +35,7 @@ | |
import com.spotify.github.v3.exceptions.RequestNotOkException; | ||
import com.spotify.github.v3.git.Tree; | ||
import com.spotify.github.v3.hooks.requests.WebhookCreate; | ||
import com.spotify.github.v3.prs.PullRequestItem; | ||
import com.spotify.github.v3.repos.Branch; | ||
import com.spotify.github.v3.repos.Commit; | ||
import com.spotify.github.v3.repos.CommitComparison; | ||
|
@@ -49,9 +51,11 @@ | |
import java.lang.invoke.MethodHandles; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -69,6 +73,7 @@ public class RepositoryClient { | |
public static final String STATUS_URI_TEMPLATE = "/repos/%s/%s/statuses/%s"; | ||
private static final String COMMITS_URI_TEMPLATE = "/repos/%s/%s/commits"; | ||
private static final String COMMIT_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s"; | ||
private static final String COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s/pulls"; | ||
private static final String COMMIT_STATUS_URI_TEMPLATE = "/repos/%s/%s/commits/%s/status"; | ||
private static final String TREE_SHA_URI_TEMPLATE = "/repos/%s/%s/git/trees/%s"; | ||
private static final String COMPARE_COMMIT_TEMPLATE = "/repos/%s/%s/compare/%s...%s"; | ||
|
@@ -272,6 +277,22 @@ public CompletableFuture<List<CommitItem>> listCommits() { | |
return github.request(path, LIST_COMMIT_TYPE_REFERENCE); | ||
} | ||
|
||
/** | ||
* List pull requests that contain the given commit. | ||
* | ||
* @param sha commit sha | ||
* @return pull requests | ||
*/ | ||
public CompletableFuture<List<PullRequestItem>> listPullRequestsForCommit(final String sha) { | ||
final String path = String.format(COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE, owner, repo, sha); | ||
|
||
// As of GHE 3.2, this feature is still in preview, so we need to add the extra header. | ||
// https://developer.github.com/changes/2019-04-11-pulls-branches-for-commit/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great addition. |
||
final Map<String, String> extraHeaders = | ||
ImmutableMap.of(HttpHeaders.ACCEPT, "application/vnd.github.groot-preview+json"); | ||
return github.request(path, LIST_PR_TYPE_REFERENCE, extraHeaders); | ||
} | ||
|
||
/** | ||
* Get a repository commit. | ||
* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an alternative class which we could use
com.google.common.net.HttpHeaders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied this from other classes in this project, doesn't matter much I think 🤷