From db54c57cdc9efc762557cef82247fd64582b94e6 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:46:05 +0200 Subject: [PATCH 1/2] feat: add reviewers input for bitbucket server pr This doesn't include default-reviewers because those require a separate semi-official API call to get, which I didn't want to implement for now. Signed-off-by: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> --- .changeset/healthy-shoes-judge.md | 5 +++++ .../report.api.md | 1 + .../bitbucketServerPullRequest.examples.test.ts | 7 ++++++- .../bitbucketServerPullRequest.examples.ts | 1 + .../src/actions/bitbucketServerPullRequest.ts | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .changeset/healthy-shoes-judge.md diff --git a/.changeset/healthy-shoes-judge.md b/.changeset/healthy-shoes-judge.md new file mode 100644 index 0000000000..4392bffdd6 --- /dev/null +++ b/.changeset/healthy-shoes-judge.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-bitbucket-server': minor +--- + +Add `reviewers` input parameter to `publish:bitbucketServer:pull-request` diff --git a/plugins/scaffolder-backend-module-bitbucket-server/report.api.md b/plugins/scaffolder-backend-module-bitbucket-server/report.api.md index d103743b91..546a2d3834 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/report.api.md +++ b/plugins/scaffolder-backend-module-bitbucket-server/report.api.md @@ -44,6 +44,7 @@ export function createPublishBitbucketServerPullRequestAction(options: { description?: string | undefined; targetBranch?: string | undefined; sourceBranch: string; + reviewers?: string[] | undefined; token?: string | undefined; gitAuthorName?: string | undefined; gitAuthorEmail?: string | undefined; diff --git a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.test.ts b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.test.ts index b83ba2be55..9cb27eb4be 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.test.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.test.ts @@ -366,7 +366,7 @@ describe('publish:bitbucketServer:pull-request', () => { }); it(`should ${examples[4].description}`, async () => { - expect.assertions(7); + expect.assertions(8); server.use( rest.get( 'https://no-credentials.bitbucket.com/rest/api/1.0/projects/project/repos/repo/branches', @@ -389,6 +389,7 @@ describe('publish:bitbucketServer:pull-request', () => { toRef: { displayId: string }; fromRef: { displayId: string }; description: string; + reviewers: [{ user: { name: string } }]; }; expect(requestBody.title).toBe('My pull request'); expect(requestBody.fromRef.displayId).toBe('my-feature-branch'); @@ -396,6 +397,10 @@ describe('publish:bitbucketServer:pull-request', () => { expect(requestBody.description).toBe( 'This is a detailed description of my pull request', ); + expect(requestBody.reviewers).toEqual([ + { user: { name: 'reviewer1' } }, + { user: { name: 'reviewer2' } }, + ]); expect(req.headers.get('Authorization')).toBe( `Bearer ${yaml.parse(examples[4].example).steps[0].input.token}`, ); diff --git a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.ts b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.ts index 77287e64e1..2859a2b051 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.examples.ts @@ -107,6 +107,7 @@ export const examples: TemplateExample[] = [ sourceBranch: 'my-feature-branch', targetBranch: 'development', description: 'This is a detailed description of my pull request', + reviewers: ['reviewer1', 'reviewer2'], token: 'my-auth-token', gitAuthorName: 'test-user', gitAuthorEmail: 'test-user@sample.com', diff --git a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts index 440e402764..e061d0fef1 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts @@ -54,6 +54,7 @@ const createPullRequest = async (opts: { latestChangeset: string; isDefault: boolean; }; + reviewers?: string[]; authorization: string; apiBaseUrl: string; }) => { @@ -64,6 +65,7 @@ const createPullRequest = async (opts: { description, toRef, fromRef, + reviewers, authorization, apiBaseUrl, } = opts; @@ -80,6 +82,7 @@ const createPullRequest = async (opts: { locked: true, toRef: toRef, fromRef: fromRef, + reviewers: reviewers?.map(reviewer => ({ user: { name: reviewer } })), }), headers: { Authorization: authorization, @@ -253,6 +256,7 @@ export function createPublishBitbucketServerPullRequestAction(options: { description?: string; targetBranch?: string; sourceBranch: string; + reviewers?: string[]; token?: string; gitAuthorName?: string; gitAuthorEmail?: string; @@ -288,6 +292,15 @@ export function createPublishBitbucketServerPullRequestAction(options: { type: 'string', description: 'Branch of repository to copy changes from', }, + reviewers: { + title: 'Pull Request Reviewers', + type: 'array', + items: { + type: 'string', + }, + description: + 'The usernames of reviewers that will be added to the pull request', + }, token: { title: 'Authorization Token', type: 'string', @@ -323,6 +336,7 @@ export function createPublishBitbucketServerPullRequestAction(options: { description, targetBranch, sourceBranch, + reviewers, gitAuthorName, gitAuthorEmail, } = ctx.input; @@ -473,6 +487,7 @@ export function createPublishBitbucketServerPullRequestAction(options: { description, toRef, fromRef, + reviewers, authorization, apiBaseUrl, }); From 71946b49f7668f9985d1cc6f42315d67b4928c3d Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Fri, 4 Oct 2024 16:20:37 +0200 Subject: [PATCH 2/2] Update healthy-shoes-judge.md Signed-off-by: Ben Lambert --- .changeset/healthy-shoes-judge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/healthy-shoes-judge.md b/.changeset/healthy-shoes-judge.md index 4392bffdd6..eebd89a23d 100644 --- a/.changeset/healthy-shoes-judge.md +++ b/.changeset/healthy-shoes-judge.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend-module-bitbucket-server': minor +'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch --- Add `reviewers` input parameter to `publish:bitbucketServer:pull-request`