Last active
October 10, 2022 11:54
-
-
Save cp-sumi-k/d13c90532c134f323e1c735fcda69275 to your computer and use it in GitHub Desktop.
https://blog.canopas.com/automation-trigger-github-workflow-from-the-backend-f04e818094e5 - workflow_final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare headers | |
const config = { | |
headers: { | |
Accept: "application/vnd.github+json", | |
Authorization: "Bearer " + PERSONAL_ACCESS_TOKEN(PAT) | |
} | |
}; | |
axios.get('https://api.github.com/repos/OWNER/REPO/actions/runs', config) | |
.then(res => { | |
// res contains list of workflows | |
const workflows = res.data["workflow_runs"].filter(function (workflow) { | |
return workflow.name == "WorkflowName"; | |
}) | |
// getting id of first workflow | |
const wID = workflows[0].id | |
axios.post( | |
"https://api.github.com/repos/OWENER/REPO/actions/runs/" + wId + "/rerun", | |
null, // request body will be null | |
{ headers: config.headers} //pass headers from config | |
); | |
}) | |
.catch(err => { | |
console.error(err.message) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment