type Github = {
token: string;
};
/**
* Create a deployment status
* Users with `push` access can create deployment statuses for a given deployment.
GitHub Apps require `read & write` access to "Deployments" and `read-only` access to "Repo contents" (for private repos). OAuth Apps require the `repo_deployment` scope.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
deployment_id: string,
body: {
auto_inactive?: boolean;
description?: string;
environment?: "production" | "staging" | "qa";
environment_url?: string;
log_url?: string;
state:
| "error"
| "failure"
| "inactive"
| "in_progress"
| "queued"
| "pending"
| "success";
target_url?: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/deployments/${deployment_id}/statuses`
);
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 367 days ago
type Github = {
token: string;
};
/**
* Create a deployment status
* Users with `push` access can create deployment statuses for a given deployment.
GitHub Apps require `read & write` access to "Deployments" and `read-only` access to "Repo contents" (for private repos). OAuth Apps require the `repo_deployment` scope.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
deployment_id: string,
body: {
auto_inactive?: boolean;
description?: string;
environment?: "production" | "staging" | "qa";
environment_url?: string;
log_url?: string;
state:
| "error"
| "failure"
| "inactive"
| "in_progress"
| "queued"
| "pending"
| "success";
target_url?: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/deployments/${deployment_id}/statuses`
);
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 927 days ago