type Bitbucket = {
username: string;
password: string;
};
/**
* Update a pull request
* Mutates the specified pull request.
This can be used to change the pull request's branches or description.
Only open pull requests can be mutated.
*/
export async function main(
auth: Bitbucket,
pull_request_id: string,
repo_slug: string,
workspace: string,
body: { type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: string };
commits?: { href?: string; name?: string };
approve?: { href?: string; name?: string };
diff?: { href?: string; name?: string };
diffstat?: { href?: string; name?: string };
comments?: { href?: string; name?: string };
activity?: { href?: string; name?: string };
merge?: { href?: string; name?: string };
decline?: { href?: string; name?: string };
};
id?: number;
title?: string;
rendered?: {
title?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
description?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
reason?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
};
summary?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
state?: "OPEN" | "MERGED" | "DECLINED" | "SUPERSEDED";
author?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
source?: {
repository?: { type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: string };
avatar?: { href?: string; name?: string };
pullrequests?: { href?: string; name?: string };
commits?: { href?: string; name?: string };
forks?: { href?: string; name?: string };
watchers?: { href?: string; name?: string };
downloads?: { href?: string; name?: string };
clone?: { href?: string; name?: string }[];
hooks?: { href?: string; name?: string };
};
uuid?: string;
full_name?: string;
is_private?: boolean;
parent?: unknown;
scm?: "git";
owner?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
name?: string;
description?: string;
created_on?: string;
updated_on?: string;
size?: number;
language?: string;
has_issues?: boolean;
has_wiki?: boolean;
fork_policy?: "allow_forks" | "no_public_forks" | "no_forks";
project?: { type: string; [k: string]: unknown } & {
links?: {
html?: { href?: string; name?: string };
avatar?: { href?: string; name?: string };
};
uuid?: string;
key?: string;
owner?: ({ type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
}) & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
} & {
self?: { href?: string; name?: string };
html?: { href?: string; name?: string };
members?: { href?: string; name?: string };
projects?: { href?: string; name?: string };
repositories?: { href?: string; name?: string };
[k: string]: unknown;
};
[k: string]: unknown;
};
name?: string;
description?: string;
is_private?: boolean;
created_on?: string;
updated_on?: string;
has_publicly_visible_repos?: boolean;
[k: string]: unknown;
};
mainbranch?: {
type: string;
links?: {
self?: { href?: string; name?: string };
commits?: { href?: string; name?: string };
html?: { href?: string; name?: string };
};
name?: string;
target?: ({ type: string; [k: string]: unknown } & {
hash?: string;
date?: string;
author?: { type: string; [k: string]: unknown } & {
raw?: string;
user?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
message?: string;
summary?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
parents?: unknown[];
[k: string]: unknown;
}) & {
repository?: unknown;
participants?: ({ type: string; [k: string]: unknown } & {
user?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
role?: "PARTICIPANT" | "REVIEWER";
approved?: boolean;
state?: "approved" | "changes_requested" | null;
participated_on?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
};
[k: string]: unknown;
} & {
merge_strategies?: ("merge_commit" | "squash" | "fast_forward")[];
default_merge_strategy?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
branch?: {
name?: string;
merge_strategies?: ("merge_commit" | "squash" | "fast_forward")[];
default_merge_strategy?: string;
};
commit?: { hash?: string };
};
destination?: {
repository?: { type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: string };
avatar?: { href?: string; name?: string };
pullrequests?: { href?: string; name?: string };
commits?: { href?: string; name?: string };
forks?: { href?: string; name?: string };
watchers?: { href?: string; name?: string };
downloads?: { href?: string; name?: string };
clone?: { href?: string; name?: string }[];
hooks?: { href?: string; name?: string };
};
uuid?: string;
full_name?: string;
is_private?: boolean;
parent?: unknown;
scm?: "git";
owner?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
name?: string;
description?: string;
created_on?: string;
updated_on?: string;
size?: number;
language?: string;
has_issues?: boolean;
has_wiki?: boolean;
fork_policy?: "allow_forks" | "no_public_forks" | "no_forks";
project?: { type: string; [k: string]: unknown } & {
links?: {
html?: { href?: string; name?: string };
avatar?: { href?: string; name?: string };
};
uuid?: string;
key?: string;
owner?: ({ type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
}) & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
} & {
self?: { href?: string; name?: string };
html?: { href?: string; name?: string };
members?: { href?: string; name?: string };
projects?: { href?: string; name?: string };
repositories?: { href?: string; name?: string };
[k: string]: unknown;
};
[k: string]: unknown;
};
name?: string;
description?: string;
is_private?: boolean;
created_on?: string;
updated_on?: string;
has_publicly_visible_repos?: boolean;
[k: string]: unknown;
};
mainbranch?: {
type: string;
links?: {
self?: { href?: string; name?: string };
commits?: { href?: string; name?: string };
html?: { href?: string; name?: string };
};
name?: string;
target?: ({ type: string; [k: string]: unknown } & {
hash?: string;
date?: string;
author?: { type: string; [k: string]: unknown } & {
raw?: string;
user?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
message?: string;
summary?: {
raw?: string;
markup?: "markdown" | "creole" | "plaintext";
html?: string;
};
parents?: unknown[];
[k: string]: unknown;
}) & {
repository?: unknown;
participants?: ({ type: string; [k: string]: unknown } & {
user?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
role?: "PARTICIPANT" | "REVIEWER";
approved?: boolean;
state?: "approved" | "changes_requested" | null;
participated_on?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
};
[k: string]: unknown;
} & {
merge_strategies?: ("merge_commit" | "squash" | "fast_forward")[];
default_merge_strategy?: string;
[k: string]: unknown;
};
[k: string]: unknown;
};
branch?: {
name?: string;
merge_strategies?: ("merge_commit" | "squash" | "fast_forward")[];
default_merge_strategy?: string;
};
commit?: { hash?: string };
};
merge_commit?: { hash?: string };
comment_count?: number;
task_count?: number;
close_source_branch?: boolean;
closed_by?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
reason?: string;
created_on?: string;
updated_on?: string;
reviewers?: ({ type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
})[];
participants?: ({ type: string; [k: string]: unknown } & {
user?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
[k: string]: unknown;
};
created_on?: string;
display_name?: string;
username?: string;
uuid?: string;
[k: string]: unknown;
};
role?: "PARTICIPANT" | "REVIEWER";
approved?: boolean;
state?: "approved" | "changes_requested" | null;
participated_on?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}`
);
const response = await fetch(url, {
method: "PUT",
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 425 days ago