type Bitbucket = {
username: string;
password: string;
};
/**
* Create a branch restriction rule
* Creates a new branch restriction rule for a repository.
*/
export async function main(
auth: Bitbucket,
repo_slug: string,
workspace: string,
body: { type: string; [k: string]: unknown } & {
users?: ({ 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;
})[];
groups?: ({ type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: 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;
};
workspace?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
html?: { href?: string; name?: string };
members?: { href?: string; name?: string };
owners?: { href?: string; name?: string };
projects?: { href?: string; name?: string };
repositories?: { href?: string; name?: string };
snippets?: { href?: string; name?: string };
self?: { href?: string; name?: string };
};
uuid?: string;
name?: string;
slug?: string;
is_private?: boolean;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
};
name?: string;
slug?: string;
full_slug?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/branch-restrictions`
);
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;
};
/**
* Create a branch restriction rule
* Creates a new branch restriction rule for a repository.
*/
export async function main(
auth: Bitbucket,
repo_slug: string,
workspace: string,
body: { type: string; [k: string]: unknown } & {
users?: ({ 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;
})[];
groups?: ({ type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: 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;
};
workspace?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
html?: { href?: string; name?: string };
members?: { href?: string; name?: string };
owners?: { href?: string; name?: string };
projects?: { href?: string; name?: string };
repositories?: { href?: string; name?: string };
snippets?: { href?: string; name?: string };
self?: { href?: string; name?: string };
};
uuid?: string;
name?: string;
slug?: string;
is_private?: boolean;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
};
name?: string;
slug?: string;
full_slug?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/branch-restrictions`
);
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
type Bitbucket = {
username: string;
password: string;
};
/**
* Create a branch restriction rule
* Creates a new branch restriction rule for a repository.
`kind` describes what will be restricted. Allowed values include:
`push`, `force`, `delete`, `restrict_merges`, `require_tasks_to_be_completed`,
`require_approvals_to_merge`, `require_default_reviewer_approvals_to_merge`,
`require_no_changes_requested`, `require_passing_builds_to_merge`, `require_commits_behind`,
`reset_pullrequest_approvals_on_change`, `smart_reset_pullrequest_approvals`,
`reset_pullrequest_changes_requested_on_change`, `require_all_dependencies_merged`,
`enforce_merge_checks`, and `allow_auto_merge_when_builds_pass`.
Different kinds of branch restrictions have different requirements:
* `push` and `restrict_merges` require `users` and `groups` to be
specified. Empty lists are allowed, in which case permission is
denied for everybody.
The restriction applies to all branches that match. There are
two ways to match a branch. It is configured in `branch_match_kind`:
1. `glob`: Matches a branch against the `pattern`. A `'*'` in
`pattern` will expand to match zero or more characters, and every
other character matches itself. For example, `'foo*'` will match
`'foo'` and `'foobar'`, but not `'barfoo'`. `'*'` will match all
branches.
2. `branching_model`: Matches a branch against the repository's
branching model. The `branch_type` controls the type of branch
to match. Allowed values include: `production`, `development`,
`bugfix`, `release`, `feature` and `hotfix`.
The combination of `kind` and match must be unique. This means that
two `glob` restrictions in a repository cannot have the same `kind` and
`pattern`. Additionally, two `branching_model` restrictions in a
repository cannot have the same `kind` and `branch_type`.
`users` and `groups` are lists of users and groups that are except from
the restriction. They can only be configured in `push` and
`restrict_merges` restrictions. The `push` restriction stops a user
pushing to matching branches unless that user is in `users` or is a
member of a group in `groups`. The `restrict_merges` stops a user
merging pull requests to matching branches unless that user is in
`users` or is a member of a group in `groups`. Adding new users or
groups to an existing restriction should be done via `PUT`.
Note that branch restrictions with overlapping matchers is allowed,
but the resulting behavior may be surprising.
*/
export async function main(
auth: Bitbucket,
repo_slug: string,
workspace: string,
body: { type: string; [k: string]: unknown } & {
users?: ({ 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;
})[];
groups?: ({ type: string; [k: string]: unknown } & {
links?: {
self?: { href?: string; name?: string };
html?: { href?: string; name?: 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;
};
workspace?: { type: string; [k: string]: unknown } & {
links?: {
avatar?: { href?: string; name?: string };
html?: { href?: string; name?: string };
members?: { href?: string; name?: string };
owners?: { href?: string; name?: string };
projects?: { href?: string; name?: string };
repositories?: { href?: string; name?: string };
snippets?: { href?: string; name?: string };
self?: { href?: string; name?: string };
};
uuid?: string;
name?: string;
slug?: string;
is_private?: boolean;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
};
name?: string;
slug?: string;
full_slug?: string;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/branch-restrictions`
);
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