From 6a1dab6412bf4872d0099cf6f40eecd6f90b090d Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 14 May 2020 14:13:08 +0200 Subject: [PATCH] refactor(platform): commitFilesToBranch -> commitFiles --- lib/platform/__snapshots__/index.spec.ts.snap | 8 ++++---- lib/platform/azure/index.spec.ts | 2 +- lib/platform/azure/index.ts | 4 ++-- .../__snapshots__/index.spec.ts.snap | 4 ++-- lib/platform/bitbucket-server/index.spec.ts | 6 +++--- lib/platform/bitbucket-server/index.ts | 6 +++--- lib/platform/bitbucket/index.spec.ts | 6 +++--- lib/platform/bitbucket/index.ts | 4 ++-- lib/platform/common.ts | 2 +- lib/platform/git/storage.spec.ts | 12 ++++++------ lib/platform/git/storage.ts | 2 +- lib/platform/gitea/index.spec.ts | 6 +++--- lib/platform/gitea/index.ts | 6 +++--- lib/platform/github/index.spec.ts | 2 +- lib/platform/github/index.ts | 4 ++-- lib/platform/gitlab/__snapshots__/index.spec.ts.snap | 2 +- lib/platform/gitlab/index.spec.ts | 6 +++--- lib/platform/gitlab/index.ts | 4 ++-- lib/workers/branch/commit.spec.ts | 10 +++++----- lib/workers/branch/commit.ts | 2 +- lib/workers/repository/onboarding/branch/create.ts | 2 +- .../repository/onboarding/branch/index.spec.ts | 8 ++++---- .../repository/onboarding/branch/rebase.spec.ts | 6 +++--- lib/workers/repository/onboarding/branch/rebase.ts | 2 +- 24 files changed, 58 insertions(+), 58 deletions(-) diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap index 55090138c4..b7eb3bbe15 100644 --- a/lib/platform/__snapshots__/index.spec.ts.snap +++ b/lib/platform/__snapshots__/index.spec.ts.snap @@ -6,7 +6,7 @@ Array [ "addReviewers", "branchExists", "cleanRepo", - "commitFilesToBranch", + "commitFiles", "createPr", "deleteBranch", "deleteLabel", @@ -51,7 +51,7 @@ Array [ "addReviewers", "branchExists", "cleanRepo", - "commitFilesToBranch", + "commitFiles", "createPr", "deleteBranch", "deleteLabel", @@ -96,7 +96,7 @@ Array [ "addReviewers", "branchExists", "cleanRepo", - "commitFilesToBranch", + "commitFiles", "createPr", "deleteBranch", "deleteLabel", @@ -141,7 +141,7 @@ Array [ "addReviewers", "branchExists", "cleanRepo", - "commitFilesToBranch", + "commitFiles", "createPr", "deleteBranch", "deleteLabel", diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts index e01cc79edb..6054ba78db 100644 --- a/lib/platform/azure/index.spec.ts +++ b/lib/platform/azure/index.spec.ts @@ -34,7 +34,7 @@ describe('platform/azure', () => { getAllRenovateBranches: jest.fn(), getCommitMessages: jest.fn(), getFile: jest.fn(), - commitFilesToBranch: jest.fn(), + commitFiles: jest.fn(), mergeBranch: jest.fn(), deleteBranch: jest.fn(), getRepoStatus: jest.fn(), diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 8b98d93bf6..cdfcb1cd98 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -379,12 +379,12 @@ export /* istanbul ignore next */ function mergeBranch( return config.storage.mergeBranch(branchName); } -export /* istanbul ignore next */ function commitFilesToBranch({ +export /* istanbul ignore next */ function commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { - return config.storage.commitFilesToBranch({ + return config.storage.commitFiles({ branchName, files, message, diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index 35d7d34f24..9505c71697 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -246,7 +246,7 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with no path commitFilesToBranch() sends to gitFs 1`] = ` +exports[`platform/bitbucket-server endpoint with no path commitFiles() sends to gitFs 1`] = ` Array [ Array [ "./rest/api/1.0/projects/SOME/repos/repo", @@ -1825,7 +1825,7 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with path commitFilesToBranch() sends to gitFs 1`] = ` +exports[`platform/bitbucket-server endpoint with path commitFiles() sends to gitFs 1`] = ` Array [ Array [ "./rest/api/1.0/projects/SOME/repos/repo", diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 9dc79ed5a5..84063f96c2 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -59,7 +59,7 @@ describe('platform/bitbucket-server', () => { getAllRenovateBranches: jest.fn(), getCommitMessages: jest.fn(), getFile: jest.fn(), - commitFilesToBranch: jest.fn(), + commitFiles: jest.fn(), mergeBranch: jest.fn(), deleteBranch: jest.fn(), getRepoStatus: jest.fn(), @@ -265,11 +265,11 @@ describe('platform/bitbucket-server', () => { }); }); - describe('commitFilesToBranch()', () => { + describe('commitFiles()', () => { it('sends to gitFs', async () => { expect.assertions(1); await initRepo(); - await bitbucket.commitFilesToBranch({ + await bitbucket.commitFiles({ branchName: 'some-branch', files: [{ name: 'test', contents: 'dummy' }], message: 'message', diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index f5d83c27ae..60f141ada7 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -426,13 +426,13 @@ export function getAllRenovateBranches( return config.storage.getAllRenovateBranches(branchPrefix); } -export async function commitFilesToBranch({ +export async function commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { logger.debug( - `commitFilesToBranch(${JSON.stringify( + `commitFiles(${JSON.stringify( { branchName, filesLength: files.length, @@ -442,7 +442,7 @@ export async function commitFilesToBranch({ 2 )})` ); - const commit = config.storage.commitFilesToBranch({ + const commit = config.storage.commitFiles({ branchName, files, message, diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index a6bd99e995..60af57c35d 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -34,7 +34,7 @@ describe('platform/bitbucket', () => { getAllRenovateBranches: jest.fn(), getCommitMessages: jest.fn(), getFile: jest.fn(), - commitFilesToBranch: jest.fn(), + commitFiles: jest.fn(), mergeBranch: jest.fn(), deleteBranch: jest.fn(), getRepoStatus: jest.fn(), @@ -486,11 +486,11 @@ describe('platform/bitbucket', () => { }); }); - describe('commitFilesToBranch()', () => { + describe('commitFiles()', () => { it('sends to gitFs', async () => { await initRepo(); await mocked(async () => { - await bitbucket.commitFilesToBranch({ + await bitbucket.commitFiles({ branchName: 'test', files: [], message: 'message', diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 2ec87005bd..68d6380f83 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -288,12 +288,12 @@ export function mergeBranch(branchName: string): Promise<void> { return config.storage.mergeBranch(branchName); } -export function commitFilesToBranch({ +export function commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { - return config.storage.commitFilesToBranch({ + return config.storage.commitFiles({ branchName, files, message, diff --git a/lib/platform/common.ts b/lib/platform/common.ts index a270c2383c..285dde2885 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -223,7 +223,7 @@ export interface Platform { ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>; branchExists(branchName: string): Promise<boolean>; setBaseBranch(baseBranch?: string): Promise<string>; - commitFilesToBranch(commitFile: CommitFilesConfig): Promise<string | null>; + commitFiles(commitFile: CommitFilesConfig): Promise<string | null>; getPr(number: number): Promise<Pr>; findPr(findPRConfig: FindPRConfig): Promise<Pr>; mergeBranch(branchName: string): Promise<void>; diff --git a/lib/platform/git/storage.spec.ts b/lib/platform/git/storage.spec.ts index 01a035519d..432f5b1508 100644 --- a/lib/platform/git/storage.spec.ts +++ b/lib/platform/git/storage.spec.ts @@ -195,13 +195,13 @@ describe('platform/git/storage', () => { ).rejects.toMatchSnapshot(); }); }); - describe('commitFilesToBranch({branchName, files, message})', () => { + describe('commitFiles({branchName, files, message})', () => { it('creates file', async () => { const file = { name: 'some-new-file', contents: 'some new-contents', }; - await git.commitFilesToBranch({ + await git.commitFiles({ branchName: 'renovate/past_branch', files: [file], message: 'Create something', @@ -212,7 +212,7 @@ describe('platform/git/storage', () => { name: '|delete|', contents: 'file_to_delete', }; - await git.commitFilesToBranch({ + await git.commitFiles({ branchName: 'renovate/something', files: [file], message: 'Delete something', @@ -229,7 +229,7 @@ describe('platform/git/storage', () => { contents: 'other updated content', }, ]; - await git.commitFilesToBranch({ + await git.commitFiles({ branchName: 'renovate/something', files, message: 'Update something', @@ -242,7 +242,7 @@ describe('platform/git/storage', () => { contents: 'some content', }, ]; - await git.commitFilesToBranch({ + await git.commitFiles({ branchName: 'renovate/something', files, message: 'Update something', @@ -257,7 +257,7 @@ describe('platform/git/storage', () => { `refs/heads/${branchName}:refs/remotes/origin/${branchName}`, ]); const files = []; - await git.commitFilesToBranch({ + await git.commitFiles({ branchName, files, message: 'Update something', diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index 19fe8d6692..b3253f1b3e 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -464,7 +464,7 @@ export class Storage { } } - async commitFilesToBranch({ + async commitFiles({ branchName, files, message, diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index e9724382eb..b5e08d5469 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -201,7 +201,7 @@ describe('platform/gitea', () => { setBranchPrefix: gsmSetBranchPrefix, isBranchStale: gsmIsBranchStale, getBranchCommit: gsmGetBranchCommit, - commitFilesToBranch: gsmCommitFilesToBranch, + commitFiles: gsmCommitFilesToBranch, deleteBranch: gsmDeleteBranch, })); @@ -1439,7 +1439,7 @@ index 0000000..2173594 }); }); - describe('commitFilesToBranch', () => { + describe('commitFiles', () => { it('should propagate call to storage class with default parent branch', async () => { const commitConfig: CommitFilesConfig = { branchName: 'some-branch', @@ -1448,7 +1448,7 @@ index 0000000..2173594 }; await initFakeRepo(); - await gitea.commitFilesToBranch(commitConfig); + await gitea.commitFiles(commitConfig); expect(gsmCommitFilesToBranch).toHaveBeenCalledTimes(1); expect(gsmCommitFilesToBranch).toHaveBeenCalledWith({ diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index a3c70bcb10..5e9ce871b8 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -887,12 +887,12 @@ const platform: Platform = { return Promise.resolve(); }, - commitFilesToBranch({ + commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { - return config.storage.commitFilesToBranch({ + return config.storage.commitFiles({ branchName, files, message, @@ -962,7 +962,7 @@ export const { addReviewers, branchExists, cleanRepo, - commitFilesToBranch, + commitFiles, createPr, deleteBranch, deleteLabel, diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts index bf32b2283d..f617748be4 100644 --- a/lib/platform/github/index.spec.ts +++ b/lib/platform/github/index.spec.ts @@ -39,7 +39,7 @@ describe('platform/github', () => { getAllRenovateBranches: jest.fn(), getCommitMessages: jest.fn(), getFile: jest.fn(), - commitFilesToBranch: jest.fn(), + commitFiles: jest.fn(), mergeBranch: jest.fn(), deleteBranch: jest.fn(), getRepoStatus: jest.fn(), diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 9187981ea8..5a1a47f5d2 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -554,12 +554,12 @@ export function mergeBranch(branchName: string): Promise<void> { } // istanbul ignore next -export function commitFilesToBranch({ +export function commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { - return config.storage.commitFilesToBranch({ + return config.storage.commitFiles({ branchName, files, message, diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index 2bd3fde109..0f7f181e81 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -27,7 +27,7 @@ Array [ ] `; -exports[`platform/gitlab commitFilesToBranch() sends to gitFs 1`] = ` +exports[`platform/gitlab commitFiles() sends to gitFs 1`] = ` Array [ Array [ "projects/some%2Frepo", diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 40f748ca9f..6fe998e3d1 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -41,7 +41,7 @@ describe('platform/gitlab', () => { getAllRenovateBranches: jest.fn(), getCommitMessages: jest.fn(), getFile: jest.fn(), - commitFilesToBranch: jest.fn(), + commitFiles: jest.fn(), mergeBranch: jest.fn(), deleteBranch: jest.fn(), getRepoStatus: jest.fn(), @@ -1142,11 +1142,11 @@ These updates have all been created already. Click a checkbox below to force a r await gitlab.getFile(''); }); }); - describe('commitFilesToBranch()', () => { + describe('commitFiles()', () => { it('sends to gitFs', async () => { expect.assertions(1); await initRepo(); - await gitlab.commitFilesToBranch({ + await gitlab.commitFiles({ branchName: 'some-branch', files: [{ name: 'SomeFile', contents: 'Some Content' }], message: '', diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 9208cfdf1a..bbfcfc600d 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -587,12 +587,12 @@ export function isBranchStale(branchName: string): Promise<boolean> { return config.storage.isBranchStale(branchName); } -export function commitFilesToBranch({ +export function commitFiles({ branchName, files, message, }: CommitFilesConfig): Promise<string | null> { - return config.storage.commitFilesToBranch({ + return config.storage.commitFiles({ branchName, files, message, diff --git a/lib/workers/branch/commit.spec.ts b/lib/workers/branch/commit.spec.ts index cd68fe7772..d654a6b98f 100644 --- a/lib/workers/branch/commit.spec.ts +++ b/lib/workers/branch/commit.spec.ts @@ -17,11 +17,11 @@ describe('workers/branch/automerge', () => { updatedArtifacts: [], }); jest.resetAllMocks(); - platform.commitFilesToBranch.mockResolvedValueOnce('abc123'); + platform.commitFiles.mockResolvedValueOnce('abc123'); }); it('handles empty files', async () => { await commitFilesToBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0); + expect(platform.commitFiles).toHaveBeenCalledTimes(0); }); it('commits files', async () => { config.updatedPackageFiles.push({ @@ -29,8 +29,8 @@ describe('workers/branch/automerge', () => { contents: 'some contents', }); await commitFilesToBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(1); - expect(platform.commitFilesToBranch.mock.calls).toMatchSnapshot(); + expect(platform.commitFiles).toHaveBeenCalledTimes(1); + expect(platform.commitFiles.mock.calls).toMatchSnapshot(); }); it('dry runs', async () => { config.dryRun = true; @@ -39,7 +39,7 @@ describe('workers/branch/automerge', () => { contents: 'some contents', }); await commitFilesToBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0); + expect(platform.commitFiles).toHaveBeenCalledTimes(0); }); }); }); diff --git a/lib/workers/branch/commit.ts b/lib/workers/branch/commit.ts index 86f71984d1..13f06692a7 100644 --- a/lib/workers/branch/commit.ts +++ b/lib/workers/branch/commit.ts @@ -33,7 +33,7 @@ export async function commitFilesToBranch( return null; } // API will know whether to create new branch or not - return platform.commitFilesToBranch({ + return platform.commitFiles({ branchName: config.branchName, files: updatedFiles, message: config.commitMessage, diff --git a/lib/workers/repository/onboarding/branch/create.ts b/lib/workers/repository/onboarding/branch/create.ts index fd43e4d9e7..ad8b8afcb4 100644 --- a/lib/workers/repository/onboarding/branch/create.ts +++ b/lib/workers/repository/onboarding/branch/create.ts @@ -29,7 +29,7 @@ export async function createOnboardingBranch( logger.info('DRY-RUN: Would commit files to onboarding branch'); return null; } - return platform.commitFilesToBranch({ + return platform.commitFiles({ branchName: config.onboardingBranch, files: [ { diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index 7c9502a47f..a9d53d2703 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -35,7 +35,7 @@ describe('workers/repository/onboarding/branch', () => { fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); expect( - platform.commitFilesToBranch.mock.calls[0][0].files[0].contents + platform.commitFiles.mock.calls[0][0].files[0].contents ).toMatchSnapshot(); }); it('handles skipped onboarding combined with requireConfig = false', async () => { @@ -100,10 +100,10 @@ describe('workers/repository/onboarding/branch', () => { }, }); fs.readLocalFile.mockResolvedValue(pJsonContent); - platform.commitFilesToBranch.mockResolvedValueOnce('abc123'); + platform.commitFiles.mockResolvedValueOnce('abc123'); await checkOnboardingBranch(config); expect( - platform.commitFilesToBranch.mock.calls[0][0].files[0].contents + platform.commitFiles.mock.calls[0][0].files[0].contents ).toMatchSnapshot(); }); it('updates onboarding branch', async () => { @@ -115,7 +115,7 @@ describe('workers/repository/onboarding/branch', () => { expect(res.repoIsOnboarded).toBe(false); expect(res.branchList).toEqual(['renovate/configure']); expect(platform.setBaseBranch).toHaveBeenCalledTimes(1); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0); + expect(platform.commitFiles).toHaveBeenCalledTimes(0); }); }); }); diff --git a/lib/workers/repository/onboarding/branch/rebase.spec.ts b/lib/workers/repository/onboarding/branch/rebase.spec.ts index 897106a997..fda34695fa 100644 --- a/lib/workers/repository/onboarding/branch/rebase.spec.ts +++ b/lib/workers/repository/onboarding/branch/rebase.spec.ts @@ -22,7 +22,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isModified: true, }); await rebaseOnboardingBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0); + expect(platform.commitFiles).toHaveBeenCalledTimes(0); }); it('does nothing if branch is up to date', async () => { const contents = @@ -36,7 +36,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isStale: false, }); await rebaseOnboardingBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0); + expect(platform.commitFiles).toHaveBeenCalledTimes(0); }); it('rebases onboarding branch', async () => { platform.getBranchPr.mockResolvedValueOnce({ @@ -45,7 +45,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isModified: false, }); await rebaseOnboardingBranch(config); - expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(1); + expect(platform.commitFiles).toHaveBeenCalledTimes(1); }); }); }); diff --git a/lib/workers/repository/onboarding/branch/rebase.ts b/lib/workers/repository/onboarding/branch/rebase.ts index 50d7965a0e..445ac440cc 100644 --- a/lib/workers/repository/onboarding/branch/rebase.ts +++ b/lib/workers/repository/onboarding/branch/rebase.ts @@ -49,7 +49,7 @@ export async function rebaseOnboardingBranch( logger.info('DRY-RUN: Would rebase files in onboarding branch'); return null; } - return platform.commitFilesToBranch({ + return platform.commitFiles({ branchName: config.onboardingBranch, files: [ { -- GitLab