use of org.zaproxy.zap.GitHubRepo in project zaproxy by zaproxy.
the class CreatePullRequest method pullRequest.
@TaskAction
public void pullRequest() throws Exception {
GitHubRepo ghRepo = getRepo().get();
Repository repository = new FileRepositoryBuilder().setGitDir(new File(ghRepo.getDir(), ".git")).build();
try (Git git = new Git(repository)) {
if (git.status().call().getModified().isEmpty()) {
return;
}
GitHubUser ghUser = getUser().get();
URIish originUri = new URIish(GITHUB_BASE_URL + ghUser.getName() + "/" + ghRepo.getName());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
git.checkout().setCreateBranch(true).setName(getBranchName().get()).setStartPoint(GIT_REMOTE_ORIGIN + "/" + baseBranchName.get()).call();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
git.commit().setAll(true).setSign(false).setAuthor(personIdent).setCommitter(personIdent).setMessage(getCommitSummary().get() + "\n\n" + getCommitDescription().get() + signedOffBy(personIdent)).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).setForce(true).add(getBranchName().get()).call();
GHRepository ghRepository = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(ghRepo.toString());
List<GHPullRequest> pulls = ghRepository.queryPullRequests().base(baseBranchName.get()).head(ghUser.getName() + ":" + getBranchName().get()).state(GHIssueState.OPEN).list().asList();
String description = getPullRequestDescription().getOrElse(getCommitDescription().get());
if (pulls.isEmpty()) {
String title = getPullRequestTitle().getOrElse(getCommitSummary().get());
createPullRequest(ghRepository, title, description);
} else {
pulls.get(0).setBody(description);
}
}
}
Aggregations