type Github = {
token: string;
};
/**
* Create a scoped access token
* Use a non-scoped user-to-server access token to create a repository scoped and/or permission scoped user-to-server access token.
*/
export async function main(
auth: Github,
client_id: string,
body: {
access_token: string;
permissions?: {
actions?: "read" | "write";
administration?: "read" | "write";
checks?: "read" | "write";
contents?: "read" | "write";
deployments?: "read" | "write";
environments?: "read" | "write";
issues?: "read" | "write";
members?: "read" | "write";
metadata?: "read" | "write";
organization_administration?: "read" | "write";
organization_announcement_banners?: "read" | "write";
organization_custom_roles?: "read" | "write";
organization_hooks?: "read" | "write";
organization_packages?: "read" | "write";
organization_plan?: "read";
organization_projects?: "read" | "write" | "admin";
organization_secrets?: "read" | "write";
organization_self_hosted_runners?: "read" | "write";
organization_user_blocking?: "read" | "write";
packages?: "read" | "write";
pages?: "read" | "write";
pull_requests?: "read" | "write";
repository_announcement_banners?: "read" | "write";
repository_hooks?: "read" | "write";
repository_projects?: "read" | "write" | "admin";
secret_scanning_alerts?: "read" | "write";
secrets?: "read" | "write";
security_events?: "read" | "write";
single_file?: "read" | "write";
statuses?: "read" | "write";
team_discussions?: "read" | "write";
vulnerability_alerts?: "read" | "write";
workflows?: "write";
[k: string]: unknown;
};
repositories?: string[];
repository_ids?: number[];
target?: string;
target_id?: number;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/applications/${client_id}/token/scoped`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 354 days ago
type Github = {
token: string;
};
/**
* Create a scoped access token
* Use a non-scoped user-to-server access token to create a repository scoped and/or permission scoped user-to-server access token.
*/
export async function main(
auth: Github,
client_id: string,
body: {
access_token: string;
permissions?: {
actions?: "read" | "write";
administration?: "read" | "write";
checks?: "read" | "write";
contents?: "read" | "write";
deployments?: "read" | "write";
environments?: "read" | "write";
issues?: "read" | "write";
members?: "read" | "write";
metadata?: "read" | "write";
organization_administration?: "read" | "write";
organization_announcement_banners?: "read" | "write";
organization_custom_roles?: "read" | "write";
organization_hooks?: "read" | "write";
organization_packages?: "read" | "write";
organization_plan?: "read";
organization_projects?: "read" | "write" | "admin";
organization_secrets?: "read" | "write";
organization_self_hosted_runners?: "read" | "write";
organization_user_blocking?: "read" | "write";
packages?: "read" | "write";
pages?: "read" | "write";
pull_requests?: "read" | "write";
repository_announcement_banners?: "read" | "write";
repository_hooks?: "read" | "write";
repository_projects?: "read" | "write" | "admin";
secret_scanning_alerts?: "read" | "write";
secrets?: "read" | "write";
security_events?: "read" | "write";
single_file?: "read" | "write";
statuses?: "read" | "write";
team_discussions?: "read" | "write";
vulnerability_alerts?: "read" | "write";
workflows?: "write";
[k: string]: unknown;
};
repositories?: string[];
repository_ids?: number[];
target?: string;
target_id?: number;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/applications/${client_id}/auth.token/scoped`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 359 days ago