Last active
November 16, 2023 18:56
-
-
Save gregsadetsky/47357f6f5ceeea8a898aafbaa8375c50 to your computer and use it in GitHub Desktop.
This file contains 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
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