type Github = {
token: string;
};
/**
* Get the combined status for a specific reference
* Users with pull access in a repository can access a combined view of commit statuses for a given ref. The ref can be a SHA, a branch name, or a tag name.
Additionally, a combined `state` is returned. The `state` is one of:
* **failure** if any of the contexts report as `error` or `failure`
* **pending** if there are no statuses or a context is `pending`
* **success** if the latest status for all contexts is `success`
*/
export async function main(
auth: Github,
owner: string,
repo: string,
ref: string,
per_page: string | undefined,
page: string | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/commits/${ref}/status`
);
for (const [k, v] of [
["per_page", per_page],
["page", page],
]) {
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;
};
/**
* Get the combined status for a specific reference
* Users with pull access in a repository can access a combined view of commit statuses for a given ref. The ref can be a SHA, a branch name, or a tag name.
Additionally, a combined `state` is returned. The `state` is one of:
* **failure** if any of the contexts report as `error` or `failure`
* **pending** if there are no statuses or a context is `pending`
* **success** if the latest status for all contexts is `success`
*/
export async function main(
auth: Github,
owner: string,
repo: string,
ref: string,
per_page: string | undefined,
page: string | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/commits/${ref}/status`
);
for (const [k, v] of [
["per_page", per_page],
["page", page],
]) {
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