private String getBody(String fileName, String fileContent) { JsonObject files = new JsonObject(); JsonObject singleFile = new JsonObject(); singleFile.put("content", fileContent); files.put(fileName, singleFile); JsonObject body = new JsonObject(); body.put("files", files); body.put("public", "true"); body.put("description", fileName); return body.toJson(); } }
private String getBody(String fileName, String fileContent) { JsonObject files = new JsonObject(); JsonObject singleFile = new JsonObject(); singleFile.put("content", fileContent); files.put(fileName, singleFile); JsonObject body = new JsonObject(); body.put("files", files); body.put("public", "true"); body.put("description", fileName); return body.toJson(); } }
public void postTaskOnComment(String message, Long commentId) { String request = baseUrl + TASKS_API; JsonObject anchor = new JsonObject(); anchor.put("id", commentId); anchor.put("type", "COMMENT"); JsonObject json = new JsonObject(); json.put("anchor", anchor); json.put("text", message); postCreate(request, json, MessageFormat.format(TASK_POST_ERROR_MESSAGE, commentId)); }
public void postCommentOnPullRequest(PullRequestRef pr, String report) { String request = MessageFormat.format(API_ONE_PR_ALL_COMMENTS, baseUrl, pr.project(), pr.repository(), pr.pullRequestId()); JsonObject json = new JsonObject(); json.put("text", report); postCreate(request, json, MessageFormat.format(COMMENT_POST_ERROR_MESSAGE, pr.repository(), pr.pullRequestId())); }
public void addPullRequestReviewer(PullRequestRef pr, long pullRequestVersion, List<StashUser> reviewers) { String request = MessageFormat.format(API_ONE_PR, baseUrl, pr.project(), pr.repository(), pr.pullRequestId()); JsonObject json = new JsonObject(); JsonArray jsonReviewers = new JsonArray(); for (StashUser reviewer : reviewers) { JsonObject reviewerName = new JsonObject(); reviewerName.put("name", reviewer.getName()); JsonObject user = new JsonObject(); user.put("user", reviewerName); jsonReviewers.add(user); } json.put("reviewers", jsonReviewers); json.put("id", pr.pullRequestId()); json.put("version", pullRequestVersion); put(request, json, MessageFormat.format(PULL_REQUEST_PUT_ERROR_MESSAGE, pr.repository(), pr.pullRequestId())); }
private JsonObject getStatusCheck(MergePullRequestTask task, GitHubApi gitHubApi) throws IOException { String relativeUrl = "/repos/" + task.getUpstreamRepositoryName() + "/commits/" + task.getPullRequestSha() + "/status"; LOG.lifecycle("Using {} for status check", relativeUrl); String statusesResponse = gitHubApi.get(relativeUrl); return Jsoner.deserialize(statusesResponse, new JsonObject()); }
private JsonObject getStatusCheck(MergePullRequestTask task, GitHubApi gitHubApi) throws IOException { String relativeUrl = "/repos/" + task.getUpstreamRepositoryName() + "/commits/" + task.getPullRequestSha() + "/status"; LOG.lifecycle("Using {} for status check", relativeUrl); String statusesResponse = gitHubApi.get(relativeUrl); return Jsoner.deserialize(statusesResponse, new JsonObject()); }
public StashComment postCommentLineOnPullRequest(PullRequestRef pr, String message, String path, long line, IssueType type) { String request = MessageFormat.format(API_ONE_PR_ALL_COMMENTS, baseUrl, pr.project(), pr.repository(), pr.pullRequestId()); JsonObject anchor = new JsonObject(); if (line != 0L) { anchor.put("line", line); anchor.put("lineType", type.name()); } String fileType = "TO"; if (type == IssueType.CONTEXT) { fileType = "FROM"; } anchor.put("fileType", fileType); anchor.put("path", path); JsonObject json = new JsonObject(); json.put("text", message); json.put("anchor", anchor); JsonObject response = postCreate(request, json, MessageFormat.format(COMMENT_POST_ERROR_MESSAGE, pr.repository(), pr.pullRequestId())); return StashCollector.extractComment(response, path, line); }
public PullRequest createPullRequest(CreatePullRequestTask task, GitHubApi gitHubApi) throws IOException { if (task.isDryRun()) { LOG.lifecycle(" Skipping pull request creation due to dryRun = true"); return null; } String headBranch = BranchUtils.getHeadBranch(task.getForkRepositoryName(), task.getVersionBranch()); IncubatingWarning.warn("creating pull requests"); LOG.lifecycle(" Creating a pull request of title '{}' in repository '{}' between base = '{}' and head = '{}'.", task.getPullRequestTitle(), task.getUpstreamRepositoryName(), task.getBaseBranch(), headBranch); String body = "{" + " \"title\": \"" + task.getPullRequestTitle() + "\"," + " \"body\": \"" + task.getPullRequestDescription() + "\"," + " \"head\": \"" + headBranch + "\"," + " \"base\": \"" + task.getBaseBranch() + "\"," + " \"maintainer_can_modify\": true" + "}"; String response = gitHubApi.post("/repos/" + task.getUpstreamRepositoryName() + "/pulls", body); JsonObject pullRequest = Jsoner.deserialize(response, new JsonObject()); return toPullRequest(pullRequest); } }
public PullRequest createPullRequest(CreatePullRequestTask task, GitHubApi gitHubApi) throws IOException { if (task.isDryRun()) { LOG.lifecycle(" Skipping pull request creation due to dryRun = true"); return null; } String headBranch = BranchUtils.getHeadBranch(task.getForkRepositoryName(), task.getVersionBranch()); IncubatingWarning.warn("creating pull requests"); LOG.lifecycle(" Creating a pull request of title '{}' in repository '{}' between base = '{}' and head = '{}'.", task.getPullRequestTitle(), task.getUpstreamRepositoryName(), task.getBaseBranch(), headBranch); String body = "{" + " \"title\": \"" + task.getPullRequestTitle() + "\"," + " \"body\": \"" + task.getPullRequestDescription() + "\"," + " \"head\": \"" + headBranch + "\"," + " \"base\": \"" + task.getBaseBranch() + "\"," + " \"maintainer_can_modify\": true" + "}"; String response = gitHubApi.post("/repos/" + task.getUpstreamRepositoryName() + "/pulls", body); JsonObject pullRequest = Jsoner.deserialize(response, new JsonObject()); return toPullRequest(pullRequest); } }