Search in sources :

Example 1 with PullRequestMarker

use of org.eclipse.egit.github.core.PullRequestMarker in project pivotal-cla by pivotalsoftware.

the class SmokeTests method createPullRequest.

/**
 * @return the HTML link of the Pull Request
 * @throws InterruptedException
 */
private static String createPullRequest(User user, int count) throws IOException, InterruptedException {
    GitHubClient client = createClient(user.getGitHubAccessToken());
    PullRequestService pulls = new PullRequestService(client);
    RestTemplate rest = new RestTemplate();
    // get sha for master
    DataService references = new DataService(client);
    RepositoryId forkRepositoryId = RepositoryId.create(user.getGitHubUsername(), "cla-test");
    Reference forked = references.getReference(forkRepositoryId, "heads/master");
    // create a branch for our Pull Request
    Reference createPullRequestBranch = new Reference();
    createPullRequestBranch.setRef("refs/heads/pull-" + count);
    createPullRequestBranch.setObject(forked.getObject());
    references.createReference(forkRepositoryId, createPullRequestBranch);
    // create a file for our Pull Request
    Map<String, String> content = new HashMap<>();
    content.put("message", "We added some content for " + count);
    content.put("content", "bXkgbmV3IGZpbGUgY29udGVudHM=");
    content.put("branch", "pull-" + count);
    rest.put("https://api.github.com/repos/{owner}/{repo}/contents/forPullRequest?access_token={token}", content, user.getGitHubUsername(), "cla-test", user.getGitHubAccessToken());
    PullRequest request = new PullRequest();
    request.setTitle("Please merge");
    request.setBody("Please merge");
    PullRequestMarker head = new PullRequestMarker();
    head.setLabel(signUser.getGitHubUsername() + ":pull-" + count);
    request.setHead(head);
    PullRequestMarker base = new PullRequestMarker();
    base.setLabel("master");
    request.setBase(base);
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    PullRequest newPull = pulls.createPullRequest(RepositoryId.createFromId(linkUser.getGitHubUsername() + "/" + "cla-test"), request);
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    return newPull.getHtmlUrl();
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) HashMap(java.util.HashMap) Reference(org.eclipse.egit.github.core.Reference) PullRequest(org.eclipse.egit.github.core.PullRequest) RestTemplate(org.springframework.web.client.RestTemplate) PullRequestMarker(org.eclipse.egit.github.core.PullRequestMarker) RepositoryId(org.eclipse.egit.github.core.RepositoryId) DataService(org.eclipse.egit.github.core.service.DataService)

Aggregations

HashMap (java.util.HashMap)1 PullRequest (org.eclipse.egit.github.core.PullRequest)1 PullRequestMarker (org.eclipse.egit.github.core.PullRequestMarker)1 Reference (org.eclipse.egit.github.core.Reference)1 RepositoryId (org.eclipse.egit.github.core.RepositoryId)1 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)1 DataService (org.eclipse.egit.github.core.service.DataService)1 PullRequestService (org.eclipse.egit.github.core.service.PullRequestService)1 RestTemplate (org.springframework.web.client.RestTemplate)1