Skip to content

Instantly share code, notes, and snippets.

@masterflitzer
Last active March 2, 2023 08:22
Show Gist options
  • Save masterflitzer/45b7c5936071c21acf80a8eb69aac74a to your computer and use it in GitHub Desktop.
Save masterflitzer/45b7c5936071c21acf80a8eb69aac74a to your computer and use it in GitHub Desktop.
Find unverified commits in your GitHub repositories
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",
});
}
{
"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