diff --git a/lib/manager/common.ts b/lib/manager/common.ts index 5d4319e4d0bad88a380b4ab883fc9ecac132878f..3a916bcf1e4f944edb328a9415b39da9787a009d 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> = T | Promise<T>; diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap index bdab051f49fb3e444881ed5af464362144ed2e48..c6720de416c79e96081a9ba423728e56bff2ea41 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 21f84fc091766a0832624deb8ebe828475d17d98..c100776518a0de36f5b435421999d2cbdf285992 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<string | null> { - 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 b41cdd8523147418ba3aaf9ea8750cf2da3cd0ed..e64f7e282896edbb62bb49b153e52a92277169fd 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 82221e374389668409454462050048a7478b68e8..54915b0b1318f836ad65a9eb5b7d8b7c462d014c 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 8594d033b5eac8d139838902b898518f451b21e7..079e613b92085184fac29ee273c28e3146f8eb3e 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<BbsPr | null> { +export async function getBranchPr(branchName: string): Promise<BbsPr | null> { 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<string | null> { - const commit = git.commitFiles(commitFilesConfig); - +// istanbul ignore next +export async function refreshPr(number: number): Promise<void> { // 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 76786c3e693e82925aba109b0689ea81ae3cf89d..d8d0869a56c6be9639bbadd37d7629d74048ca79 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 9ae1831a45ba25a4624d5bbcde1ffc26c66b6afc..6217dabd0a7ec74531c9982765343dc73b8c3bf0 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 bec3c4e3ee50213ac600c99f30b69400daeb6a14..5ab6af86a7774016013a0bf53d0097dd1da886d0 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<string | null> { - return git.commitFiles(commitFilesConfig); -} - async function isPrConflicted(prNo: number): Promise<boolean> { const diff = ( await bitbucketHttp.get( diff --git a/lib/platform/common.ts b/lib/platform/common.ts index c29d1194658d96e92fc353384b46e1628275cbca..a6325d8b71327d26d4336a9c6920f81d725ca729 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<void>; ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>; setBaseBranch(baseBranch?: string): Promise<string>; - commitFiles(commitFile: CommitFilesConfig): Promise<string | null>; getPr(number: number): Promise<Pr>; findPr(findPRConfig: FindPRConfig): Promise<Pr>; + refreshPr?(number: number): Promise<void>; getBranchStatus( branchName: string, requiredStatusChecks?: string[] | null diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index eb213e200a49a94b1cc745bea34ecf91f95040b0..a3eb028734f0a755d50298ce42e90f3d9ad645e0 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<File>({})], - 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 aa069ebbf2e9229819bad6b168efae898974269d..5dd9eb2c6c5f567256219f367f6cd86b195cc9f5 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<string | null> { - 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 b73778b55e41f23b444413ba407cf688c5147ae3..32a0431ed523da2b59b41458511146c1df5b64fd 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<string | null> { - return git.commitFiles(commitFilesConfig); -} - async function getClosedPrs(): Promise<PrList> { 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 5f4f2125c497c30f90a3a049dfb5b00bbb4abcce..1ec0d3cee996317b0d4f04aa3562007804a4ad70 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 0ee02ac057c89a52db7a6900fb0704287f24a4f5..ad2e79ea10b7afff1c398a14af59a0c84d4bd067 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 4d524e29a160840a23c1c74b97ef9cc5500a84b2..e3950db9d815721c56c94c93d5e1ca1af4958fee 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<Pr> { return getPr(pr.iid); } -// istanbul ignore next -export function commitFiles( - commitFilesConfig: CommitFilesConfig -): Promise<string | null> { - 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 ab87556b34a7db55d538aa84a0ad96af0e49695a..6669e8f73225e49dba9f90fcc0cc402167caf2b7 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 d2d3aea5c1d3924c54ab380821d6ea523b8f0e13..91bc12731dcd70ff91c7e96d992015adee013c34 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<boolean> { } } +/** + * 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 d654a6b98fd1dbee6c69c5cd8effdf53d0546124..65add63e6f921604314e17eecca44cd327325094 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 4bf55c818406d61f41e761db90fa318e3715af48..35ebdb58f26809f540b236208d89c12dc8a86116 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 3d5f64e37bd9835bb2cfb393b5a994be1eec6fa2..d922990984ac7155752d3f719496353d0f40c0d8 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 d1c14f354010d0b02ced70e1d7b61aa099be6e17..f7d2019ea7787a639795353c4ea99b79ca8be92b 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 c481e20a5f463441c3f83a84d3e27e36bb0d0c81..52f5ed5a33674f20dbf05a8e8a8e8dea5ce79e00 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 e40f83a2e4db74db0c7f8ab1dbe5d9cf73500a25..47f474ebbf23bb6b928ff79ee7566b1e9d1af700 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 709e7bbfa4ae54b02500ed24c3a377eb4b5e2a34..ff7ffc068e8358038ce418f4e58f0a46cae0879d 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 8d61dc07d9f1c5331e4b101adaa03a6f0a1ad1d7..639c7ecba068935e64c532a26d2650bfacb4a0bf 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 ace750bb82cf8800c3f8d64ea6f84314fc36e1fe..4e51dbd61b54384e15bb0c0fa6fa6046fd94a77e 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 9ec32ee7a3dfa1212a1dc8a9f885492ed6bdb687..fe9678364d7334fa820307057666705b1b02e086 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 0b34bb6ed0e0be4c95a1367ba2400f991dc33e88..26148254155a4025889362c6e41a1c50bdc588a5 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: [ {