2424import static com .spotify .github .v3 .clients .GitHubClient .LIST_BRANCHES ;
2525import static com .spotify .github .v3 .clients .GitHubClient .LIST_COMMIT_TYPE_REFERENCE ;
2626import static com .spotify .github .v3 .clients .GitHubClient .LIST_FOLDERCONTENT_TYPE_REFERENCE ;
27+ import static com .spotify .github .v3 .clients .GitHubClient .LIST_PR_TYPE_REFERENCE ;
2728import static com .spotify .github .v3 .clients .GitHubClient .LIST_REPOSITORY ;
2829import static com .spotify .github .v3 .clients .GitHubClient .LIST_STATUS_TYPE_REFERENCE ;
2930
3435import com .spotify .github .v3 .exceptions .RequestNotOkException ;
3536import com .spotify .github .v3 .git .Tree ;
3637import com .spotify .github .v3 .hooks .requests .WebhookCreate ;
38+ import com .spotify .github .v3 .prs .PullRequestItem ;
3739import com .spotify .github .v3 .repos .Branch ;
3840import com .spotify .github .v3 .repos .Commit ;
3941import com .spotify .github .v3 .repos .CommitComparison ;
4951import java .lang .invoke .MethodHandles ;
5052import java .util .Iterator ;
5153import java .util .List ;
54+ import java .util .Map ;
5255import java .util .Optional ;
5356import java .util .concurrent .CompletableFuture ;
5457import java .util .concurrent .CompletionException ;
58+ import javax .ws .rs .core .HttpHeaders ;
5559import org .slf4j .Logger ;
5660import org .slf4j .LoggerFactory ;
5761
@@ -69,6 +73,7 @@ public class RepositoryClient {
6973 public static final String STATUS_URI_TEMPLATE = "/repos/%s/%s/statuses/%s" ;
7074 private static final String COMMITS_URI_TEMPLATE = "/repos/%s/%s/commits" ;
7175 private static final String COMMIT_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s" ;
76+ private static final String COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE = "/repos/%s/%s/commits/%s/pulls" ;
7277 private static final String COMMIT_STATUS_URI_TEMPLATE = "/repos/%s/%s/commits/%s/status" ;
7378 private static final String TREE_SHA_URI_TEMPLATE = "/repos/%s/%s/git/trees/%s" ;
7479 private static final String COMPARE_COMMIT_TEMPLATE = "/repos/%s/%s/compare/%s...%s" ;
@@ -272,6 +277,22 @@ public CompletableFuture<List<CommitItem>> listCommits() {
272277 return github .request (path , LIST_COMMIT_TYPE_REFERENCE );
273278 }
274279
280+ /**
281+ * List pull requests that contain the given commit.
282+ *
283+ * @param sha commit sha
284+ * @return pull requests
285+ */
286+ public CompletableFuture <List <PullRequestItem >> listPullRequestsForCommit (final String sha ) {
287+ final String path = String .format (COMMIT_PULL_REQUESTS_SHA_URI_TEMPLATE , owner , repo , sha );
288+
289+ // As of GHE 3.2, this feature is still in preview, so we need to add the extra header.
290+ // https://developer.github.com/changes/2019-04-11-pulls-branches-for-commit/
291+ final Map <String , String > extraHeaders =
292+ ImmutableMap .of (HttpHeaders .ACCEPT , "application/vnd.github.groot-preview+json" );
293+ return github .request (path , LIST_PR_TYPE_REFERENCE , extraHeaders );
294+ }
295+
275296 /**
276297 * Get a repository commit.
277298 *
0 commit comments