Skip to content

Instantly share code, notes, and snippets.

@gregsadetsky
Last active November 16, 2023 18:56
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 gregsadetsky/47357f6f5ceeea8a898aafbaa8375c50 to your computer and use it in GitHub Desktop.
Save gregsadetsky/47357f6f5ceeea8a898aafbaa8375c50 to your computer and use it in GitHub Desktop.
function logAnalytics() {
// GITHUB ACTIONS FREE ANALYTICS
// create a github personal token and insert it here
// ONLY give it actions:write permissions on a SINGLE repo, which is bad, but not, I think, extra extra bad
const githubPat = "github_pat_INSERT_YOUR_PERSONAL_TOKEN_HERE";
// this is YOUR repo where you'd want your log files
const githubRepo = "gregsadetsky/github-actions-free-analytics";
const githubApiVersion = "2022-11-28";
// replace this with the ID of your workflow -- I use `gh workflow list` i.e. the GitHub CLI tool to find the ID
const githubWorkflowId = "76361355";
const githubWorkflowInputs = {
// this is the part where you'd pass some useful payload to the server to log
// it could be just the date for example
"incomingRequest": "{\"key\": \"value\"}"
};
fetch(`https://api.github.com/repos/${githubRepo}/actions/workflows/${githubWorkflowId}/dispatches`, {
method: "POST",
headers: {
"Accept": "application/vnd.github+json",
"Authorization": `Bearer ${githubPat}`,
"X-GitHub-Api-Version": githubApiVersion
},
body: JSON.stringify({
ref: "main",
inputs: githubWorkflowInputs
})
}).then(function(response) {
console.log(response)
document.getElementById("app")!.innerHTML += `<div>logged!! ${new Date()}</div>`;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment