From 66d1ae94d3b8e20b8bfd91002fd60f554ee4b7ec Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Tue, 18 Apr 2023 22:30:05 +0300 Subject: [PATCH] refactor(git): Rename `fetchCommit` to `fetchBranch` (#21581) --- lib/modules/platform/github/index.spec.ts | 2 +- lib/modules/platform/github/index.ts | 2 +- lib/util/git/error.ts | 4 ++-- lib/util/git/index.spec.ts | 2 +- lib/util/git/index.ts | 13 ++++++------- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index ca15ae314d..9fac0812dd 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -3202,7 +3202,7 @@ describe('modules/platform/github/index', () => { files, }) ); - git.fetchCommit.mockImplementation(() => Promise.resolve('0abcdef')); + git.fetchBranch.mockImplementation(() => Promise.resolve('0abcdef')); }); it('returns null if pre-commit phase has failed', async () => { diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 7162a97495..7c9ac146a3 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1836,6 +1836,6 @@ export async function commitFiles( // Replace locally created branch with the remotely created one // and return the remote commit SHA await git.resetToCommit(commitResult.parentCommitSha); - const commitSha = await git.fetchCommit(config); + const commitSha = await git.fetchBranch(branchName); return commitSha; } diff --git a/lib/util/git/error.ts b/lib/util/git/error.ts index 19b8ab6a52..b006e1f142 100644 --- a/lib/util/git/error.ts +++ b/lib/util/git/error.ts @@ -73,9 +73,9 @@ export function checkForPlatformFailure(err: Error): Error | null { // istanbul ignore next export function handleCommitError( - files: FileChange[], + err: Error, branchName: string, - err: Error + files?: FileChange[] ): null { checkForPlatformFailure(err); if (err.message.includes(`'refs/heads/renovate' exists`)) { diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 1f205f85bd..1551fdca23 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -500,7 +500,7 @@ describe('util/git/index', () => { message: 'Update something', }; const commitSha = await git.commitFiles(commitConfig); - const remoteSha = await git.fetchCommit(commitConfig); + const remoteSha = await git.fetchBranch(commitConfig.branchName); expect(commitSha).toEqual(remoteSha); }); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 2df34dfdcd..806bda394b 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -1024,7 +1024,7 @@ export async function prepareCommit({ return result; } catch (err) /* istanbul ignore next */ { - return handleCommitError(files, branchName, err); + return handleCommitError(err, branchName, files); } } @@ -1053,15 +1053,14 @@ export async function pushCommit({ incLimitedValue('Commits'); result = true; } catch (err) /* istanbul ignore next */ { - handleCommitError(files, sourceRef, err); + handleCommitError(err, sourceRef, files); } return result; } -export async function fetchCommit({ - branchName, - files, -}: CommitFilesConfig): Promise<CommitSha | null> { +export async function fetchBranch( + branchName: string +): Promise<CommitSha | null> { await syncGit(); logger.debug(`Fetching branch ${branchName}`); try { @@ -1072,7 +1071,7 @@ export async function fetchCommit({ config.branchIsModified[branchName] = false; return commit; } catch (err) /* istanbul ignore next */ { - return handleCommitError(files, branchName, err); + return handleCommitError(err, branchName); } } -- GitLab