use of com.google.copybara.git.github.util.GitHubHost.GitHubPrUrl in project copybara by google.
the class GitHubPrOrigin method resolve.
@Override
public GitRevision resolve(String reference) throws RepoException, ValidationException {
checkCondition(reference != null, "" + "A pull request reference is expected as argument in the command line." + " Invoke copybara as:\n" + " copybara copy.bara.sky workflow_name 12345");
console.progress("GitHub PR Origin: Resolving reference " + reference);
String configProjectName = ghHost.getProjectNameFromUrl(url);
// GitHub's commit 'status' webhook provides only the commit SHA
if (GitRevision.COMPLETE_SHA1_PATTERN.matcher(reference).matches()) {
PullRequest pr = getPrFromSha(configProjectName, reference);
return getRevisionForPR(configProjectName, pr);
}
// A whole https pull request url
Optional<GitHubPrUrl> githubPrUrl = ghHost.maybeParseGithubPrUrl(reference);
if (githubPrUrl.isPresent()) {
checkCondition(githubPrUrl.get().getProject().equals(configProjectName), "Project name should be '%s' but it is '%s' instead", configProjectName, githubPrUrl.get().getProject());
return getRevisionForPR(configProjectName, getPrFromNumber(configProjectName, githubPrUrl.get().getPrNumber()));
}
// A Pull request number
if (CharMatcher.digit().matchesAllOf(reference)) {
return getRevisionForPR(ghHost.getProjectNameFromUrl(url), getPrFromNumber(configProjectName, Integer.parseInt(reference)));
}
// refs/pull/12345/head
Optional<Integer> prNumber = GitHubUtil.maybeParseGithubPrFromHeadRef(reference);
if (prNumber.isPresent()) {
return getRevisionForPR(configProjectName, getPrFromNumber(configProjectName, prNumber.get()));
}
throw new CannotResolveRevisionException(String.format("'%s' is not a valid reference for a GitHub Pull Request. Valid formats:" + "'https://github.com/project/pull/1234', 'refs/pull/1234/head' or '1234'", reference));
}
Aggregations