'Create a Pull Request in Github from a Java Application

I'm trying to create a pull request from my Java application but I can't find any documentation for Github's Java API.

I already implemented all the methods for adding a file, commit, and push.

Any useful links?



Solution 1:[1]

There are several Java APIs listed in the GitHub developer guide:

https://developer.github.com/libraries/ (search for 'Java')

Solution 2:[2]

I created on Spring boot and HTML project for taking a pull on private GitHub repository to ubuntu server

use this maven dependency

<dependency>
        <groupId>org.eclipse.jgit</groupId>
        <artifactId>org.eclipse.jgit</artifactId>
        <version>5.11.0.202103091610-r</version>
</dependency>
Make Sure the Github project present in your local storage
dir - is your location where this project is present in your local Director
gitDir - is your github repository url
username and password is your github username and password

public String pullReq(String dir, String gitDir, String userName, String pass) {

    try {
        
        Repository localRepo = new FileRepository(dir + "/.git");
        Git git = new Git(localRepo);
        CredentialsProvider cp = new UsernamePasswordCredentialsProvider(userName, pass);
        git.pull().setCredentialsProvider(cp).call();
        git.close();
        localRepo.close();
    
    } catch (Exception e) {
        return e.getLocalizedMessage();
    }
    return "success";

}

Github plan to remove UsernamePasswordCredentialsProvider authentication.
I don't know how many days this code is working but currently, it is working.
Github is asking to Use Token Based authentication.

Solution 3:[3]

the link of Ruediger is dead:

here is a list of more up to date links:

this would be the api function: https://github-api.kohsuke.org/apidocs/org/kohsuke/github/GHRepository.html#createPullRequest(java.lang.String,java.lang.String,java.lang.String,java.lang.String)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rüdiger Herrmann
Solution 2 Arun Patel
Solution 3