Search in sources :

Example 1 with MergeStatus

use of org.eclipse.egit.github.core.MergeStatus 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);
    }
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) HashMap(java.util.HashMap) MergeStatus(org.eclipse.egit.github.core.MergeStatus) RepositoryId(org.eclipse.egit.github.core.RepositoryId)

Aggregations

HashMap (java.util.HashMap)1 MergeStatus (org.eclipse.egit.github.core.MergeStatus)1 RepositoryId (org.eclipse.egit.github.core.RepositoryId)1 PullRequestService (org.eclipse.egit.github.core.service.PullRequestService)1