use of com.google.copybara.git.github.api.CreateStatusRequest in project copybara by google.
the class AbstractGithubApiTest method testCreateStatus.
@Test
public void testCreateStatus() throws Exception {
trainMockPost("/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", createValidator(TestCreateStatusRequest.class, csr -> csr.getContext().equals("continuous-integration/jenkins") && csr.getState().equals(State.SUCCESS)), getResource("create_status_response_testdata.json"));
Status response = api.createStatus("octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e", new CreateStatusRequest(State.SUCCESS, "https://ci.example.com/1000/output", "Build has completed successfully", "continuous-integration/jenkins"));
assertThat(response.getContext()).isEqualTo("continuous-integration/jenkins");
assertThat(response.getTargetUrl()).isEqualTo("https://ci.example.com/1000/output");
assertThat(response.getDescription()).isEqualTo("Build has completed successfully");
assertThat(response.getState()).isEqualTo(State.SUCCESS);
assertThat(response.getCreator()).isNotNull();
assertThat(response.getCreator().getLogin()).isEqualTo("octocat");
}
use of com.google.copybara.git.github.api.CreateStatusRequest in project copybara by google.
the class AbstractGitHubApiTest method testCreateStatus.
@Test
public void testCreateStatus() throws Exception {
trainMockPost("/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", createValidator(TestCreateStatusRequest.class, csr -> csr.getContext().equals("continuous-integration/jenkins") && csr.getState().equals(State.SUCCESS)), getResource("create_status_response_testdata.json"));
Status response = api.createStatus("octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e", new CreateStatusRequest(State.SUCCESS, "https://ci.example.com/1000/output", "Build has completed successfully", "continuous-integration/jenkins"));
assertThat(response.getContext()).isEqualTo("continuous-integration/jenkins");
assertThat(response.getTargetUrl()).isEqualTo("https://ci.example.com/1000/output");
assertThat(response.getDescription()).isEqualTo("Build has completed successfully");
assertThat(response.getState()).isEqualTo(State.SUCCESS);
assertThat(response.getCreator()).isNotNull();
assertThat(response.getCreator().getLogin()).isEqualTo("octocat");
}
use of com.google.copybara.git.github.api.CreateStatusRequest in project copybara by google.
the class GitHubEndPoint method createStatus.
@StarlarkMethod(name = "create_status", doc = "Create or update a status for a commit. Returns the status created.", parameters = { @Param(name = "sha", named = true, doc = "The SHA-1 for which we want to create or update the status"), @Param(name = "state", named = true, doc = "The state of the commit status: 'success', 'error', 'pending' or 'failure'"), @Param(name = "context", doc = "The context for the commit status. Use a value like 'copybara/import_successful'" + " or similar", named = true), @Param(name = "description", named = true, doc = "Description about what happened"), @Param(name = "target_url", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "Url with expanded information about the event", defaultValue = "None") })
public Status createStatus(String sha, String state, String context, String description, Object targetUrl) throws EvalException, RepoException, ValidationException {
try {
checkCondition(State.VALID_VALUES.contains(state), "Invalid value for state. Valid values: %s", State.VALID_VALUES);
checkCondition(GitRevision.COMPLETE_SHA1_PATTERN.matcher(sha).matches(), "Not a valid complete SHA-1: %s", sha);
checkCondition(!Strings.isNullOrEmpty(description), "description cannot be empty");
checkCondition(!Strings.isNullOrEmpty(context), "context cannot be empty");
String project = ghHost.getProjectNameFromUrl(url);
return apiSupplier.load(console).createStatus(project, sha, new CreateStatusRequest(State.valueOf(state.toUpperCase()), convertFromNoneable(targetUrl, null), description, context));
} catch (GitHubApiException gae) {
if (gae.getResponseCode() == ResponseCode.UNPROCESSABLE_ENTITY) {
throw new ValidationException("GitHub was unable to process the request " + gae.getError(), gae);
}
throw gae;
} catch (ValidationException | RuntimeException e) {
throw Starlark.errorf("Error calling create_status: %s", e.getMessage());
}
}
Aggregations