Created
November 22, 2022 14:51
-
-
Save bshaffer/fb17da8ed80dd6f7eca65b016162c69e to your computer and use it in GitHub Desktop.
list apiary services in JSON format
This file contains hidden or 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
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