type Github = {
token: string;
};
/**
* Delete GitHub Actions caches for a repository (using a cache key)
* Deletes one or more GitHub Actions caches for a repository, using a complete cache key. By default, all caches that match the provided key are deleted, but you can optionally provide a Git ref to restrict deletions to caches that match both the provided key and the Git ref.
You must authenticate using an access token with the `repo` scope to use this endpoint.
GitHub Apps must have the `actions:write` permission to use this endpoint.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
key: string | undefined,
ref: string | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/actions/caches`
);
for (const [k, v] of [
["key", key],
["ref", ref],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
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;
};
/**
* Delete GitHub Actions caches for a repository (using a cache key)
* Deletes one or more GitHub Actions caches for a repository, using a complete cache key. By default, all caches that match the provided key are deleted, but you can optionally provide a Git ref to restrict deletions to caches that match both the provided key and the Git ref.
You must authenticate using an access token with the `repo` scope to use this endpoint.
GitHub Apps must have the `actions:write` permission to use this endpoint.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
key: string | undefined,
ref: string | undefined
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/actions/caches`
);
for (const [k, v] of [
["key", key],
["ref", ref],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
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