Skip to content

Commit

Permalink
feat: add getFiles functions to list files in a github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Jun 28, 2020
1 parent 570ae6e commit ac00958
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"typescript": "^3.9.3"
},
"dependencies": {
"jsonld": "^3.1.1"
"jsonld": "^3.1.1",
"node-fetch": "^2.6.0"
}
}
16 changes: 16 additions & 0 deletions packages/lib/src/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable import/prefer-default-export */
const fetch = require('node-fetch');

const githubApi = async endpoint => {
return fetch(`https://api.github.com/repos/${endpoint}`).then(res =>
res.json()
);
};

const getFiles = async (user, repo, ref = 'HEAD') => {
const all = await githubApi(`${user}/${repo}/git/trees/${ref}?recursive=1`);
const files = all.tree.filter(node => node.type === 'blob');
return files;
};

export { getFiles };

0 comments on commit ac00958

Please sign in to comment.