From 4665dbff6fe96c4aa2665d95022284c60be3f320 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 8 Jul 2020 14:14:13 +0200 Subject: [PATCH] refactor: remove commitFiles from platforms (#6701) Co-authored-by: Michael Kriese --- lib/manager/common.ts | 2 +- lib/platform/__snapshots__/index.spec.ts.snap | 132 ------------------ lib/platform/azure/index.ts | 13 -- .../__snapshots__/index.spec.ts.snap | 82 ----------- lib/platform/bitbucket-server/index.spec.ts | 21 --- lib/platform/bitbucket-server/index.ts | 18 +-- .../__snapshots__/index.spec.ts.snap | 18 --- lib/platform/bitbucket/index.spec.ts | 13 -- lib/platform/bitbucket/index.ts | 8 -- lib/platform/common.ts | 24 +--- lib/platform/gitea/index.spec.ts | 27 +--- lib/platform/gitea/index.ts | 6 - lib/platform/github/index.ts | 8 -- .../gitlab/__snapshots__/index.spec.ts.snap | 16 --- lib/platform/gitlab/index.spec.ts | 12 -- lib/platform/gitlab/index.ts | 8 -- lib/platform/index.spec.ts | 56 -------- lib/util/git/index.ts | 23 ++- lib/workers/branch/commit.spec.ts | 14 +- lib/workers/branch/commit.ts | 4 +- lib/workers/branch/get-updated.ts | 3 +- lib/workers/branch/index.spec.ts | 3 +- lib/workers/branch/index.ts | 4 + lib/workers/common.ts | 3 +- .../repository/onboarding/branch/create.ts | 4 +- .../onboarding/branch/index.spec.ts | 4 +- .../repository/onboarding/branch/index.ts | 5 + .../onboarding/branch/rebase.spec.ts | 6 +- .../repository/onboarding/branch/rebase.ts | 4 +- 29 files changed, 62 insertions(+), 479 deletions(-) diff --git a/lib/manager/common.ts b/lib/manager/common.ts index 5d4319e4d0bad8..3a916bcf1e4f94 100644 --- a/lib/manager/common.ts +++ b/lib/manager/common.ts @@ -1,7 +1,7 @@ import { ReleaseType } from 'semver'; import { GlobalConfig, UpdateType, ValidationMessage } from '../config/common'; -import { File } from '../platform/common'; import { RangeStrategy, SkipReason } from '../types'; +import { File } from '../util/git'; export type Result = T | Promise; diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap index bdab051f49fb3e..c6720de416c79e 100644 --- a/lib/platform/__snapshots__/index.spec.ts.snap +++ b/lib/platform/__snapshots__/index.spec.ts.snap @@ -2,138 +2,6 @@ exports[`platform escapes names 1`] = `"name [what]"`; -exports[`platform has a list of supported methods for azure 1`] = ` -Array [ - "addAssignees", - "addReviewers", - "commitFiles", - "createPr", - "deleteBranch", - "deleteLabel", - "ensureComment", - "ensureCommentRemoval", - "ensureIssue", - "ensureIssueClosing", - "findIssue", - "findPr", - "getBranchPr", - "getBranchStatus", - "getBranchStatusCheck", - "getIssueList", - "getPr", - "getPrBody", - "getPrList", - "getRepoForceRebase", - "getRepos", - "getVulnerabilityAlerts", - "initPlatform", - "initRepo", - "mergePr", - "setBaseBranch", - "setBranchStatus", - "updatePr", -] -`; - -exports[`platform has a list of supported methods for gitea 1`] = ` -Array [ - "addAssignees", - "addReviewers", - "commitFiles", - "createPr", - "deleteBranch", - "deleteLabel", - "ensureComment", - "ensureCommentRemoval", - "ensureIssue", - "ensureIssueClosing", - "findIssue", - "findPr", - "getBranchPr", - "getBranchStatus", - "getBranchStatusCheck", - "getIssueList", - "getPr", - "getPrBody", - "getPrList", - "getRepoForceRebase", - "getRepos", - "getVulnerabilityAlerts", - "initPlatform", - "initRepo", - "mergePr", - "setBaseBranch", - "setBranchStatus", - "updatePr", -] -`; - -exports[`platform has a list of supported methods for github 1`] = ` -Array [ - "addAssignees", - "addReviewers", - "commitFiles", - "createPr", - "deleteBranch", - "deleteLabel", - "ensureComment", - "ensureCommentRemoval", - "ensureIssue", - "ensureIssueClosing", - "findIssue", - "findPr", - "getBranchPr", - "getBranchStatus", - "getBranchStatusCheck", - "getIssueList", - "getPr", - "getPrBody", - "getPrList", - "getRepoForceRebase", - "getRepos", - "getVulnerabilityAlerts", - "initPlatform", - "initRepo", - "mergePr", - "setBaseBranch", - "setBranchStatus", - "updatePr", -] -`; - -exports[`platform has a list of supported methods for gitlab 1`] = ` -Array [ - "addAssignees", - "addReviewers", - "commitFiles", - "createPr", - "deleteBranch", - "deleteLabel", - "ensureComment", - "ensureCommentRemoval", - "ensureIssue", - "ensureIssueClosing", - "findIssue", - "findPr", - "getBranchPr", - "getBranchStatus", - "getBranchStatusCheck", - "getIssueList", - "getPr", - "getPrBody", - "getPrList", - "getRepoForceRebase", - "getRepos", - "getVulnerabilityAlerts", - "initPlatform", - "initRepo", - "mergePr", - "setBaseBranch", - "setBranchStatus", - "updatePr", -] -`; - exports[`platform initializes 1`] = ` Object { "endpoint": "https://api.bitbucket.org/", diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 21f84fc091766a..c100776518a0de 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -19,7 +19,6 @@ import { sanitize } from '../../util/sanitize'; import { ensureTrailingSlash } from '../../util/url'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -326,18 +325,6 @@ export /* istanbul ignore next */ async function deleteBranch( } } -export /* istanbul ignore next */ function commitFiles({ - branchName, - files, - message, -}: CommitFilesConfig): Promise { - return git.commitFiles({ - branchName, - files, - message, - }); -} - export async function getBranchStatusCheck( branchName: string, context: string diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index b41cdd85231474..e64f7e282896ed 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -546,47 +546,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with no path commitFiles() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100", - }, -] -`; - exports[`platform/bitbucket-server endpoint with no path createPr() posts PR 1`] = ` Array [ Object { @@ -4449,47 +4408,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with path commitFiles() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100", - }, -] -`; - exports[`platform/bitbucket-server endpoint with path createPr() posts PR 1`] = ` Array [ Object { diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 82221e37438966..54915b0b1318f8 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -408,27 +408,6 @@ describe('platform/bitbucket-server', () => { }); }); - describe('commitFiles()', () => { - it('sends to gitFs', async () => { - expect.assertions(1); - const scope = await initRepo(); - scope - .get( - `${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100` - ) - .reply(200, { - isLastPage: true, - values: [prMock(url, 'SOME', 'repo')], - }); - await bitbucket.commitFiles({ - branchName: 'some-branch', - files: [{ name: 'test', contents: 'dummy' }], - message: 'message', - }); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('addAssignees()', () => { it('does not throw', async () => { expect(await bitbucket.addAssignees(3, ['some'])).toMatchSnapshot(); diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 8594d033b5eac8..079e613b920851 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -21,7 +21,6 @@ import { sanitize } from '../../util/sanitize'; import { ensureTrailingSlash } from '../../util/url'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -385,28 +384,21 @@ export async function findPr({ } // Returns the Pull Request for a branch. Null if not exists. -export async function getBranchPr( - branchName: string, - refreshCache?: boolean -): Promise { +export async function getBranchPr(branchName: string): Promise { logger.debug(`getBranchPr(${branchName})`); const existingPr = await findPr({ branchName, state: PR_STATE_OPEN, }); - return existingPr ? getPr(existingPr.number, refreshCache) : null; + return existingPr ? getPr(existingPr.number) : null; } -export async function commitFiles( - commitFilesConfig: CommitFilesConfig -): Promise { - const commit = git.commitFiles(commitFilesConfig); - +// istanbul ignore next +export async function refreshPr(number: number): Promise { // wait for pr change propagation await delay(1000); // refresh cache - await getBranchPr(commitFilesConfig.branchName, true); - return commit; + await getPr(number, true); } export async function deleteBranch( diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index 76786c3e693e82..d8d0869a56c6be 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -64,24 +64,6 @@ Array [ ] `; -exports[`platform/bitbucket commitFiles() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket commitFiles() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "api.bitbucket.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://api.bitbucket.org/2.0/repositories/some/repo", - }, -] -`; - exports[`platform/bitbucket createPr() posts PR 1`] = ` Array [ Object { diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index 9ae1831a45ba25..6217dabd0a7ec7 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -807,19 +807,6 @@ describe('platform/bitbucket', () => { }); }); - describe('commitFiles()', () => { - it('sends to gitFs', async () => { - await initRepoMock(); - const res = await bitbucket.commitFiles({ - branchName: 'test', - files: [], - message: 'message', - }); - expect(res).toMatchSnapshot(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('getVulnerabilityAlerts()', () => { it('returns empty array', async () => { expect(await bitbucket.getVulnerabilityAlerts()).toEqual([]); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index bec3c4e3ee5021..5ab6af86a77740 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -16,7 +16,6 @@ import { BitbucketHttp, setBaseUrl } from '../../util/http/bitbucket'; import { sanitize } from '../../util/sanitize'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -245,13 +244,6 @@ export async function deleteBranch( return git.deleteBranch(branchName); } -// istanbul ignore next -export function commitFiles( - commitFilesConfig: CommitFilesConfig -): Promise { - return git.commitFiles(commitFilesConfig); -} - async function isPrConflicted(prNo: number): Promise { const diff = ( await bitbucketHttp.get( diff --git a/lib/platform/common.ts b/lib/platform/common.ts index c29d1194658d96..a6325d8b71327d 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -7,28 +7,6 @@ import { export type VulnerabilityAlert = _VulnerabilityAlert; -/** - * File to commit to branch - */ -export interface File { - /** - * Relative file path - */ - name: string; - - /** - * file contents - */ - contents: string | Buffer; -} - -export type CommitFilesConfig = { - branchName: string; - files: File[]; - message: string; - force?: boolean; -}; - export interface GotApiOptions { useCache?: boolean; hostType?: string; @@ -214,9 +192,9 @@ export interface Platform { deleteBranch(branchName: string, closePr?: boolean): Promise; ensureComment(ensureComment: EnsureCommentConfig): Promise; setBaseBranch(baseBranch?: string): Promise; - commitFiles(commitFile: CommitFilesConfig): Promise; getPr(number: number): Promise; findPr(findPRConfig: FindPRConfig): Promise; + refreshPr?(number: number): Promise; getBranchStatus( branchName: string, requiredStatusChecks?: string[] | null diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index eb213e200a49a9..a3eb028734f0a7 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -1,11 +1,4 @@ -import { - BranchStatusConfig, - CommitFilesConfig, - File, - Platform, - RepoConfig, - RepoParams, -} from '..'; +import { BranchStatusConfig, Platform, RepoConfig, RepoParams } from '..'; import { partial } from '../../../test/util'; import { REPOSITORY_ACCESS_FORBIDDEN, @@ -1336,24 +1329,6 @@ describe('platform/gitea', () => { }); }); - describe('commitFiles', () => { - it('should propagate call to storage class with default parent branch', async () => { - const commitConfig: CommitFilesConfig = { - branchName: 'some-branch', - files: [partial({})], - message: 'some-message', - }; - - await initFakeRepo(); - await gitea.commitFiles(commitConfig); - - expect(gitvcs.commitFiles).toHaveBeenCalledTimes(1); - expect(gitvcs.commitFiles).toHaveBeenCalledWith({ - ...commitConfig, - }); - }); - }); - describe('getPrBody', () => { it('should truncate body to 1000000 characters', () => { const excessiveBody = '*'.repeat(1000001); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index aa069ebbf2e922..5dd9eb2c6c5f56 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -21,7 +21,6 @@ import { sanitize } from '../../util/sanitize'; import { ensureTrailingSlash } from '../../util/url'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -845,10 +844,6 @@ const platform: Platform = { return Promise.resolve(); }, - commitFiles(commitFilesConfig: CommitFilesConfig): Promise { - return git.commitFiles(commitFilesConfig); - }, - getPrBody(prBody: string): string { return smartTruncate(prBody, 1000000); }, @@ -861,7 +856,6 @@ const platform: Platform = { export const { addAssignees, addReviewers, - commitFiles, createPr, deleteBranch, deleteLabel, diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index b73778b55e41f2..32a0431ed523da 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -31,7 +31,6 @@ import { sanitize } from '../../util/sanitize'; import { ensureTrailingSlash } from '../../util/url'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -494,13 +493,6 @@ export function deleteBranch( return git.deleteBranch(branchName); } -// istanbul ignore next -export function commitFiles( - commitFilesConfig: CommitFilesConfig -): Promise { - return git.commitFiles(commitFilesConfig); -} - async function getClosedPrs(): Promise { if (!config.closedPrList) { config.closedPrList = {}; diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index 5f4f2125c497c3..1ec0d3cee99631 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -148,22 +148,6 @@ Array [ exports[`platform/gitlab addReviewers(issueNo, reviewers) should add the given reviewers to the PR 1`] = `Array []`; -exports[`platform/gitlab commitFiles() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/projects/some%2Frepo", - }, -] -`; - exports[`platform/gitlab createPr(branchName, title, body) auto-accepts the MR when requested 1`] = ` Array [ Object { diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 0ee02ac057c89a..ad2e79ea10b7af 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -1171,18 +1171,6 @@ These updates have all been created already. Click a checkbox below to force a r expect(gitlab.getPrBody(prBody)).toMatchSnapshot(); }); }); - describe('commitFiles()', () => { - it('sends to gitFs', async () => { - expect.assertions(1); - await initRepo(); - await gitlab.commitFiles({ - branchName: 'some-branch', - files: [{ name: 'SomeFile', contents: 'Some Content' }], - message: '', - }); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); describe('getVulnerabilityAlerts()', () => { it('returns empty', async () => { const res = await gitlab.getVulnerabilityAlerts(); diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 4d524e29a16084..e3950db9d81572 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -26,7 +26,6 @@ import { sanitize } from '../../util/sanitize'; import { ensureTrailingSlash } from '../../util/url'; import { BranchStatusConfig, - CommitFilesConfig, CreatePRConfig, EnsureCommentConfig, EnsureCommentRemovalConfig, @@ -590,13 +589,6 @@ export async function getBranchPr(branchName: string): Promise { return getPr(pr.iid); } -// istanbul ignore next -export function commitFiles( - commitFilesConfig: CommitFilesConfig -): Promise { - return git.commitFiles(commitFilesConfig); -} - export async function deleteBranch( branchName: string, shouldClosePr = false diff --git a/lib/platform/index.spec.ts b/lib/platform/index.spec.ts index ab87556b34a7db..6669e8f73225e4 100644 --- a/lib/platform/index.spec.ts +++ b/lib/platform/index.spec.ts @@ -1,12 +1,6 @@ import { PLATFORM_NOT_FOUND } from '../constants/error-messages'; import { PLATFORM_TYPE_BITBUCKET } from '../constants/platforms'; import { loadModules } from '../util/modules'; -import * as azure from './azure'; -import * as bitbucket from './bitbucket'; -import * as bitbucketServer from './bitbucket-server'; -import * as gitea from './gitea'; -import * as github from './github'; -import * as gitlab from './gitlab'; import * as platform from '.'; import { Platform } from '.'; @@ -67,56 +61,6 @@ describe('platform', () => { }; expect(await platform.initPlatform(config)).toMatchSnapshot(); }); - it('has a list of supported methods for github', () => { - const githubMethods = Object.keys(github).sort(); - expect(githubMethods).toMatchSnapshot(); - }); - - it('has a list of supported methods for gitlab', () => { - const gitlabMethods = Object.keys(gitlab).sort(); - expect(gitlabMethods).toMatchSnapshot(); - }); - - it('has a list of supported methods for gitea', () => { - const giteaMethods = Object.keys(gitea).sort(); - expect(giteaMethods).toMatchSnapshot(); - }); - - it('has a list of supported methods for azure', () => { - const azureMethods = Object.keys(azure).sort(); - expect(azureMethods).toMatchSnapshot(); - }); - - it('has same API for github and gitlab', () => { - const githubMethods = Object.keys(github).sort(); - const gitlabMethods = Object.keys(gitlab).sort(); - expect(githubMethods).toMatchObject(gitlabMethods); - }); - - it('has same API for github and gitea', () => { - const githubMethods = Object.keys(github).sort(); - const giteaMethods = Object.keys(gitea).sort(); - expect(githubMethods).toMatchObject(giteaMethods); - }); - - it('has same API for github and azure', () => { - const githubMethods = Object.keys(github).sort(); - const azureMethods = Object.keys(azure).sort(); - expect(githubMethods).toMatchObject(azureMethods); - }); - - it('has same API for github and Bitbucket', () => { - const githubMethods = Object.keys(github).sort(); - const bitbucketMethods = Object.keys(bitbucket).sort(); - expect(bitbucketMethods).toMatchObject(githubMethods); - }); - - it('has same API for github and Bitbucket Server', () => { - const githubMethods = Object.keys(github).sort(); - const bitbucketMethods = Object.keys(bitbucketServer).sort(); - expect(bitbucketMethods).toMatchObject(githubMethods); - }); - it('returns null if empty email given', () => { expect(platform.parseGitAuthor(undefined)).toBeNull(); }); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index d2d3aea5c1d392..91bc12731dcd70 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -10,7 +10,6 @@ import { SYSTEM_INSUFFICIENT_DISK_SPACE, } from '../../constants/error-messages'; import { logger } from '../../logger'; -import { CommitFilesConfig } from '../../platform/common'; import { ExternalHostError } from '../../types/errors/external-host-error'; import * as limits from '../../workers/global/limits'; import { writePrivateKey } from './private-key'; @@ -475,6 +474,28 @@ export async function hasDiff(branchName: string): Promise { } } +/** + * File to commit + */ +export interface File { + /** + * Relative file path + */ + name: string; + + /** + * file contents + */ + contents: string | Buffer; +} + +export type CommitFilesConfig = { + branchName: string; + files: File[]; + message: string; + force?: boolean; +}; + export async function commitFiles({ branchName, files, diff --git a/lib/workers/branch/commit.spec.ts b/lib/workers/branch/commit.spec.ts index d654a6b98fd1db..65add63e6f9216 100644 --- a/lib/workers/branch/commit.spec.ts +++ b/lib/workers/branch/commit.spec.ts @@ -1,7 +1,9 @@ -import { defaultConfig, partial, platform } from '../../../test/util'; +import { defaultConfig, git, partial } from '../../../test/util'; import { BranchConfig } from '../common'; import { commitFilesToBranch } from './commit'; +jest.mock('../../util/git'); + describe('workers/branch/automerge', () => { describe('commitFilesToBranch', () => { let config: BranchConfig; @@ -17,11 +19,11 @@ describe('workers/branch/automerge', () => { updatedArtifacts: [], }); jest.resetAllMocks(); - platform.commitFiles.mockResolvedValueOnce('abc123'); + git.commitFiles.mockResolvedValueOnce('abc123'); }); it('handles empty files', async () => { await commitFilesToBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(0); + expect(git.commitFiles).toHaveBeenCalledTimes(0); }); it('commits files', async () => { config.updatedPackageFiles.push({ @@ -29,8 +31,8 @@ describe('workers/branch/automerge', () => { contents: 'some contents', }); await commitFilesToBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(1); - expect(platform.commitFiles.mock.calls).toMatchSnapshot(); + expect(git.commitFiles).toHaveBeenCalledTimes(1); + expect(git.commitFiles.mock.calls).toMatchSnapshot(); }); it('dry runs', async () => { config.dryRun = true; @@ -39,7 +41,7 @@ describe('workers/branch/automerge', () => { contents: 'some contents', }); await commitFilesToBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(0); + expect(git.commitFiles).toHaveBeenCalledTimes(0); }); }); }); diff --git a/lib/workers/branch/commit.ts b/lib/workers/branch/commit.ts index 4bf55c818406d6..35ebdb58f26809 100644 --- a/lib/workers/branch/commit.ts +++ b/lib/workers/branch/commit.ts @@ -2,7 +2,7 @@ import is from '@sindresorhus/is'; import minimatch from 'minimatch'; import { CONFIG_SECRETS_EXPOSED } from '../../constants/error-messages'; import { logger } from '../../logger'; -import { platform } from '../../platform'; +import { commitFiles } from '../../util/git'; import { sanitize } from '../../util/sanitize'; import { BranchConfig } from '../common'; @@ -43,7 +43,7 @@ export async function commitFilesToBranch( throw new Error(CONFIG_SECRETS_EXPOSED); } // API will know whether to create new branch or not - return platform.commitFiles({ + return commitFiles({ branchName: config.branchName, files: updatedFiles, message: config.commitMessage, diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index 3d5f64e37bd983..d922990984ac71 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -4,8 +4,7 @@ import * as datasourceGitSubmodules from '../../datasource/git-submodules'; import { logger } from '../../logger'; import { get } from '../../manager'; import { ArtifactError } from '../../manager/common'; -import { File } from '../../platform'; -import { getFile } from '../../util/git'; +import { File, getFile } from '../../util/git'; import { BranchConfig } from '../common'; import { doAutoReplace } from './auto-replace'; diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index d1c14f354010d0..f7d2019ea7787a 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -10,9 +10,8 @@ import { PR_STATE_OPEN, } from '../../constants/pull-requests'; import * as _npmPostExtract from '../../manager/npm/post-update'; -import { File } from '../../platform'; import * as _exec from '../../util/exec'; -import { StatusResult } from '../../util/git'; +import { File, StatusResult } from '../../util/git'; import { BranchConfig, PrResult } from '../common'; import * as _prWorker from '../pr'; import * as _automerge from './automerge'; diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index c481e20a5f4634..52f5ed5a33674f 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -421,6 +421,10 @@ export async function processBranch( config.forceCommit = !!masterIssueCheck || config.rebaseRequested || branchPr?.isConflicted; const commitHash = await commitFilesToBranch(config); + // istanbul ignore if + if (branchPr && platform.refreshPr) { + await platform.refreshPr(branchPr.number); + } if (!commitHash && !branchExists) { return 'no-work'; } diff --git a/lib/workers/common.ts b/lib/workers/common.ts index e40f83a2e4db74..47f474ebbf23bb 100644 --- a/lib/workers/common.ts +++ b/lib/workers/common.ts @@ -12,7 +12,8 @@ import { PackageDependency, PackageFile, } from '../manager/common'; -import { File, PlatformPrOptions } from '../platform'; +import { PlatformPrOptions } from '../platform'; +import { File } from '../util/git'; import { ChangeLogResult } from './pr/changelog/common'; import { Merge } from 'type-fest'; diff --git a/lib/workers/repository/onboarding/branch/create.ts b/lib/workers/repository/onboarding/branch/create.ts index 709e7bbfa4ae54..ff7ffc068e8358 100644 --- a/lib/workers/repository/onboarding/branch/create.ts +++ b/lib/workers/repository/onboarding/branch/create.ts @@ -1,7 +1,7 @@ import { RenovateConfig } from '../../../../config'; import { configFileNames } from '../../../../config/app-strings'; import { logger } from '../../../../logger'; -import { platform } from '../../../../platform'; +import { commitFiles } from '../../../../util/git'; import { getOnboardingConfig } from './config'; const defaultConfigFile = configFileNames[0]; @@ -29,7 +29,7 @@ export async function createOnboardingBranch( logger.info('DRY-RUN: Would commit files to onboarding branch'); return null; } - return platform.commitFiles({ + return 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 8d61dc07d9f1c5..639c7ecba06893 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -37,7 +37,7 @@ describe('workers/repository/onboarding/branch', () => { fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); expect( - platform.commitFiles.mock.calls[0][0].files[0].contents + git.commitFiles.mock.calls[0][0].files[0].contents ).toMatchSnapshot(); }); it('handles skipped onboarding combined with requireConfig = false', async () => { @@ -99,7 +99,7 @@ describe('workers/repository/onboarding/branch', () => { expect(res.repoIsOnboarded).toBe(false); expect(res.branchList).toEqual(['renovate/configure']); expect(platform.setBaseBranch).toHaveBeenCalledTimes(1); - expect(platform.commitFiles).toHaveBeenCalledTimes(0); + expect(git.commitFiles).toHaveBeenCalledTimes(0); }); }); }); diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index ace750bb82cf88..4e51dbd61b5438 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -33,6 +33,11 @@ export async function checkOnboardingBranch( 'Branch updated' ); } + // istanbul ignore if + if (platform.refreshPr) { + const onboardingPr = await platform.getBranchPr(config.onboardingBranch); + await platform.refreshPr(onboardingPr.number); + } } else { logger.debug('Onboarding PR does not exist'); if (Object.entries(await extractAllDependencies(config)).length === 0) { diff --git a/lib/workers/repository/onboarding/branch/rebase.spec.ts b/lib/workers/repository/onboarding/branch/rebase.spec.ts index 9ec32ee7a3dfa1..fe9678364d7334 100644 --- a/lib/workers/repository/onboarding/branch/rebase.spec.ts +++ b/lib/workers/repository/onboarding/branch/rebase.spec.ts @@ -25,7 +25,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isModified: true, }); await rebaseOnboardingBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(0); + expect(git.commitFiles).toHaveBeenCalledTimes(0); }); it('does nothing if branch is up to date', async () => { const contents = @@ -39,7 +39,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isStale: false, }); await rebaseOnboardingBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(0); + expect(git.commitFiles).toHaveBeenCalledTimes(0); }); it('rebases onboarding branch', async () => { platform.getBranchPr.mockResolvedValueOnce({ @@ -48,7 +48,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { isModified: false, }); await rebaseOnboardingBranch(config); - expect(platform.commitFiles).toHaveBeenCalledTimes(1); + expect(git.commitFiles).toHaveBeenCalledTimes(1); }); }); }); diff --git a/lib/workers/repository/onboarding/branch/rebase.ts b/lib/workers/repository/onboarding/branch/rebase.ts index 0b34bb6ed0e0be..26148254155a40 100644 --- a/lib/workers/repository/onboarding/branch/rebase.ts +++ b/lib/workers/repository/onboarding/branch/rebase.ts @@ -2,7 +2,7 @@ import { RenovateConfig } from '../../../../config'; import { configFileNames } from '../../../../config/app-strings'; import { logger } from '../../../../logger'; import { platform } from '../../../../platform'; -import { getFile } from '../../../../util/git'; +import { commitFiles, getFile } from '../../../../util/git'; import { getOnboardingConfig } from './config'; const defaultConfigFile = configFileNames[0]; @@ -50,7 +50,7 @@ export async function rebaseOnboardingBranch( logger.info('DRY-RUN: Would rebase files in onboarding branch'); return null; } - return platform.commitFiles({ + return commitFiles({ branchName: config.onboardingBranch, files: [ {