Skip to content

Instantly share code, notes, and snippets.

@wlee221
Last active March 20, 2023 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlee221/09fb32cf9d42740536466a8733781d94 to your computer and use it in GitHub Desktop.
Save wlee221/09fb32cf9d42740536466a8733781d94 to your computer and use it in GitHub Desktop.
createCommitStatus example
const { status_context, description, state, sha, target_url, owner, repo } = process.env;
if (state.length === 0 || !["error", "failure", "pending", "success"].includes(state)) {
core.setFailed('"state" input cannot be empty.');
return;
}
if (!["error", "failure", "pending", "success"].includes(state)) {
core.setFailed('"state" must be a string input with possible value of (...).');
return;
}
if (context.length === 0) {
core.setFailed('"context" input cannot be empty.');
return;
}
if (sha.length === 0) {
core.setFailed('"sha" input cannot be empty.');
return;
}
if (!sha.match(/^[0-9a-z]+$/)) {
core.setFailed('"sha" must be an alphanumeric string.');
return;
}
github.rest.repos.createCommitStatus({
owner,
repo,
sha,
state,
context: status_context,
description: description.length > 0 ? description : undefined,
target_url: target_url.length > 0 ? target_url : undefined,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment