I want to create a graph that displays the information provided by the Github PunchCard in a similar way as this python script, but with JavaScript instead, using D3.js. I retrieve the information from the Github API this way using GET /repos/:owner/:repo/stats/punch_card
Right now I am stuck with how to modify the response to gather the data and classify it by day / hour, but apparently I cannot access the Array. My code, so far, is as follows:
const showGithubData = (user, repo) => {
console.log(`Querying user ${user} and repo ${repo}`);
fetchPunchCard(repoUser.value, repoName.value).then((res) => {
console.log(res);
})
};
const fetchPunchCard = async (username, repository) => {
/* GET / repos /: owner /: repo / stats / punch_card */
const url = `https://api.github.com/repos/${username}/${repository}/stats/punch_card`;
const api_call = await fetch(url);
const data = await api_call.json();
return { data }
};
I return the correct values but then I cannot access them, in the same function. If in showGithubData() I do console.log(res[0]) it says undefined, however, when doing console.log(res) I can see it returns an Array of Arrays(3), like this:
{data: Array(168)}
data: Array(168)
[0 … 99]
0: Array(3)
0: 0
1: 0
2: 0
length: 3
__proto__: Array(0)
1: (3) [0, 1, 0]
2: (3) [0, 2, 0]
I want to access all of this positions (0 is day, 1 is hour and 2 is number of commits) to create my charts, but I don't know why I can't.
I really appreciate any help.