public PullRequest findOpenPullRequest(String upstreamRepositoryName, String versionBranchRegex, GitHubApi gitHubApi) throws IOException { String response = gitHubApi.get("/repos/" + upstreamRepositoryName + "/pulls?state=open"); JsonArray pullRequests = Jsoner.deserialize(response, new JsonArray()); for (Object pullRequest : pullRequests) { PullRequest openPullRequest = PullRequestUtils.toPullRequest((JsonObject) pullRequest); if (openPullRequest != null && openPullRequest.getRef().matches(versionBranchRegex)) { LOG.lifecycle(" Found an open pull request with version upgrade on branch {}", openPullRequest.getRef()); return openPullRequest; } } LOG.lifecycle(" New pull request will be opened because we didn't find an existing PR to reuse."); return null; } }
public PullRequest findOpenPullRequest(String upstreamRepositoryName, String versionBranchRegex, GitHubApi gitHubApi) throws IOException { String response = gitHubApi.get("/repos/" + upstreamRepositoryName + "/pulls?state=open"); JsonArray pullRequests = Jsoner.deserialize(response, new JsonArray()); for (Object pullRequest : pullRequests) { PullRequest openPullRequest = PullRequestUtils.toPullRequest((JsonObject) pullRequest); if (openPullRequest != null && openPullRequest.getRef().matches(versionBranchRegex)) { LOG.lifecycle(" Found an open pull request with version upgrade on branch {}", openPullRequest.getRef()); return openPullRequest; } } LOG.lifecycle(" New pull request will be opened because we didn't find an existing PR to reuse."); return null; } }
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); } }