-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.mjs
More file actions
46 lines (41 loc) · 969 Bytes
/
github.mjs
File metadata and controls
46 lines (41 loc) · 969 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
import fetch from 'node-fetch';
import { writeFileSync } from 'fs';
const query = `query {
user(login:"smzelek") {
contributionsCollection {
contributionYears
contributionCalendar {
totalContributions
colors
months {
name
totalWeeks
}
weeks {
contributionDays {
contributionLevel
}
}
}
}
}
}`;
const cacheGithubData = async () => {
console.log("Loading GitHub contribution data to cache it")
const data = await fetch('https://api.github.com/graphql', {
method: 'POST',
headers: {
Authorization: `token ${process.env.CONTRIBUTION_HISTORY_TOKEN}`,
},
body: JSON.stringify({
query,
variables: {},
})
});
const json = await data.json();
console.log("Loaded data")
console.log(JSON.stringify(json))
writeFileSync('github.json', JSON.stringify(json));
console.log("Wrote data to github.json")
}
await cacheGithubData();