From def2f0b37d4ea1e33fd0e80e4675749726985b21 Mon Sep 17 00:00:00 2001 From: Tadas Giniotis Date: Wed, 12 Aug 2020 01:56:23 +0300 Subject: [PATCH] methods for listing PRs where the commit is head & listing branches which contain the commit --- .../java/org/kohsuke/github/GHCommit.java | 35 +++++++++++++++++++ .../java/org/kohsuke/github/Previews.java | 8 +++++ 2 files changed, 43 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 5d13dd776..01784bf84 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -11,6 +11,8 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import static org.kohsuke.github.Previews.GROOT; + /** * A commit in a repository. * @@ -446,6 +448,39 @@ public class GHCommit { return owner.root.getUser(author.login); } + /** + * Retrieves a list of pull requests which contain this commit. + * + * @return {@link PagedIterable} with the pull requests which contain this commit + */ + @Preview + @Deprecated + public PagedIterable listPullRequests() { + return owner.root.createRequest() + .withPreview(GROOT) + .withUrlPath(String.format("/repos/%s/%s/commits/%s/pulls", owner.getOwnerName(), owner.getName(), sha)) + .toIterable(GHPullRequest[].class, item -> item.wrapUp(owner)); + } + + /** + * Retrieves a list of branches where this commit is the head commit. + * + * @return {@link PagedIterable} with the branches where the commit is the head commit + * @throws IOException + * the io exception + */ + @Preview + @Deprecated + public PagedIterable listBranchesWhereHead() throws IOException { + return owner.root.createRequest() + .withPreview(GROOT) + .withUrlPath(String.format("/repos/%s/%s/commits/%s/branches-where-head", + owner.getOwnerName(), + owner.getName(), + sha)) + .toIterable(GHBranch[].class, item -> item.wrap(owner)); + } + /** * List comments paged iterable. * diff --git a/src/main/java/org/kohsuke/github/Previews.java b/src/main/java/org/kohsuke/github/Previews.java index a50425f47..292bd7621 100644 --- a/src/main/java/org/kohsuke/github/Previews.java +++ b/src/main/java/org/kohsuke/github/Previews.java @@ -37,6 +37,14 @@ class Previews { */ static final String GAMBIT = "application/vnd.github.gambit-preview+json"; + /** + * List branches or pull requests for a commit + * + * @see GitHub API + * Previews + */ + static final String GROOT = "application/vnd.github.groot-preview+json"; + /** * Manage projects *