getContribution.js
1.16 KB
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
const userContributionsBox = document.querySelector(".user-status__contributions");
const totalContributionIndicator = document.getElementById("jsTotalContributions");
const URL = "https://api.github.com/graphql"
// const handleImage = () =>{
// const total = totalContributionIndicator.innerText;
// console.log(total);
// };
const handleContributons = (total) =>{
totalContributionIndicator.appendChild(total);
};
const getGithubRepo = () =>{
const token = process.env.GH_SECRET_SH;
const username = user.username
const headers = {
'Authorization': `bearer ${token}`,
};
const body = {
"query": `query {user(login: "${username}") {contributionsCollection {contributionCalendar {totalContributions}}}}`
};
const response = fetch(URL, { method: "POST", body: JSON.stringify(body), headers: headers }).then(function(response){
return response.json();
}).then(function(res){
const total = res.data.user.contributionsCollection.contributionCalendar.totalContributions;
handleContributons(total);
});
};
const init=()=>{
handleImage();
getGithubRepo();
};
if(userContributionsBox){
init();
};