diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap index efde7b4bfcf2de..bdab051f49fb3e 100644 --- a/lib/platform/__snapshots__/index.spec.ts.snap +++ b/lib/platform/__snapshots__/index.spec.ts.snap @@ -22,7 +22,6 @@ Array [ "getIssueList", "getPr", "getPrBody", - "getPrFiles", "getPrList", "getRepoForceRebase", "getRepos", @@ -56,7 +55,6 @@ Array [ "getIssueList", "getPr", "getPrBody", - "getPrFiles", "getPrList", "getRepoForceRebase", "getRepos", @@ -90,7 +88,6 @@ Array [ "getIssueList", "getPr", "getPrBody", - "getPrFiles", "getPrList", "getRepoForceRebase", "getRepos", @@ -124,7 +121,6 @@ Array [ "getIssueList", "getPr", "getPrBody", - "getPrFiles", "getPrList", "getRepoForceRebase", "getRepos", diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 51f169b63c15ce..21f84fc091766a 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -233,11 +233,6 @@ export async function getPrList(): Promise { return config.prList; } -/* istanbul ignore next */ -export async function getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); -} - export async function getPr(pullRequestId: number): Promise { logger.debug(`getPr(${pullRequestId})`); if (!pullRequestId) { diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 9fe43c99e29849..8594d033b5eac8 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -365,11 +365,6 @@ export async function getPrList(_args?: any): Promise { return config.prList; } -/* istanbul ignore next */ -export async function getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); -} - // TODO: coverage // istanbul ignore next export async function findPr({ diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 19089d509d2d12..bec3c4e3ee5021 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -211,11 +211,6 @@ export async function getPrList(): Promise { return config.prList; } -/* istanbul ignore next */ -export async function getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); -} - export async function findPr({ branchName, prTitle, diff --git a/lib/platform/common.ts b/lib/platform/common.ts index 143212a95b3819..c29d1194658d96 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -188,7 +188,6 @@ export interface Platform { getVulnerabilityAlerts(): Promise; initRepo(config: RepoParams): Promise; getPrList(): Promise; - getPrFiles(pr: Pr): Promise; ensureIssueClosing(title: string): Promise; ensureIssue( issueConfig: EnsureIssueConfig diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 5519512ac4d2d2..aa069ebbf2e922 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -468,11 +468,6 @@ const platform: Platform = { return config.prList; }, - /* istanbul ignore next */ - async getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); - }, - async getPr(number: number): Promise { // Search for pull request in cached list or attempt to query directly const prList = await platform.getPrList(); @@ -883,7 +878,6 @@ export const { getPr, getPrBody, getPrList, - getPrFiles, getRepoForceRebase, getRepos, getVulnerabilityAlerts, diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 1dba08543578e5..b73778b55e41f2 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -907,11 +907,6 @@ export async function getPrList(): Promise { return config.prList; } -/* istanbul ignore next */ -export async function getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); -} - export async function findPr({ branchName, prTitle, diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 5f81f17376fc6c..4d524e29a16084 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -1017,11 +1017,6 @@ export async function getPrList(): Promise { return config.prList; } -/* istanbul ignore next */ -export async function getPrFiles(pr: Pr): Promise { - return git.getBranchFiles(pr.branchName, pr.targetBranch); -} - function matchesState(state: string, desiredState: string): boolean { if (desiredState === PR_STATE_ALL) { return true; diff --git a/lib/util/git/__snapshots__/index.spec.ts.snap b/lib/util/git/__snapshots__/index.spec.ts.snap index f068e0bb58571a..0ad158e031cfc8 100644 --- a/lib/util/git/__snapshots__/index.spec.ts.snap +++ b/lib/util/git/__snapshots__/index.spec.ts.snap @@ -2,13 +2,7 @@ exports[`platform/git getBranchCommit(branchName) should throw if branch does not exist 1`] = `[Error: Cannot fetch commit for branch that does not exist: not_found]`; -exports[`platform/git getBranchFiles(branchName, baseBranchName?) detects changed files 1`] = ` -Array [ - "some-new-file", -] -`; - -exports[`platform/git getBranchFiles(branchName, baseBranchName?) detects changed files compared to current base branch 1`] = ` +exports[`platform/git getBranchFiles(branchName) detects changed files compared to current base branch 1`] = ` Array [ "some-new-file", ] diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 592e6c204ae46d..635fe2d2e97b5f 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -145,25 +145,7 @@ describe('platform/git', () => { }); }); - describe('getBranchFiles(branchName, baseBranchName?)', () => { - it('detects changed files', async () => { - const hex = await git.getBranchCommit('master'); - await git.createBranch('renovate/branch_with_changes', hex); - const file = { - name: 'some-new-file', - contents: 'some new-contents', - }; - await git.commitFiles({ - branchName: 'renovate/branch_with_changes', - files: [file], - message: 'Create something', - }); - const branchFiles = await git.getBranchFiles( - 'renovate/branch_with_changes', - 'master' - ); - expect(branchFiles).toMatchSnapshot(); - }); + describe('getBranchFiles(branchName)', () => { it('detects changed files compared to current base branch', async () => { const hex = await git.getBranchCommit('master'); await git.createBranch('renovate/branch_with_changes', hex); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 6612fb90d1ef5c..d2d3aea5c1d392 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -435,15 +435,9 @@ export async function getBranchLastCommitTime( } } -export async function getBranchFiles( - branchName: string, - baseBranchName?: string -): Promise { +export async function getBranchFiles(branchName: string): Promise { try { - const diff = await git.diffSummary([ - branchName, - baseBranchName || config.baseBranch, - ]); + const diff = await git.diffSummary([branchName, config.baseBranch]); return diff.files.map((file) => file.file); } catch (err) /* istanbul ignore next */ { checkForPlatformFailure(err); diff --git a/lib/workers/pr/code-owners.spec.ts b/lib/workers/pr/code-owners.spec.ts index f353cb7c683e54..d6999d28b38fac 100644 --- a/lib/workers/pr/code-owners.spec.ts +++ b/lib/workers/pr/code-owners.spec.ts @@ -1,9 +1,10 @@ import { mock } from 'jest-mock-extended'; -import { fs, platform } from '../../../test/util'; +import { fs, git } from '../../../test/util'; import { Pr } from '../../platform'; import { codeOwnersForPr } from './code-owners'; jest.mock('../../util/fs'); +jest.mock('../../util/git'); describe('workers/pr/code-owners', () => { describe('codeOwnersForPr', () => { @@ -14,7 +15,7 @@ describe('workers/pr/code-owners', () => { }); it('returns global code owner', async () => { fs.readLocalFile.mockResolvedValueOnce(['* @jimmy'].join('\n')); - platform.getPrFiles.mockResolvedValueOnce(['README.md']); + git.getBranchFiles.mockResolvedValueOnce(['README.md']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual(['@jimmy']); }); @@ -22,7 +23,7 @@ describe('workers/pr/code-owners', () => { fs.readLocalFile.mockResolvedValueOnce( ['* @jimmy', 'package.json @john @maria'].join('\n') ); - platform.getPrFiles.mockResolvedValueOnce(['package.json']); + git.getBranchFiles.mockResolvedValueOnce(['package.json']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual(['@john', '@maria']); }); @@ -36,13 +37,13 @@ describe('workers/pr/code-owners', () => { ' package.json @john @maria ', ].join('\n') ); - platform.getPrFiles.mockResolvedValueOnce(['package.json']); + git.getBranchFiles.mockResolvedValueOnce(['package.json']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual(['@john', '@maria']); }); it('returns empty array when no code owners set', async () => { fs.readLocalFile.mockResolvedValueOnce(null); - platform.getPrFiles.mockResolvedValueOnce(['package.json']); + git.getBranchFiles.mockResolvedValueOnce(['package.json']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual([]); }); @@ -50,7 +51,7 @@ describe('workers/pr/code-owners', () => { fs.readLocalFile.mockResolvedValueOnce( ['package-lock.json @mike'].join('\n') ); - platform.getPrFiles.mockResolvedValueOnce(['yarn.lock']); + git.getBranchFiles.mockResolvedValueOnce(['yarn.lock']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual([]); }); @@ -75,7 +76,7 @@ describe('workers/pr/code-owners', () => { } return Promise.resolve(null); }); - platform.getPrFiles.mockResolvedValueOnce(['README.md']); + git.getBranchFiles.mockResolvedValueOnce(['README.md']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual(['@mike']); }); diff --git a/lib/workers/pr/code-owners.ts b/lib/workers/pr/code-owners.ts index d2522d5068503e..21930d3104f70b 100644 --- a/lib/workers/pr/code-owners.ts +++ b/lib/workers/pr/code-owners.ts @@ -1,7 +1,8 @@ import ignore from 'ignore'; import { logger } from '../../logger'; -import { Pr, platform } from '../../platform'; +import { Pr } from '../../platform'; import { readLocalFile } from '../../util/fs'; +import { getBranchFiles } from '../../util/git'; export async function codeOwnersForPr(pr: Pr): Promise { try { @@ -15,7 +16,7 @@ export async function codeOwnersForPr(pr: Pr): Promise { return []; } - const prFiles = await platform.getPrFiles(pr); + const prFiles = await getBranchFiles(pr.branchName); const rules = codeOwnersFile .split('\n') .map((line) => line.trim())