How to create a pull request programmatically

218 views
Skip to first unread message

Henry Mikhail

unread,
Apr 22, 2019, 1:56:21 PM4/22/19
to GitHub Java API (http://github-api.kohsuke.org/)
Hi,
I am new to this api and was trying to figure out how to use this java API to create a pull request from one branch to another in the same repo.

Thanks,
Henry

Mani Bauer

unread,
Nov 12, 2019, 6:38:03 AM11/12/19
to GitHub Java API (http://github-api.kohsuke.org/)
Heja,

yes that is possible.

You need a GitHub object and get your repository via that.
GitHub github = GitHub.connectToEnterpriseWithOAuth(API_URL,
USER,
TOKEN);
GHRepository ghRepo = github.getRepository(Name of your Repo);

GHPullRequest newPr = ghRepo.createPullRequest(String title, String head, String base, String body);

The newPr is created at the specified repository. You can use the Object newPr to set more data in your pull request.

You can find info on the used classes here: https://github-api.kohsuke.org/apidocs/index.html

Mani Bauer

unread,
Nov 12, 2019, 6:40:34 AM11/12/19
to GitHub Java API (http://github-api.kohsuke.org/)
I forgot to mention that in ghRepo.createPullRequest(...) -> head is the name of the branch where your changes are implemented and base is the name of the branch where you want your changes pulled in to.
Reply all
Reply to author
Forward
0 new messages