//native
type Planetscale = {
serviceTokenId: string;
serviceToken: string;
};
/**
* List deploy requests
* List deploy requests for a database
### Authorization
A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
**Service Token Accesses**
`read_deploy_request`
**OAuth Scopes**
| Resource | Scopes |
| :------- | :---------- |
| Organization | `read_deploy_requests` |
| Database | `read_deploy_requests` |
*/
export async function main(
auth: Planetscale,
organization: string,
database: string,
page: string | undefined,
per_page: string | undefined,
state: string | undefined,
branch: string | undefined,
into_branch: string | undefined,
) {
const url = new URL(
`https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/deploy-requests`,
);
for (const [k, v] of [
["page", page],
["per_page", per_page],
["state", state],
["branch", branch],
["into_branch", into_branch],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago