type Bitbucket = {
username: string;
password: string;
};
/**
* Create a commit by uploading a file
* This endpoint is used to create new commits in the repository by
uploading files.
*/
export async function main(
auth: Bitbucket,
repo_slug: string,
workspace: string,
message: string | undefined,
author: string | undefined,
parents: string | undefined,
files: string | undefined,
branch: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
);
for (const [k, v] of [
["message", message],
["author", author],
["parents", parents],
["files", files],
["branch", branch],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 455 days ago