Forked from xjasonlyu/github-actions-workflow-dispatcher.js
Created
January 28, 2024 12:49
-
-
Save definiteIymaybe/551809e5521354f34f555e88c62ca7f1 to your computer and use it in GitHub Desktop.
Cloudflare Worker Snippets
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
addEventListener('scheduled', event => { | |
event.waitUntil(handleSchedule(event.scheduledTime)) | |
}) | |
async function handleSchedule(scheduledDate) { | |
const url = `https://api.github.com/repos/${OWNER}/${REPO}/actions/workflows/${WORKFLOW_ID}/dispatches` | |
await fetch(url, { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/vnd.github+json', | |
'Authorization': `Bearer ${TOKEN}`, | |
'X-GitHub-Api-Version': '2022-11-28', | |
'Content-Type': 'application/json', | |
'User-Agent': `Cloudflare-Workers/${scheduledDate}`, | |
}, | |
body: JSON.stringify({ | |
// The git reference for the workflow. | |
'ref': `${REF}` | |
}), | |
}).then(resp => console.log(resp.status)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment