type Bitbucket = {
username: string;
password: string;
};
/**
* Merge a pull request
* Merges the pull request.
*/
export async function main(
auth: Bitbucket,
pull_request_id: string,
repo_slug: string,
workspace: string,
async: string | undefined,
body: {
type: string;
message?: string;
close_source_branch?: boolean;
merge_strategy?: "merge_commit" | "squash" | "fast_forward";
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}/merge`
);
for (const [k, v] of [["async", async]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 375 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Merge a pull request
* Merges the pull request.
*/
export async function main(
auth: Bitbucket,
pull_request_id: string,
repo_slug: string,
workspace: string,
async: string | undefined,
body: {
type: string;
message?: string;
close_source_branch?: boolean;
merge_strategy?: "merge_commit" | "squash" | "fast_forward";
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}/merge`
);
for (const [k, v] of [["async", async]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 935 days ago