use of org.zaproxy.zap.GitHubUser in project zaproxy by zaproxy.
the class CreateGitHubRelease method createRelease.
@TaskAction
public void createRelease() throws IOException {
if (bodyFile.isPresent() && body.isPresent()) {
throw new InvalidUserDataException("Only one type of body property must be set.");
}
if (checksumAlgorithm.get().isEmpty()) {
throw new IllegalArgumentException("The checksum algorithm must not be empty.");
}
GitHubUser ghUser = getUser().get();
GHRepository ghRepo = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(repo.get());
validateTagExists(ghRepo, tag.get());
validateReleaseDoesNotExist(ghRepo, tag.get());
StringBuilder releaseBody = new StringBuilder(250);
releaseBody.append(bodyFile.isPresent() ? readContents(bodyFile.getAsFile().get().toPath()) : body.getOrElse(""));
if (addChecksums.get()) {
if (releaseBody.length() != 0) {
releaseBody.append("\n\n---\n");
}
appendChecksumsTable(releaseBody);
}
GHRelease release = ghRepo.createRelease(tag.get()).name(title.get()).body(releaseBody.toString()).prerelease(prerelease.get()).draft(true).create();
for (Asset asset : assets) {
release.uploadAsset(asset.getFile().getAsFile().get(), asset.getContentType().get());
}
if (!draft.get()) {
release.update().draft(false).update();
}
}
use of org.zaproxy.zap.GitHubUser in project zaproxy by zaproxy.
the class CreateTagAndGitHubRelease method createTag.
private void createTag() throws Exception {
Repository repository = new FileRepositoryBuilder().setGitDir(new File(getProject().getRootDir(), ".git")).build();
try (Git git = new Git(repository)) {
URIish originUri = new URIish(GITHUB_BASE_URL + getRepo().get());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
GitHubUser ghUser = getUser().get();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
Ref tag = git.tag().setName(getTag().get()).setMessage(getTagMessage().get()).setAnnotated(true).setTagger(personIdent).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).add(tag).call();
}
}
use of org.zaproxy.zap.GitHubUser 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);
}
}
}
use of org.zaproxy.zap.GitHubUser in project zaproxy by zaproxy.
the class SendRepositoryDispatch method createConnection.
private HttpURLConnection createConnection() {
String url = String.format("https://api.github.com/repos/%s/dispatches", getGitHubRepo().get().toString());
HttpURLConnection connection;
try {
connection = (HttpURLConnection) new URL(url).openConnection();
} catch (IOException e) {
throw new BuildException("Failed to create the connection:", e);
}
connection.setDoOutput(true);
connection.setUseCaches(false);
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new BuildException("Failed to create the connection:", e);
}
connection.setRequestProperty("Accept", "application/vnd.github.v3+json");
connection.setRequestProperty("Content-Type", "application/json");
GitHubUser user = getGitHubUser().get();
String userName = user.getName();
String token = user.getAuthToken();
byte[] usernameAuthToken = (userName + ":" + token).getBytes(StandardCharsets.UTF_8);
String authorization = "Basic " + Base64.getEncoder().encodeToString(usernameAuthToken);
connection.setRequestProperty("Authorization", authorization);
return connection;
}
Aggregations