use of org.eclipse.egit.github.core.service.PullRequestService 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();
}
use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method createUpdatePullRequestStatuses.
@Override
@SneakyThrows
public List<PullRequestStatus> createUpdatePullRequestStatuses(MigratePullRequestStatusRequest request) {
GitHubClient client = createClient(request.getAccessToken());
PullRequestService pullRequestService = new PullRequestService(client);
String commitStatusUrl = request.getCommitStatusUrl();
String accessToken = request.getAccessToken();
List<PullRequestStatus> results = new ArrayList<>();
for (String repositoryId : request.getRepositoryIds()) {
RepositoryId repository = RepositoryId.createFromId(repositoryId);
List<PullRequest> repositoryPullRequests = pullRequestService.getPullRequests(repository, "open");
for (PullRequest pullRequest : repositoryPullRequests) {
PullRequestStatus status = new PullRequestStatus();
String sha = pullRequest.getHead().getSha();
String syncUrl = UriComponentsBuilder.fromHttpUrl(request.getBaseSyncUrl()).queryParam("repositoryId", repositoryId).queryParam("pullRequestId", pullRequest.getNumber()).build().toUriString();
status.setPullRequestId(pullRequest.getNumber());
status.setRepoId(repositoryId);
status.setSha(sha);
status.setGitHubUsername(pullRequest.getUser().getLogin());
status.setUrl(commitStatusUrl);
status.setAccessToken(accessToken);
status.setFaqUrl(request.getFaqUrl());
status.setSyncUrl(syncUrl);
status.setPullRequestState(pullRequest.getState());
results.add(status);
}
}
return results;
}
use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method findPullRequest.
@Override
@SneakyThrows
public Optional<PullRequest> findPullRequest(String repoId, int pullRequestId, String accessToken) {
GitHubClient client = createClient(accessToken);
PullRequestService service = new PullRequestService(client);
try {
return Optional.ofNullable(service.getPullRequest(RepositoryId.createFromId(repoId), pullRequestId));
} catch (RequestException e) {
if (e.getStatus() == HttpStatus.NOT_FOUND.value()) {
return Optional.empty();
}
throw e;
}
}
use of org.eclipse.egit.github.core.service.PullRequestService in project jbpm-work-items by kiegroup.
the class MergePullRequestWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
Map<String, Object> results = new HashMap<String, Object>();
String repoOwner = (String) workItem.getParameter("RepoOwner");
String repoName = (String) workItem.getParameter("RepoName");
String pullRequestNum = (String) workItem.getParameter("PullRequestNum");
String commitMessage = (String) workItem.getParameter("CommitMessage");
MergeStatus mergeStatus;
if (StringUtils.isNotEmpty(repoOwner) && StringUtils.isNotEmpty(repoName) && StringUtils.isNumeric(pullRequestNum)) {
PullRequestService pullRequestService = auth.getPullRequestService(this.userName, this.password);
RepositoryId repositoryId = new RepositoryId(repoOwner, repoName);
if (pullRequestService.getPullRequest(repositoryId, Integer.parseInt(pullRequestNum)).isMergeable()) {
mergeStatus = pullRequestService.merge(repositoryId, Integer.parseInt(pullRequestNum), commitMessage);
results.put(RESULTS_VALUE, mergeStatus.isMerged());
} else {
results.put(RESULTS_VALUE, false);
}
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing repository and pull request info.");
throw new IllegalArgumentException("Missing repository and pull request info.");
}
} catch (Exception e) {
handleException(e);
}
}
use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method getShaForPullRequest.
@SneakyThrows
public String getShaForPullRequest(PullRequestId pullRequestId) {
PullRequestService service = getPullRequestService();
PullRequest pullRequest = service.getPullRequest(pullRequestId.getRepositoryId(), pullRequestId.getId());
if (pullRequest == null) {
throw new IllegalArgumentException(String.format("Cannot find Pull-request %s#%s", pullRequestId.getRepositoryId(), pullRequestId.getId()));
}
return pullRequest.getHead().getSha();
}
Aggregations