Skip to content

Instantly share code, notes, and snippets.

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 definiteIymaybe/551809e5521354f34f555e88c62ca7f1 to your computer and use it in GitHub Desktop.
Save definiteIymaybe/551809e5521354f34f555e88c62ca7f1 to your computer and use it in GitHub Desktop.
Cloudflare Worker Snippets
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