Skip to content

Instantly share code, notes, and snippets.

@bshaffer
Created November 22, 2022 14:51
Show Gist options
  • Save bshaffer/fb17da8ed80dd6f7eca65b016162c69e to your computer and use it in GitHub Desktop.
Save bshaffer/fb17da8ed80dd6f7eca65b016162c69e to your computer and use it in GitHub Desktop.
list apiary services in JSON format
const { Octokit, App } = require("octokit");
async function run() {
const github = new Octokit();
// fetch tree head and look for /discoveries folder's tree SHA
const {
data: tree
} = await github.rest.git.getTree({
owner: "googleapis",
repo: "discovery-artifact-manager",
tree_sha: "master",
});
const {sha: discoveryTreeSha} = tree.tree.find((node) => {
return node.path === "discoveries";
});
// fetch tree for /discoveries folder
const {
data: {
tree: discoveryFiles
}
} = await github.rest.git.getTree({
owner: "googleapis",
repo: "discovery-artifact-manager",
tree_sha: discoveryTreeSha,
});
// limit files that end in .json and grab the service name
const services = discoveryFiles.filter((file) => {
return file.path.endsWith(".json");
}).map(file => file.path.split(".")[0]);
// make unique
console.log(JSON.stringify([...new Set(services)]));
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment