Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/pages/api/v1/[username].js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { fetchDataForAllYears } from '../../../utils/api/fetch'

export default async (req, res) => {
const { username, format } = req.query;
const data = await fetchDataForAllYears(username, format);
let { username, format } = req.query;
let organization = undefined

if (username.includes('|')) {
[username, organization] = username.split('|');
}

const data = await fetchDataForAllYears(username, organization, format);
res.setHeader('Cache-Control', 's-maxage=3600, stale-while-revalidate')
res.json(data);
}
8 changes: 4 additions & 4 deletions src/utils/api/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const COLOR_MAP = {
4: "#216e39"
};

async function fetchYears(username) {
const data = await fetch(`https://github.com/${username}?tab=contributions`, {
async function fetchYears(username, organization) {
const data = await fetch(`https://github.com/${username}?tab=contributions&org=${organization}`, {
headers: {
"x-requested-with": "XMLHttpRequest"
}
Expand Down Expand Up @@ -94,8 +94,8 @@ async function fetchDataForYear(url, year, format) {
};
}

export async function fetchDataForAllYears(username, format) {
const years = await fetchYears(username);
export async function fetchDataForAllYears(username, organization, format) {
const years = await fetchYears(username, organization);
return Promise.all(
years.map((year) => fetchDataForYear(year.href, year.text, format))
).then((resp) => {
Expand Down