-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
34 lines (30 loc) · 940 Bytes
/
github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const {throughAll} = require("./tools.js")
const BASE_URL = "https://api.github.com";
//Setup headers
const auth = process.env["GITHUB_BASIC_AUTH"]
const headers = auth?{
Authorization: Buffer.from(auth).toString('base64')
}:{};
/**
* Fetches all of a user's gists
* @param {string} username The user to lookup
*/
function usersGists(username){
return throughAll(`${BASE_URL}/users/${username}/gists`,headers);
}
/**
* Returns all of a user's gists that contain the specified file
* @param {string} username The user to lookup
* @param {string} targetFile The file to search for
*/
async function* gistsWithFile(username,targetFile){
const gists = usersGists(username);
for await(const gist of gists){
for (const file of Object.values(gist.files)){
if(targetFile === file.filename){
yield {file,gist};
}
}
}
}
module.exports = {gistsWithFile,usersGists}