chore: updating bitbucket cloud actions

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-06-03 11:19:40 +02:00
parent 7f710d2a52
commit ca9fdc0b08
7 changed files with 422 additions and 374 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-bitbucket-cloud': patch
---
Migrate `bitbucket-cloud` to new actions format
@@ -20,15 +20,56 @@ export const createBitbucketPipelinesRunAction: (options: {
{
workspace: string;
repo_slug: string;
body?: object;
token?: string;
body?:
| {
target?:
| {
type?: string | undefined;
source?: string | undefined;
selector?:
| {
type: string;
pattern: string;
}
| undefined;
pull_request?:
| {
id: string;
}
| undefined;
commit?:
| {
type: string;
hash: string;
}
| undefined;
destination?: string | undefined;
ref_name?: string | undefined;
ref_type?: string | undefined;
destination_commit?:
| {
hash: string;
}
| undefined;
}
| undefined;
variables?:
| {
key: string;
value: string;
secured: boolean;
}[]
| undefined;
}
| undefined;
token?: string | undefined;
},
{
buildNumber: number;
repoUrl: string;
pipelinesUrl: string;
buildNumber?: number | undefined;
repoUrl?: string | undefined;
pipelinesUrl?: string | undefined;
},
'v1'
'v2'
>;
// @public
@@ -38,16 +79,20 @@ export function createPublishBitbucketCloudAction(options: {
}): TemplateAction<
{
repoUrl: string;
description?: string;
defaultBranch?: string;
repoVisibility?: 'private' | 'public';
gitCommitMessage?: string;
sourcePath?: string;
token?: string;
signCommit?: boolean;
description?: string | undefined;
defaultBranch?: string | undefined;
repoVisibility?: 'private' | 'public' | undefined;
gitCommitMessage?: string | undefined;
sourcePath?: string | undefined;
token?: string | undefined;
signCommit?: boolean | undefined;
},
JsonObject,
'v1'
{
remoteUrl?: string | undefined;
repoContentsUrl?: string | undefined;
commitHash?: string | undefined;
},
'v2'
>;
// @public
@@ -105,83 +105,81 @@ export function createPublishBitbucketCloudAction(options: {
}) {
const { integrations, config } = options;
return createTemplateAction<{
repoUrl: string;
description?: string;
defaultBranch?: string;
repoVisibility?: 'private' | 'public';
gitCommitMessage?: string;
sourcePath?: string;
token?: string;
signCommit?: boolean;
}>({
return createTemplateAction({
id: 'publish:bitbucketCloud',
examples,
description:
'Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Cloud.',
schema: {
input: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
description: {
title: 'Repository Description',
type: 'string',
},
repoVisibility: {
title: 'Repository Visibility',
type: 'string',
enum: ['private', 'public'],
},
defaultBranch: {
title: 'Default Branch',
type: 'string',
description: `Sets the default branch on the repository. The default value is 'master'`,
},
gitCommitMessage: {
title: 'Git Commit Message',
type: 'string',
description: `Sets the commit message on the repository. The default value is 'initial commit'`,
},
sourcePath: {
title: 'Source Path',
description:
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',
type: 'string',
},
token: {
title: 'Authentication Token',
type: 'string',
description:
'The token to use for authorization to BitBucket Cloud',
},
signCommit: {
title: 'Sign commit',
type: 'boolean',
description: 'Sign commit with configured PGP private key',
},
},
repoUrl: z =>
z.string({
description: 'Repository Location',
}),
description: z =>
z
.string({
description: 'Repository Description',
})
.optional(),
defaultBranch: z =>
z
.string({
description: `Sets the default branch on the repository. The default value is 'master'`,
})
.optional(),
repoVisibility: z =>
z
.enum(['private', 'public'], {
description: 'Repository Visibility',
})
.optional(),
gitCommitMessage: z =>
z
.string({
description: `Sets the commit message on the repository. The default value is 'initial commit'`,
})
.optional(),
sourcePath: z =>
z
.string({
description:
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',
})
.optional(),
token: z =>
z
.string({
description:
'The token to use for authorization to BitBucket Cloud',
})
.optional(),
signCommit: z =>
z
.boolean({
description: 'Sign commit with configured PGP private key',
})
.optional(),
},
output: {
type: 'object',
properties: {
remoteUrl: {
title: 'A URL to the repository with the provider',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the root of the repository',
type: 'string',
},
commitHash: {
title: 'The git commit hash of the initial commit',
type: 'string',
},
},
remoteUrl: z =>
z
.string({
description: 'A URL to the repository with the provider',
})
.optional(),
repoContentsUrl: z =>
z
.string({
description: 'A URL to the root of the repository',
})
.optional(),
commitHash: z =>
z
.string({
description: 'The git commit hash of the initial commit',
})
.optional(),
},
},
async handler(ctx) {
@@ -78,49 +78,36 @@ export function createBitbucketCloudBranchRestrictionAction(options: {
integrations: ScmIntegrationRegistry;
}) {
const { integrations } = options;
return createTemplateAction<{
repoUrl: string;
kind: string;
branchMatchKind?: string;
branchType?: string;
pattern?: string;
value?: number | null;
users?: { uuid: string }[];
groups?: { slug: string }[];
token?: string;
}>({
return createTemplateAction({
id: 'bitbucketCloud:branchRestriction:create',
examples,
description:
'Creates branch restrictions for a Bitbucket Cloud repository.',
schema: {
input: {
type: 'object',
required: ['repoUrl', 'kind'],
properties: {
repoUrl: inputProps.repoUrl,
kind: inputProps.restriction.kind,
branchMatchKind: inputProps.restriction.branchMatchKind,
branchType: inputProps.restriction.branchType,
pattern: inputProps.restriction.pattern,
value: inputProps.restriction.value,
users: inputProps.restriction.users,
groups: inputProps.restriction.groups,
token: inputProps.token,
},
repoUrl: inputProps.repoUrl,
kind: inputProps.restriction.kind,
branchMatchKind: inputProps.restriction.branchMatchKind,
branchType: inputProps.restriction.branchType,
pattern: inputProps.restriction.pattern,
value: inputProps.restriction.value,
users: inputProps.restriction.users,
groups: inputProps.restriction.groups,
token: inputProps.token,
},
output: {
type: 'object',
properties: {
json: {
title: 'The response from bitbucket cloud',
type: 'string',
},
statusCode: {
title: 'The status code of the response',
type: 'number',
},
},
json: z =>
z
.string({
description: 'The response from bitbucket cloud',
})
.optional(),
statusCode: z =>
z
.number({
description: 'The status code of the response',
})
.optional(),
},
},
async handler(ctx) {
@@ -30,49 +30,36 @@ export const createBitbucketPipelinesRunAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
const { integrations } = options;
return createTemplateAction<
{
workspace: string;
repo_slug: string;
body?: object;
token?: string;
},
{
buildNumber: number;
repoUrl: string;
pipelinesUrl: string;
}
>({
return createTemplateAction({
id,
description: 'Run a bitbucket cloud pipeline',
examples,
schema: {
input: {
type: 'object',
required: ['workspace', 'repo_slug'],
properties: {
workspace: inputProps.workspace,
repo_slug: inputProps.repo_slug,
body: inputProps.pipelinesRunBody,
token: inputProps.token,
},
workspace: inputProps.workspace,
repo_slug: inputProps.repo_slug,
body: inputProps.pipelinesRunBody,
token: inputProps.token,
},
output: {
type: 'object',
properties: {
buildNumber: {
title: 'Build number',
type: 'number',
},
repoUrl: {
title: 'A URL to the pipeline repository',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the pipeline',
type: 'string',
},
},
buildNumber: z =>
z
.number({
description: 'Build number',
})
.optional(),
repoUrl: z =>
z
.string({
description: 'A URL to the pipeline repository',
})
.optional(),
pipelinesUrl: z =>
z
.string({
description: 'A URL to the pipeline',
})
.optional(),
},
},
supportsDryRun: false,
@@ -14,239 +14,224 @@
* limitations under the License.
*/
const repoUrl = {
title: 'Repository Location',
description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`,
type: 'string',
};
import { z as zod } from 'zod';
const workspace = {
title: 'Workspace',
description: `The workspace name`,
type: 'string',
};
const repoUrl = (z: typeof zod) =>
z.string({
description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`,
});
const repo_slug = {
title: 'Repository name',
description: 'The repository name',
type: 'string',
};
const workspace = (z: typeof zod) =>
z.string({
description: 'The workspace name',
});
const ref_type = {
title: 'ref_type',
type: 'string',
};
const repo_slug = (z: typeof zod) =>
z.string({
description: 'The repository name',
});
const type = {
title: 'type',
type: 'string',
};
const ref_type = (z: typeof zod) =>
z.string({
description: 'ref_type',
});
const ref_name = {
title: 'ref_name',
type: 'string',
};
const source = {
title: 'source',
type: 'string',
};
const destination = {
title: 'destination',
type: 'string',
};
const hash = {
title: 'hash',
type: 'string',
};
const type = (z: typeof zod) =>
z.string({
description: 'type',
});
const pattern = {
title: 'pattern',
type: 'string',
};
const ref_name = (z: typeof zod) =>
z.string({
description: 'ref_name',
});
const id = {
title: 'id',
type: 'string',
};
const source = (z: typeof zod) =>
z.string({
description: 'source',
});
const key = {
title: 'key',
type: 'string',
};
const value = {
title: 'value',
type: 'string',
};
const secured = {
title: 'secured',
type: 'boolean',
};
const destination = (z: typeof zod) =>
z.string({
description: 'destination',
});
const token = {
title: 'Authentication Token',
type: 'string',
description: 'The token to use for authorization to BitBucket Cloud',
};
const hash = (z: typeof zod) =>
z.string({
description: 'hash',
});
const destination_commit = {
title: 'destination_commit',
type: 'object',
properties: {
hash,
},
};
const pattern = (z: typeof zod) =>
z.string({
description: 'pattern',
});
const commit = {
title: 'commit',
type: 'object',
properties: {
type,
hash,
},
};
const id = (z: typeof zod) =>
z.string({
description: 'id',
});
const selector = {
title: 'selector',
type: 'object',
properties: {
type,
pattern,
},
};
const key = (z: typeof zod) =>
z.string({
description: 'key',
});
const pull_request = {
title: 'pull_request',
type: 'object',
properties: {
id,
},
};
const value = (z: typeof zod) =>
z.string({
description: 'value',
});
const pipelinesRunBody = {
title: 'Request Body',
description:
'Request body properties: see Bitbucket Cloud Rest API documentation for more details',
type: 'object',
properties: {
target: {
title: 'target',
type: 'object',
properties: {
ref_type,
type,
ref_name,
source,
destination,
destination_commit,
commit,
selector,
pull_request,
const secured = (z: typeof zod) =>
z.boolean({
description: 'secured',
});
const token = (z: typeof zod) =>
z
.string({
description: 'The token to use for authorization to BitBucket Cloud',
})
.optional();
const destination_commit = (z: typeof zod) =>
z.object({
hash: hash(z),
});
const commit = (z: typeof zod) =>
z.object({
type: type(z),
hash: hash(z),
});
const selector = (z: typeof zod) =>
z.object({
type: type(z),
pattern: pattern(z),
});
const pull_request = (z: typeof zod) =>
z.object({
id: id(z),
});
const pipelinesRunBody = (z: typeof zod) =>
z
.object(
{
target: z
.object({
ref_type: ref_type(z).optional(),
type: type(z).optional(),
ref_name: ref_name(z).optional(),
source: source(z).optional(),
destination: destination(z).optional(),
destination_commit: destination_commit(z).optional(),
commit: commit(z).optional(),
selector: selector(z).optional(),
pull_request: pull_request(z).optional(),
})
.optional(),
variables: z
.array(
z.object({
key: key(z),
value: value(z),
secured: secured(z),
}),
)
.optional(),
},
},
variables: {
title: 'variables',
type: 'array',
items: {
type: 'object',
properties: {
key,
value,
secured,
},
{
description:
'Request body properties: see Bitbucket Cloud Rest API documentation for more details',
},
},
},
};
)
.optional();
const restriction = {
kind: {
title: 'kind',
description: 'The kind of restriction.',
type: 'string',
enum: [
'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',
'allow_auto_merge_when_builds_pass',
],
},
branchMatchKind: {
title: 'branch_match_kind',
description: 'The branch match kind.',
type: 'string',
enum: ['glob', 'branching_model'],
},
branchType: {
title: 'branch_type',
description:
'The branch type. When branchMatchKind is set to branching_model, this field is required.',
type: 'string',
enum: [
'feature',
'bugfix',
'release',
'hotfix',
'development',
'production',
],
},
pattern: {
title: 'pattern',
description:
'The pattern to match branches against. This field is required when branchMatchKind is set to glob.',
type: 'string',
},
value: {
title: 'value',
description:
'The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind.',
type: 'number',
nullable: true,
},
users: {
title: 'users',
description:
'Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',
type: 'array',
items: {
type: 'object',
properties: {
uuid: {
title: 'uuid',
description: 'The UUID of the user in the format "{a-b-c-d}".',
type: 'string',
},
kind: (z: typeof zod) =>
z.enum(
[
'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',
'allow_auto_merge_when_builds_pass',
],
{
description: 'The kind of restriction.',
},
},
},
groups: {
title: 'groups',
description:
'Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',
type: 'array',
items: {
type: 'object',
properties: {
slug: {
title: 'slug',
description: 'The name of the group.',
type: 'string',
),
branchMatchKind: (z: typeof zod) =>
z
.enum(['glob', 'branching_model'], {
description: 'The branch match kind.',
})
.optional(),
branchType: (z: typeof zod) =>
z
.enum(
['feature', 'bugfix', 'release', 'hotfix', 'development', 'production'],
{
description:
'The branch type. When branchMatchKind is set to branching_model, this field is required.',
},
},
},
},
)
.optional(),
pattern: (z: typeof zod) =>
z
.string({
description:
'The pattern to match branches against. This field is required when branchMatchKind is set to glob.',
})
.optional(),
value: (z: typeof zod) =>
z
.union([z.number(), z.null()], {
description:
'The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind.',
})
.optional(),
users: (z: typeof zod) =>
z
.array(
z.object({
uuid: z.string({
description: 'The UUID of the user in the format "{a-b-c-d}".',
}),
}),
{
description:
'Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',
},
)
.optional(),
groups: (z: typeof zod) =>
z
.array(
z.object({
slug: z.string({
description: 'The name of the group.',
}),
}),
{
description:
'Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',
},
)
.optional(),
};
export { workspace, repo_slug, pipelinesRunBody, token };
@@ -21,15 +21,56 @@ export const createBitbucketPipelinesRunAction: (options: {
{
workspace: string;
repo_slug: string;
body?: object;
token?: string;
body?:
| {
target?:
| {
type?: string | undefined;
source?: string | undefined;
selector?:
| {
type: string;
pattern: string;
}
| undefined;
pull_request?:
| {
id: string;
}
| undefined;
commit?:
| {
type: string;
hash: string;
}
| undefined;
destination?: string | undefined;
ref_name?: string | undefined;
ref_type?: string | undefined;
destination_commit?:
| {
hash: string;
}
| undefined;
}
| undefined;
variables?:
| {
key: string;
value: string;
secured: boolean;
}[]
| undefined;
}
| undefined;
token?: string | undefined;
},
{
buildNumber: number;
repoUrl: string;
pipelinesUrl: string;
buildNumber?: number | undefined;
repoUrl?: string | undefined;
pipelinesUrl?: string | undefined;
},
'v1'
'v2'
>;
// @public @deprecated