From 2b15cb4aa0a6afe04b379e55b707118f49d9e867 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Tue, 4 Apr 2023 09:49:50 +0200 Subject: [PATCH 1/9] Add Commit Hash Output for Scaffolder Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .changeset/dull-birds-lie.md | 5 +++++ .changeset/quick-plants-live.md | 5 +++++ packages/backend-common/package.json | 2 +- packages/backend-common/src/scm/git.ts | 3 +-- .../src/features/Patch/PatchBody.tsx | 2 +- .../scaffolder/actions/builtin/github/helpers.ts | 6 ++++-- .../src/scaffolder/actions/builtin/helpers.test.ts | 6 ++++-- .../src/scaffolder/actions/builtin/helpers.ts | 13 ++++++++----- .../src/scaffolder/actions/builtin/publish/azure.ts | 3 ++- .../scaffolder/actions/builtin/publish/bitbucket.ts | 3 ++- .../actions/builtin/publish/bitbucketCloud.ts | 3 ++- .../actions/builtin/publish/bitbucketServer.ts | 3 ++- .../scaffolder/actions/builtin/publish/gerrit.ts | 3 ++- .../scaffolder/actions/builtin/publish/github.ts | 3 ++- .../scaffolder/actions/builtin/publish/gitlab.ts | 3 ++- yarn.lock | 4 ++-- 16 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 .changeset/dull-birds-lie.md create mode 100644 .changeset/quick-plants-live.md diff --git a/.changeset/dull-birds-lie.md b/.changeset/dull-birds-lie.md new file mode 100644 index 0000000000..addb988fb8 --- /dev/null +++ b/.changeset/dull-birds-lie.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +**BREAKING** The non-PR/MR Git Actions now return the commitHash of the commit pushed as a new output called `commitHash` diff --git a/.changeset/quick-plants-live.md b/.changeset/quick-plants-live.md new file mode 100644 index 0000000000..0cfba91314 --- /dev/null +++ b/.changeset/quick-plants-live.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': minor +--- + +**BREAKING** The git commit helper now returns the commitHash of the commit created diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index 4b7789a04d..373d664aa9 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -82,7 +82,7 @@ "fs-extra": "10.1.0", "git-url-parse": "^13.0.0", "helmet": "^6.0.0", - "isomorphic-git": "^1.8.0", + "isomorphic-git": "^1.21.0", "jose": "^4.6.0", "keyv": "^4.5.2", "knex": "^2.0.0", diff --git a/packages/backend-common/src/scm/git.ts b/packages/backend-common/src/scm/git.ts index 1c33b89ef6..8317c77d1e 100644 --- a/packages/backend-common/src/scm/git.ts +++ b/packages/backend-common/src/scm/git.ts @@ -111,8 +111,7 @@ export class Git { this.config.logger?.info( `Committing file to repo {dir=${dir},message=${message}}`, ); - - return git.commit({ fs, dir, message, author, committer }); + return await git.commit({ fs, dir, message, author, committer }); } /** https://isomorphic-git.org/docs/en/clone */ diff --git a/plugins/git-release-manager/src/features/Patch/PatchBody.tsx b/plugins/git-release-manager/src/features/Patch/PatchBody.tsx index c5429e389a..790b704487 100644 --- a/plugins/git-release-manager/src/features/Patch/PatchBody.tsx +++ b/plugins/git-release-manager/src/features/Patch/PatchBody.tsx @@ -182,7 +182,7 @@ export const PatchBody = ({ // The selected patch commit's sha is included in the commit message, // which means it's part of a previous patch releaseBranchCommit.commit.message.includes( - getPatchCommitSuffix({ commitSha: commit.sha }), + getPatchCommitSuffix({ commitHash: commit.sha }), ), ); const hasNoParent = !commit.firstParentSha; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts index 75c8f25d8b..ab5710facd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts @@ -293,7 +293,7 @@ export async function initRepoPushAndProtect( gitAuthorEmail?: string, dismissStaleReviews?: boolean, requiredCommitSigning?: boolean, -) { +): Promise<{ commitHash: string }> { const gitAuthorInfo = { name: gitAuthorName ? gitAuthorName @@ -307,7 +307,7 @@ export async function initRepoPushAndProtect( ? gitCommitMessage : config.getOptionalString('scaffolder.defaultCommitMessage'); - await initRepoAndPush({ + const commitHash = await initRepoAndPush({ dir: getRepoSourceDirectory(workspacePath, sourcePath), remoteUrl, defaultBranch, @@ -346,6 +346,8 @@ export async function initRepoPushAndProtect( ); } } + + return { commitHash }; } function extractCollaboratorName( diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts index b5a375d83d..63053725f3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Git, getVoidLogger } from '@backstage/backend-common'; +import { getVoidLogger, Git } from '@backstage/backend-common'; import { commitAndPushRepo, initRepoAndPush } from './helpers'; jest.mock('@backstage/backend-common', () => ({ @@ -23,7 +23,9 @@ jest.mock('@backstage/backend-common', () => ({ init: jest.fn(), add: jest.fn(), checkout: jest.fn(), - commit: jest.fn(), + commit: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), fetch: jest.fn(), addRemote: jest.fn(), push: jest.fn(), diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts index 8bed279a1b..0ea86000d1 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts @@ -91,7 +91,7 @@ export async function initRepoAndPush({ defaultBranch?: string; commitMessage?: string; gitAuthorInfo?: { name?: string; email?: string }; -}): Promise { +}): Promise<{ commitHash: string }> { const git = Git.fromAuth({ ...auth, logger, @@ -110,13 +110,12 @@ export async function initRepoAndPush({ email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io', }; - await git.commit({ + const commitHash = await git.commit({ dir, message: commitMessage, author: authorInfo, committer: authorInfo, }); - await git.addRemote({ dir, url: remoteUrl, @@ -127,6 +126,8 @@ export async function initRepoAndPush({ dir, remote: 'origin', }); + + return { commitHash }; } export async function commitAndPushRepo({ @@ -148,7 +149,7 @@ export async function commitAndPushRepo({ gitAuthorInfo?: { name?: string; email?: string }; branch?: string; remoteRef?: string; -}): Promise { +}): Promise<{ commitHash: string }> { const git = Git.fromAuth({ ...auth, logger, @@ -164,7 +165,7 @@ export async function commitAndPushRepo({ email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io', }; - await git.commit({ + const commitHash = await git.commit({ dir, message: commitMessage, author: authorInfo, @@ -176,6 +177,8 @@ export async function commitAndPushRepo({ remote: 'origin', remoteRef: remoteRef ?? `refs/heads/${branch}`, }); + + return { commitHash }; } type BranchProtectionOptions = { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts index 083c18c94f..6686ea3dba 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -183,7 +183,7 @@ export function createPublishAzureAction(options: { : config.getOptionalString('scaffolder.defaultAuthor.email'), }; - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath), remoteUrl, defaultBranch, @@ -198,6 +198,7 @@ export function createPublishAzureAction(options: { gitAuthorInfo, }); + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); ctx.output('repositoryId', repositoryId); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts index 74e5e8c1ab..72c7f065ab 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts @@ -391,7 +391,7 @@ export function createPublishBitbucketAction(options: { }; } - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath), remoteUrl, auth, @@ -407,6 +407,7 @@ export function createPublishBitbucketAction(options: { await performEnableLFS({ authorization, host, project, repo }); } + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts index 2c17bf2dbb..419abdd8f0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts @@ -262,7 +262,7 @@ export function createPublishBitbucketCloudAction(options: { }; } - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath), remoteUrl, auth, @@ -274,6 +274,7 @@ export function createPublishBitbucketCloudAction(options: { gitAuthorInfo, }); + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts index f2f581eadb..c990d14086 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts @@ -279,7 +279,7 @@ export function createPublishBitbucketServerAction(options: { password: authConfig.password!, }; - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath), remoteUrl, auth, @@ -295,6 +295,7 @@ export function createPublishBitbucketServerAction(options: { await performEnableLFS({ authorization, host, project, repo }); } + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts index b5bcc31c62..e72d1d9011 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts @@ -201,7 +201,7 @@ export function createPublishGerritAction(options: { }; const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`; - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath), remoteUrl, auth, @@ -213,6 +213,7 @@ export function createPublishGerritAction(options: { const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${defaultBranch}`; ctx.output('remoteUrl', remoteUrl); + ctx.output('commitHash', commitResult?.commitHash); ctx.output('repoContentsUrl', repoContentsUrl); }, }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 185239c73f..cefb57270c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -236,7 +236,7 @@ export function createPublishGithubAction(options: { const remoteUrl = newRepo.clone_url; const repoContentsUrl = `${newRepo.html_url}/blob/${defaultBranch}`; - await initRepoPushAndProtect( + const commitResult = await initRepoPushAndProtect( remoteUrl, octokitOptions.auth, ctx.workspacePath, @@ -263,6 +263,7 @@ export function createPublishGithubAction(options: { requiredCommitSigning, ); + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 2e7520b77f..4b2f7ee727 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -212,7 +212,7 @@ export function createPublishGitlabAction(options: { ? gitAuthorEmail : config.getOptionalString('scaffolder.defaultAuthor.email'), }; - await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath), remoteUrl: http_url_to_repo as string, defaultBranch, @@ -227,6 +227,7 @@ export function createPublishGitlabAction(options: { gitAuthorInfo, }); + ctx.output('commitHash', commitResult?.commitHash); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); ctx.output('projectId', projectId); diff --git a/yarn.lock b/yarn.lock index 589db99d4e..eb25118c8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3525,7 +3525,7 @@ __metadata: git-url-parse: ^13.0.0 helmet: ^6.0.0 http-errors: ^2.0.0 - isomorphic-git: ^1.8.0 + isomorphic-git: ^1.21.0 jose: ^4.6.0 keyv: ^4.5.2 knex: ^2.0.0 @@ -27103,7 +27103,7 @@ __metadata: languageName: node linkType: hard -"isomorphic-git@npm:^1.8.0": +"isomorphic-git@npm:^1.21.0, isomorphic-git@npm:^1.8.0": version: 1.23.0 resolution: "isomorphic-git@npm:1.23.0" dependencies: From 1d4b92171f40fce67dae423099f1a060bfc86bf2 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Tue, 4 Apr 2023 10:46:19 +0200 Subject: [PATCH 2/9] Remove erroneous renaming Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- plugins/git-release-manager/src/features/Patch/PatchBody.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git-release-manager/src/features/Patch/PatchBody.tsx b/plugins/git-release-manager/src/features/Patch/PatchBody.tsx index 790b704487..c5429e389a 100644 --- a/plugins/git-release-manager/src/features/Patch/PatchBody.tsx +++ b/plugins/git-release-manager/src/features/Patch/PatchBody.tsx @@ -182,7 +182,7 @@ export const PatchBody = ({ // The selected patch commit's sha is included in the commit message, // which means it's part of a previous patch releaseBranchCommit.commit.message.includes( - getPatchCommitSuffix({ commitHash: commit.sha }), + getPatchCommitSuffix({ commitSha: commit.sha }), ), ); const hasNoParent = !commit.firstParentSha; From cd6ab5355e73b24f4395a55aadc97f388a0a3506 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Tue, 4 Apr 2023 12:03:39 +0200 Subject: [PATCH 3/9] Fix compilation issue Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../src/scaffolder/actions/builtin/github/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts index ab5710facd..4d6f585ac5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts @@ -307,7 +307,7 @@ export async function initRepoPushAndProtect( ? gitCommitMessage : config.getOptionalString('scaffolder.defaultCommitMessage'); - const commitHash = await initRepoAndPush({ + const { commitHash } = await initRepoAndPush({ dir: getRepoSourceDirectory(workspacePath, sourcePath), remoteUrl, defaultBranch, From 69e976155ac3611741fa5d97d6d128ca9ff595c7 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Tue, 4 Apr 2023 14:29:00 +0200 Subject: [PATCH 4/9] Add commitHashs to output Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../src/scaffolder/actions/builtin/github/githubRepoPush.ts | 4 +++- .../scaffolder/actions/builtin/github/outputProperties.ts | 6 ++++++ .../src/scaffolder/actions/builtin/publish/azure.ts | 4 ++++ .../src/scaffolder/actions/builtin/publish/bitbucket.ts | 4 ++++ .../scaffolder/actions/builtin/publish/bitbucketCloud.ts | 4 ++++ .../scaffolder/actions/builtin/publish/bitbucketServer.ts | 4 ++++ .../src/scaffolder/actions/builtin/publish/gerrit.ts | 4 ++++ .../src/scaffolder/actions/builtin/publish/github.ts | 1 + .../src/scaffolder/actions/builtin/publish/gitlab.ts | 4 ++++ 9 files changed, 34 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.ts index 6e3892cee5..fb15535453 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.ts @@ -107,6 +107,7 @@ export function createGithubRepoPushAction(options: { properties: { remoteUrl: outputProps.remoteUrl, repoContentsUrl: outputProps.repoContentsUrl, + commitHash: outputProps.commitHash, }, }, }, @@ -151,7 +152,7 @@ export function createGithubRepoPushAction(options: { const remoteUrl = targetRepo.data.clone_url; const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`; - await initRepoPushAndProtect( + const { commitHash } = await initRepoPushAndProtect( remoteUrl, octokitOptions.auth, ctx.workspacePath, @@ -180,6 +181,7 @@ export function createGithubRepoPushAction(options: { ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); + ctx.output('commitHash', commitHash); }, }); } diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts index d5d6eb108f..99310e7385 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts @@ -23,5 +23,11 @@ const repoContentsUrl = { type: 'string', }; +const commitHash = { + title: 'The commithash of the initial commit', + type: 'string', +}; + export { remoteUrl }; export { repoContentsUrl }; +export { commitHash }; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts index 6686ea3dba..e4bf7d0dcf 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -108,6 +108,10 @@ export function createPublishAzureAction(options: { title: 'The Id of the created repository', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts index 72c7f065ab..6169a315eb 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts @@ -289,6 +289,10 @@ export function createPublishBitbucketAction(options: { title: 'A URL to the root of the repository', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts index 419abdd8f0..feeb58d5c0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts @@ -182,6 +182,10 @@ export function createPublishBitbucketCloudAction(options: { title: 'A URL to the root of the repository', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts index c990d14086..cceb5d8135 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts @@ -205,6 +205,10 @@ export function createPublishBitbucketServerAction(options: { title: 'A URL to the root of the repository', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts index e72d1d9011..a6652e08d8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts @@ -149,6 +149,10 @@ export function createPublishGerritAction(options: { title: 'A URL to the root of the repository', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index cefb57270c..ef74c62083 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -156,6 +156,7 @@ export function createPublishGithubAction(options: { properties: { remoteUrl: outputProps.remoteUrl, repoContentsUrl: outputProps.repoContentsUrl, + commitHash: outputProps.commitHash, }, }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 4b2f7ee727..46414e965a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -125,6 +125,10 @@ export function createPublishGitlabAction(options: { title: 'The ID of the project', type: 'string', }, + commitHash: { + title: 'The commithash of the initial commit', + type: 'string', + }, }, }, }, From 19eb8e206616c6a9d3ad1dc2f4378574cc0de277 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Wed, 5 Apr 2023 10:39:15 +0200 Subject: [PATCH 5/9] Adress review comments Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .changeset/dull-birds-lie.md | 2 +- .changeset/quick-plants-live.md | 4 ++-- packages/backend-common/package.json | 2 +- packages/backend-common/src/scm/git.ts | 2 +- plugins/scaffolder-backend/package.json | 2 +- yarn.lock | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.changeset/dull-birds-lie.md b/.changeset/dull-birds-lie.md index addb988fb8..5f8049a85e 100644 --- a/.changeset/dull-birds-lie.md +++ b/.changeset/dull-birds-lie.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': minor --- -**BREAKING** The non-PR/MR Git Actions now return the commitHash of the commit pushed as a new output called `commitHash` +The non-PR/MR Git Actions now return the commit hash of the commit pushed as a new output called `commitHash`, isomorphic-git is now on version 1.23.0 diff --git a/.changeset/quick-plants-live.md b/.changeset/quick-plants-live.md index 0cfba91314..5263d4c2fb 100644 --- a/.changeset/quick-plants-live.md +++ b/.changeset/quick-plants-live.md @@ -1,5 +1,5 @@ --- -'@backstage/backend-common': minor +'@backstage/backend-common': patch --- -**BREAKING** The git commit helper now returns the commitHash of the commit created +The dependency isomorphic-git is now on version 1.23.0 diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index 373d664aa9..4082089a08 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -82,7 +82,7 @@ "fs-extra": "10.1.0", "git-url-parse": "^13.0.0", "helmet": "^6.0.0", - "isomorphic-git": "^1.21.0", + "isomorphic-git": "^1.23.0", "jose": "^4.6.0", "keyv": "^4.5.2", "knex": "^2.0.0", diff --git a/packages/backend-common/src/scm/git.ts b/packages/backend-common/src/scm/git.ts index 8317c77d1e..234ae57d30 100644 --- a/packages/backend-common/src/scm/git.ts +++ b/packages/backend-common/src/scm/git.ts @@ -111,7 +111,7 @@ export class Git { this.config.logger?.info( `Committing file to repo {dir=${dir},message=${message}}`, ); - return await git.commit({ fs, dir, message, author, committer }); + return git.commit({ fs, dir, message, author, committer }); } /** https://isomorphic-git.org/docs/en/clone */ diff --git a/plugins/scaffolder-backend/package.json b/plugins/scaffolder-backend/package.json index 97d4577d23..1e234feb37 100644 --- a/plugins/scaffolder-backend/package.json +++ b/plugins/scaffolder-backend/package.json @@ -78,7 +78,7 @@ "git-url-parse": "^13.0.0", "globby": "^11.0.0", "isbinaryfile": "^5.0.0", - "isomorphic-git": "^1.8.0", + "isomorphic-git": "^1.23.0", "jsonschema": "^1.2.6", "knex": "^2.0.0", "lodash": "^4.17.21", diff --git a/yarn.lock b/yarn.lock index eb25118c8f..8ad5779546 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3525,7 +3525,7 @@ __metadata: git-url-parse: ^13.0.0 helmet: ^6.0.0 http-errors: ^2.0.0 - isomorphic-git: ^1.21.0 + isomorphic-git: ^1.23.0 jose: ^4.6.0 keyv: ^4.5.2 knex: ^2.0.0 @@ -8031,7 +8031,7 @@ __metadata: git-url-parse: ^13.0.0 globby: ^11.0.0 isbinaryfile: ^5.0.0 - isomorphic-git: ^1.8.0 + isomorphic-git: ^1.23.0 jest-when: ^3.1.0 jsonschema: ^1.2.6 knex: ^2.0.0 @@ -27103,7 +27103,7 @@ __metadata: languageName: node linkType: hard -"isomorphic-git@npm:^1.21.0, isomorphic-git@npm:^1.8.0": +"isomorphic-git@npm:^1.23.0": version: 1.23.0 resolution: "isomorphic-git@npm:1.23.0" dependencies: From 608b44ef49fa49d094b13e36a69a5e7653a748e1 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Wed, 5 Apr 2023 12:37:44 +0200 Subject: [PATCH 6/9] Add test fixes Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../builtin/github/githubRepoPush.test.ts | 26 +++++++++++- .../actions/builtin/github/helpers.ts | 4 +- .../actions/builtin/helpers.test.ts | 40 +++++++++++++++++-- .../actions/builtin/publish/azure.test.ts | 11 ++++- .../actions/builtin/publish/bitbucket.test.ts | 11 ++++- .../builtin/publish/bitbucketCloud.test.ts | 11 ++++- .../builtin/publish/bitbucketServer.test.ts | 11 ++++- .../actions/builtin/publish/gerrit.test.ts | 11 ++++- .../actions/builtin/publish/github.test.ts | 10 +++-- .../actions/builtin/publish/gitlab.test.ts | 11 ++++- 10 files changed, 131 insertions(+), 15 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts index 517347c733..37a13bf814 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts @@ -14,10 +14,30 @@ * limitations under the License. */ -import { TemplateAction } from '@backstage/plugin-scaffolder-node'; +const mockGit = { + init: jest.fn(), + add: jest.fn(), + checkout: jest.fn(), + commit: jest + .fn() + .mockResolvedValue('220f19cc36b551763d157f1b5e4a4b446165dbd6'), + fetch: jest.fn(), + addRemote: jest.fn(), + push: jest.fn(), +}; + +jest.mock('@backstage/backend-common', () => ({ + Git: { + fromAuth() { + return mockGit; + }, + }, + getVoidLogger: jest.requireActual('@backstage/backend-common').getVoidLogger, +})); jest.mock('../helpers'); +import { TemplateAction } from '@backstage/plugin-scaffolder-node'; import { getVoidLogger } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; import { @@ -77,6 +97,10 @@ describe('github:repo:push', () => { beforeEach(() => { jest.resetAllMocks(); + + // @ts-ignore TS2339 Jest Mock is not detected by Typescript + initRepoAndPush.mockResolvedValue({ commitHash: 'test123' }); + githubCredentialsProvider = DefaultGithubCredentialsProvider.fromIntegrations(integrations); action = createGithubRepoPushAction({ diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts index 4d6f585ac5..c7fd1caf5c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts @@ -307,7 +307,7 @@ export async function initRepoPushAndProtect( ? gitCommitMessage : config.getOptionalString('scaffolder.defaultCommitMessage'); - const { commitHash } = await initRepoAndPush({ + const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(workspacePath, sourcePath), remoteUrl, defaultBranch, @@ -347,7 +347,7 @@ export async function initRepoPushAndProtect( } } - return { commitHash }; + return { commitHash: commitResult.commitHash }; } function extractCollaboratorName( diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts index 63053725f3..87b88eb53e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts @@ -23,9 +23,9 @@ jest.mock('@backstage/backend-common', () => ({ init: jest.fn(), add: jest.fn(), checkout: jest.fn(), - commit: jest.fn().mockResolvedValue({ - commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', - }), + commit: jest + .fn() + .mockResolvedValue('220f19cc36b551763d157f1b5e4a4b446165dbd6'), fetch: jest.fn(), addRemote: jest.fn(), push: jest.fn(), @@ -43,6 +43,23 @@ describe('initRepoAndPush', () => { jest.clearAllMocks(); }); + describe('resolves the commitHash properly', () => { + it('resolves the correct hash', () => { + const commitHash = initRepoAndPush({ + dir: '/test/repo/dir/', + remoteUrl: 'git@github.com:test/repo.git', + auth: { + username: 'test-user', + password: 'test-password', + }, + logger: getVoidLogger(), + }); + expect(Promise.resolve(commitHash)).toEqual({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }); + }); + }); + describe('with minimal parameters', () => { beforeEach(async () => { await initRepoAndPush({ @@ -170,6 +187,23 @@ describe('commitAndPushRepo', () => { jest.clearAllMocks(); }); + describe('resolves the commitHash properly', () => { + it('resolves to the commitHash', () => { + const commitHash = commitAndPushRepo({ + dir: '/test/repo/dir/', + auth: { + username: 'test-user', + password: 'test-password', + }, + logger: getVoidLogger(), + commitMessage: 'commit message', + }); + expect(Promise.resolve(commitHash)).toStrictEqual({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }); + }); + }); + describe('with minimal parameters', () => { beforeEach(async () => { await commitAndPushRepo({ diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts index a2262c1f9f..9f68eb848a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts @@ -19,7 +19,16 @@ jest.mock('azure-devops-node-api', () => ({ getPersonalAccessTokenHandler: jest.fn().mockReturnValue(() => {}), })); -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import { createPublishAzureAction } from './azure'; import { ScmIntegrations } from '@backstage/integration'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts index 926910467d..5d46a28a60 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import { createPublishBitbucketAction } from './bitbucket'; import { rest } from 'msw'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.test.ts index b21a47f506..3159bfc562 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.test.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import { createPublishBitbucketCloudAction } from './bitbucketCloud'; import { rest } from 'msw'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.test.ts index 6b4fa3d781..67a29210fc 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.test.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import { createPublishBitbucketServerAction } from './bitbucketServer'; import { rest } from 'msw'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.test.ts index 3b4354960b..73dcc47225 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.test.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import path from 'path'; import { createPublishGerritAction } from './gerrit'; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index 94b51f3e94..206990536a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import { TemplateAction } from '@backstage/plugin-scaffolder-node'; - jest.mock('../helpers'); +import { TemplateAction } from '@backstage/plugin-scaffolder-node'; import { getVoidLogger } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; import { @@ -88,6 +86,12 @@ describe('publish:github', () => { beforeEach(() => { jest.resetAllMocks(); + + // @ts-ignore TS2339 Jest Mock is not detected by Typescript + initRepoAndPush.mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }); + githubCredentialsProvider = DefaultGithubCredentialsProvider.fromIntegrations(integrations); action = createPublishGithubAction({ diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts index a9c4522dd3..994d1c580a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.test.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -jest.mock('../helpers'); +jest.mock('../helpers', () => { + return { + initRepoAndPush: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + commitAndPushRepo: jest.fn().mockResolvedValue({ + commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', + }), + }; +}); import { createPublishGitlabAction } from './gitlab'; import { ScmIntegrations } from '@backstage/integration'; From 0e3f44132a2bc93fe71e73e8d56491260288976d Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Wed, 5 Apr 2023 12:40:37 +0200 Subject: [PATCH 7/9] Final test fixes Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../actions/builtin/helpers.test.ts | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts index 87b88eb53e..60ab84a964 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.test.ts @@ -43,23 +43,6 @@ describe('initRepoAndPush', () => { jest.clearAllMocks(); }); - describe('resolves the commitHash properly', () => { - it('resolves the correct hash', () => { - const commitHash = initRepoAndPush({ - dir: '/test/repo/dir/', - remoteUrl: 'git@github.com:test/repo.git', - auth: { - username: 'test-user', - password: 'test-password', - }, - logger: getVoidLogger(), - }); - expect(Promise.resolve(commitHash)).toEqual({ - commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', - }); - }); - }); - describe('with minimal parameters', () => { beforeEach(async () => { await initRepoAndPush({ @@ -187,23 +170,6 @@ describe('commitAndPushRepo', () => { jest.clearAllMocks(); }); - describe('resolves the commitHash properly', () => { - it('resolves to the commitHash', () => { - const commitHash = commitAndPushRepo({ - dir: '/test/repo/dir/', - auth: { - username: 'test-user', - password: 'test-password', - }, - logger: getVoidLogger(), - commitMessage: 'commit message', - }); - expect(Promise.resolve(commitHash)).toStrictEqual({ - commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', - }); - }); - }); - describe('with minimal parameters', () => { beforeEach(async () => { await commitAndPushRepo({ From c92153205f40a2c069be58ef9f0f3b86bc67cd07 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Wed, 5 Apr 2023 14:08:02 +0200 Subject: [PATCH 8/9] Add mock fix Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../actions/builtin/github/githubRepoPush.test.ts | 7 +++++-- .../src/scaffolder/actions/builtin/publish/github.test.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts index 37a13bf814..8630dfab56 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoPush.test.ts @@ -52,6 +52,10 @@ import { } from '../helpers'; import { createGithubRepoPushAction } from './githubRepoPush'; +const initRepoAndPushMocked = initRepoAndPush as jest.Mock< + Promise<{ commitHash: string }> +>; + const mockOctokit = { rest: { repos: { @@ -98,8 +102,7 @@ describe('github:repo:push', () => { beforeEach(() => { jest.resetAllMocks(); - // @ts-ignore TS2339 Jest Mock is not detected by Typescript - initRepoAndPush.mockResolvedValue({ commitHash: 'test123' }); + initRepoAndPushMocked.mockResolvedValue({ commitHash: 'test123' }); githubCredentialsProvider = DefaultGithubCredentialsProvider.fromIntegrations(integrations); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index 206990536a..576a207786 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -31,6 +31,10 @@ import { } from '../helpers'; import { createPublishGithubAction } from './github'; +const initRepoAndPushMocked = initRepoAndPush as jest.Mock< + Promise<{ commitHash: string }> +>; + const mockOctokit = { rest: { users: { @@ -87,8 +91,7 @@ describe('publish:github', () => { beforeEach(() => { jest.resetAllMocks(); - // @ts-ignore TS2339 Jest Mock is not detected by Typescript - initRepoAndPush.mockResolvedValue({ + initRepoAndPushMocked.mockResolvedValue({ commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6', }); From c3a726b4f80bc5aacdef0b0deaed88d6e113dda0 Mon Sep 17 00:00:00 2001 From: "Lukas Fruntke (external expert on behalf of DB Netz)" Date: Wed, 5 Apr 2023 14:10:26 +0200 Subject: [PATCH 9/9] Rename output description Signed-off-by: Lukas Fruntke (external expert on behalf of DB Netz) --- .../src/scaffolder/actions/builtin/github/outputProperties.ts | 2 +- .../src/scaffolder/actions/builtin/publish/azure.ts | 2 +- .../src/scaffolder/actions/builtin/publish/bitbucket.ts | 2 +- .../src/scaffolder/actions/builtin/publish/bitbucketCloud.ts | 2 +- .../src/scaffolder/actions/builtin/publish/bitbucketServer.ts | 2 +- .../src/scaffolder/actions/builtin/publish/gerrit.ts | 2 +- .../src/scaffolder/actions/builtin/publish/gitlab.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts index 99310e7385..c0cdcb1cb2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/outputProperties.ts @@ -24,7 +24,7 @@ const repoContentsUrl = { }; const commitHash = { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts index e4bf7d0dcf..96b7c87204 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -109,7 +109,7 @@ export function createPublishAzureAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts index 6169a315eb..6a7341bdc9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts @@ -290,7 +290,7 @@ export function createPublishBitbucketAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts index feeb58d5c0..00529d5856 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketCloud.ts @@ -183,7 +183,7 @@ export function createPublishBitbucketCloudAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts index cceb5d8135..66b7a46f77 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucketServer.ts @@ -206,7 +206,7 @@ export function createPublishBitbucketServerAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts index a6652e08d8..60a0cc4aae 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gerrit.ts @@ -150,7 +150,7 @@ export function createPublishGerritAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 46414e965a..a621d27d55 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -126,7 +126,7 @@ export function createPublishGitlabAction(options: { type: 'string', }, commitHash: { - title: 'The commithash of the initial commit', + title: 'The git commit hash of the initial commit', type: 'string', }, },