type Github = {
token: string;
};
/**
* Get repository clones
* Get the total number of clones and breakdown per day or week for the last 14 days. Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
per: "day" | "week" | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/traffic/clones`
);
for (const [k, v] of [["per", per]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 66 days ago
type Github = {
token: string;
};
/**
* Get repository clones
* Get the total number of clones and breakdown per day or week for the last 14 days. Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
per: "day" | "week" | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/traffic/clones`
);
for (const [k, v] of [["per", per]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 626 days ago