type Github = {
token: string;
};
/**
* List repositories for the authenticated user
* Lists repositories that the authenticated user has explicit permission (`:read`, `:write`, or `:admin`) to access.
The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, and repositories that they can access through an organization membership.
*/
export async function main(
auth: Github,
visibility: "all" | "public" | "private" | undefined,
affiliation: string | undefined,
type: "all" | "owner" | "public" | "private" | "member" | undefined,
sort: "created" | "updated" | "pushed" | "full_name" | undefined,
direction: "asc" | "desc" | undefined,
per_page: string | undefined,
page: string | undefined,
since: string | undefined,
before: string | undefined
) {
const url = new URL(`https://api.github.com/user/repos`);
for (const [k, v] of [
["visibility", visibility],
["affiliation", affiliation],
["type", type],
["sort", sort],
["direction", direction],
["per_page", per_page],
["page", page],
["since", since],
["before", before],
]) {
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 367 days ago
type Github = {
token: string;
};
/**
* List repositories for the authenticated user
* Lists repositories that the authenticated user has explicit permission (`:read`, `:write`, or `:admin`) to access.
The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, and repositories that they can access through an organization membership.
*/
export async function main(
auth: Github,
visibility: "all" | "public" | "private" | undefined,
affiliation: string | undefined,
type: "all" | "owner" | "public" | "private" | "member" | undefined,
sort: "created" | "updated" | "pushed" | "full_name" | undefined,
direction: "asc" | "desc" | undefined,
per_page: string | undefined,
page: string | undefined,
since: string | undefined,
before: string | undefined
) {
const url = new URL(`https://api.github.com/user/repos`);
for (const [k, v] of [
["visibility", visibility],
["affiliation", affiliation],
["type", type],
["sort", sort],
["direction", direction],
["per_page", per_page],
["page", page],
["since", since],
["before", before],
]) {
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 927 days ago