chore: smaller changes

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-06-04 11:25:25 +02:00
parent d6d63c7cfe
commit c701c34391
5 changed files with 87 additions and 105 deletions
@@ -5,7 +5,6 @@
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import { JsonObject } from '@backstage/types';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
@@ -103,14 +102,16 @@ export function createPublishBitbucketCloudPullRequestAction(options: {
{
repoUrl: string;
title: string;
description?: string;
targetBranch?: string;
sourceBranch: string;
token?: string;
gitAuthorName?: string;
gitAuthorEmail?: string;
description?: string | undefined;
targetBranch?: string | undefined;
token?: string | undefined;
gitAuthorName?: string | undefined;
gitAuthorEmail?: string | undefined;
},
JsonObject,
'v1'
{
pullRequestUrl: string;
},
'v2'
>;
```
@@ -139,6 +139,7 @@ const findBranches = async (opts: {
return r.values[0];
};
const createBranch = async (opts: {
workspace: string;
repo: string;
@@ -190,6 +191,7 @@ const createBranch = async (opts: {
return await response.json();
};
const getDefaultBranch = async (opts: {
workspace: string;
repo: string;
@@ -233,73 +235,60 @@ export function createPublishBitbucketCloudPullRequestAction(options: {
}) {
const { integrations, config } = options;
return createTemplateAction<{
repoUrl: string;
title: string;
description?: string;
targetBranch?: string;
sourceBranch: string;
token?: string;
gitAuthorName?: string;
gitAuthorEmail?: string;
}>({
return createTemplateAction({
id: 'publish:bitbucketCloud:pull-request',
examples,
schema: {
input: {
type: 'object',
required: ['repoUrl', 'title', 'sourceBranch'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
title: {
title: 'Pull Request title',
type: 'string',
repoUrl: z =>
z.string({
description: 'Repository Location',
}),
title: z =>
z.string({
description: 'The title for the pull request',
},
description: {
title: 'Pull Request Description',
type: 'string',
description: 'The description of the pull request',
},
targetBranch: {
title: 'Target Branch',
type: 'string',
description: `Branch of repository to apply changes to. The default value is 'master'`,
},
sourceBranch: {
title: 'Source Branch',
type: 'string',
}),
description: z =>
z
.string({
description: 'The description of the pull request',
})
.optional(),
targetBranch: z =>
z
.string({
description: `Branch of repository to apply changes to. The default value is 'master'`,
})
.optional(),
sourceBranch: z =>
z.string({
description: 'Branch of repository to copy changes from',
},
token: {
title: 'Authorization Token',
type: 'string',
description:
'The token to use for authorization to BitBucket Cloud',
},
gitAuthorName: {
title: 'Author Name',
type: 'string',
description: `Sets the author name for the commit. The default value is 'Scaffolder'`,
},
gitAuthorEmail: {
title: 'Author Email',
type: 'string',
description: `Sets the author email for the commit.`,
},
},
}),
token: z =>
z
.string({
description:
'The token to use for authorization to BitBucket Cloud',
})
.optional(),
gitAuthorName: z =>
z
.string({
description: `Sets the author name for the commit. The default value is 'Scaffolder'`,
})
.optional(),
gitAuthorEmail: z =>
z
.string({
description: `Sets the author email for the commit.`,
})
.optional(),
},
output: {
type: 'object',
properties: {
pullRequestUrl: {
title: 'A URL to the pull request with the provider',
type: 'string',
},
},
pullRequestUrl: z =>
z.string({
description: 'A URL to the pull request with the provider',
}),
},
},
async handler(ctx) {
@@ -97,7 +97,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with targetBranchName', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
fakeClient = {
@@ -181,7 +181,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with no sourcePath', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -250,7 +250,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with sourcePath', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -306,7 +306,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with repoUrl', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -359,7 +359,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with reviewers and teamReviewers', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -406,7 +406,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with no reviewers and teamReviewers', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -431,7 +431,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with assignees', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -475,7 +475,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with broken symlink', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -520,7 +520,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with executable file mode 755', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -579,7 +579,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with executable file mode 775', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -638,7 +638,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with commit message', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -683,7 +683,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with force fork', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -729,7 +729,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author name and email', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -779,7 +779,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author name', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -828,7 +828,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author email', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -877,7 +877,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author from config file', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -946,7 +946,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author attributes and config file', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -1017,7 +1017,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with author fallback and no config', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -1112,7 +1112,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with createWhenEmpty equals true', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
input = {
@@ -1175,7 +1175,7 @@ describe('createPublishGithubPullRequestAction', () => {
describe('with createWhenEmpty equals false', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
let ctx: ActionContext<GithubPullRequestActionInput, any, any>;
beforeEach(() => {
fakeClient.createPullRequest.mockResolvedValueOnce(null);
@@ -7,12 +7,12 @@ import { ActionContext } from '@backstage/plugin-scaffolder-node';
import { JsonObject } from '@backstage/types';
// @public
export const createMockActionContext: <
export function createMockActionContext<
TActionInput extends JsonObject = JsonObject,
TActionOutput extends JsonObject = JsonObject,
TActionOutput extends JsonObject = any,
>(
options?: Partial<ActionContext<TActionInput, TActionOutput>>,
) => ActionContext<TActionInput, TActionOutput>;
): ActionContext<TActionInput, TActionOutput>;
// (No @packageDocumentation comment for this package)
```
@@ -30,13 +30,14 @@ import { loggerToWinstonLogger } from './loggerToWinstonLogger';
* @public
* @param options - optional parameters to override default mock context
*/
export const createMockActionContext = <
export function createMockActionContext<
TActionInput extends JsonObject = JsonObject,
TActionOutput extends JsonObject = JsonObject,
TActionOutput extends JsonObject = any,
>(
options?: Partial<ActionContext<TActionInput, TActionOutput>>,
): ActionContext<TActionInput, TActionOutput> => {
): ActionContext<TActionInput, TActionOutput> {
const credentials = mockCredentials.user();
const defaultContext = {
logger: loggerToWinstonLogger(mockServices.logger.mock()),
logStream: new PassThrough(),
@@ -66,16 +67,8 @@ export const createMockActionContext = <
};
}
const {
input,
logger,
logStream,
secrets,
templateInfo,
workspacePath,
task,
user,
} = options;
const { input, logger, secrets, templateInfo, workspacePath, task, user } =
options;
return {
...defaultContext,
@@ -84,11 +77,10 @@ export const createMockActionContext = <
createTemporaryDirectory: jest.fn().mockResolvedValue(workspacePath),
}),
...(logger && { logger }),
...(logStream && { logStream }),
...(input && { input }),
...(secrets && { secrets }),
...(task && { task }),
...(user && { user }),
templateInfo,
};
};
}