Last active
March 2, 2023 08:22
-
-
Save masterflitzer/45b7c5936071c21acf80a8eb69aac74a to your computer and use it in GitHub Desktop.
Find unverified commits in your GitHub repositories
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
import { writeFile } from "fs/promises"; | |
import { Octokit } from "octokit"; | |
import ProxyAgent from "proxy-agent"; | |
const apiToken = process.env.API_TOKEN; | |
const output = process.argv[2] ?? "-"; | |
if (apiToken == null) { | |
console.error("API_TOKEN was empty!"); | |
console.info("Please set the API_TOKEN environment variable:"); | |
console.info("bash: export API_TOKEN='github_pat_XXX'"); | |
console.info("pwsh: $env:API_TOKEN = 'github_pat_XXX'"); | |
process.exit(1); | |
} | |
const gh = new Octokit({ | |
auth: apiToken, | |
request: { | |
agent: new ProxyAgent(), | |
}, | |
}); | |
const headers = { | |
Accept: "application/vnd.github+json", | |
"X-GitHub-Api-Version": "2022-11-28", | |
}; | |
const username = ( | |
await gh.request("GET /user", { | |
headers, | |
}) | |
).data.login; | |
const repos = await gh.paginate("GET /user/repos", { | |
headers, | |
}); | |
let results = new Array(); | |
for (const repo of repos) { | |
const owner = repo.owner.login; | |
const name = repo.name; | |
const commits = ( | |
await gh.paginate("GET /repos/{owner}/{repo}/commits", { | |
headers, | |
owner, | |
repo: name, | |
}) | |
) | |
.map((x) => x.commit) | |
.filter( | |
(x) => | |
x.author.name.toLowerCase() === username.toLowerCase() || | |
x.committer.name.toLowerCase() == username.toLowerCase() | |
); | |
const unverified = commits.filter((x) => !x.verification.verified); | |
results = results.concat(unverified); | |
} | |
const json = JSON.stringify(results, null, 2); | |
if (output === "-") { | |
console.info(json); | |
} else { | |
writeFile(output, json, { | |
encoding: "utf8", | |
}); | |
} |
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
{ | |
"name": "github-unverified-commits", | |
"version": "1.0.0", | |
"author": "Masterflitzer <[email protected]>", | |
"main": "github-unverified-commits.js", | |
"type": "module", | |
"license": "MIT", | |
"scripts": { | |
"start": "node github-unverified-commits.js" | |
}, | |
"dependencies": { | |
"octokit": "^2.0.14", | |
"proxy-agent": "^5.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment