Skip to content

Instantly share code, notes, and snippets.

@fadookie
Last active October 21, 2024 23:25
Show Gist options
  • Save fadookie/6ca8027d272bf5fa21ec9020ba20afb4 to your computer and use it in GitHub Desktop.
Save fadookie/6ca8027d272bf5fa21ec9020ba20afb4 to your computer and use it in GitHub Desktop.
GitHub License Query Tool

This tool helps query your own GitHub repos to see which licenses you've used. It would be pretty easy to adapt this to query any user or organization's public repos, but I'll leave that as an exercise for the reader.

Open the GitHub GraphQL Explorer (or any GraphQL client) and run the provided query. If pageInfo.hasNextPage is true, use the provided cursor to query for the next page, see Using pagination in the GraphQL API for more info. Merging multiple pages for use by the JS collator script is also left as an exercise for the reader.

Then, run the JS code to collate the results, it's probably easiest to do in your browser's JS console but any JS REPL such as Node.JS will do.

var result = // Paste result from GraphQL query here
var groupings = result.data.viewer.repositories.nodes.reduce((acc, node) => {
const nickname = node.licenseInfo?.name || 'none' ;
if (!acc[nickname]) acc[nickname] = 0;
++acc[nickname];
return acc;
}, {});
console.log(groupings);
# Query current user's non-forked repositories for license info
query {
viewer {
repositories(isFork: false, first: 100) {
nodes {
name,
licenseInfo {
name
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment