MCPcopy
hub / github.com/sallar/github-contributions-chart / fetchDataForAllYears

Function fetchDataForAllYears

src/utils/api/fetch.js:97–124  ·  view source on GitHub ↗
(username, format)

Source from the content-addressed store, hash-verified

95}
96
97export async function fetchDataForAllYears(username, format) {
98 const years = await fetchYears(username);
99 return Promise.all(
100 years.map((year) => fetchDataForYear(year.href, year.text, format))
101 ).then((resp) => {
102 return {
103 years: (() => {
104 const obj = {};
105 const arr = resp.map((year) => {
106 const { contributions, ...rest } = year;
107 _.setWith(obj, [rest.year], rest, Object);
108 return rest;
109 });
110 return format === "nested" ? obj : arr;
111 })(),
112 contributions:
113 format === "nested"
114 ? resp.reduce((acc, curr) => _.merge(acc, curr.contributions))
115 : resp
116 .reduce((list, curr) => [...list, ...curr.contributions], [])
117 .sort((a, b) => {
118 if (a.date < b.date) return 1;
119 else if (a.date > b.date) return -1;
120 return 0;
121 })
122 };
123 });
124}

Callers 1

[username].jsFile · 0.90

Calls 2

fetchYearsFunction · 0.85
fetchDataForYearFunction · 0.85

Tested by

no test coverage detected