use of com.google.copybara.git.github.api.UpdateReferenceRequest in project copybara by google.
the class GitHubEndPoint method updateReference.
@StarlarkMethod(name = "update_reference", doc = "Update a reference to point to a new commit. Returns the info of the reference.", parameters = { @Param(name = "ref", named = true, doc = "The name of the reference."), @Param(name = "sha", doc = "The id for the commit" + " status.", named = true), @Param(name = "force", named = true, doc = "Indicates whether to force the update or to make sure the update is a" + " fast-forward update. Leaving this out or setting it to false will make" + " sure you're not overwriting work. Default: false") })
public Ref updateReference(String sha, String ref, boolean force) throws EvalException, RepoException {
try {
checkCondition(GitRevision.COMPLETE_SHA1_PATTERN.matcher(sha).matches(), "Not a valid complete SHA-1: %s", sha);
checkCondition(!Strings.isNullOrEmpty(ref), "ref cannot be empty");
if (!ref.startsWith("refs/")) {
// TODO(malcon): Remove this functionality and use a check once library migrated.
console.warnFmt("Non-complete ref passed to update_reference '%s'. Assuming refs/heads/%s", ref, ref);
ref = "refs/heads/" + ref;
}
String project = ghHost.getProjectNameFromUrl(url);
return apiSupplier.load(console).updateReference(project, ref, new UpdateReferenceRequest(sha, force));
} catch (ValidationException | RuntimeException e) {
throw Starlark.errorf("Error calling update_reference: %s", e.getMessage());
}
}
use of com.google.copybara.git.github.api.UpdateReferenceRequest in project copybara by google.
the class AbstractGitHubApiTest method testUpdateReference.
@Test
public void testUpdateReference() throws Exception {
trainMockPost("/repos/octocat/Hello-World/git/refs/heads/test", createValidator(TestUpdateReferenceRequest.class, urr -> urr.getSha1().equals("6dcb09b5b57875f334f61aebed695e2e4193db5e") && urr.getForce()), getResource("update_reference_response_testdata.json"));
Ref response = api.updateReference("octocat/Hello-World", "refs/heads/test", new UpdateReferenceRequest("6dcb09b5b57875f334f61aebed695e2e4193db5e", true));
assertThat(response.getRef()).isEqualTo("refs/heads/test");
assertThat(response.getSha()).isEqualTo("6dcb09b5b57875f334f61aebed695e2e4193db5e");
assertThat(response.getUrl()).isEqualTo("https://api.github.com/repos/octocat/Hello-World/git/refs/heads/test");
}
Aggregations