diff --git a/lib/constants/pull-requests.ts b/lib/constants/pull-requests.ts new file mode 100644 index 0000000000000000000000000000000000000000..9f926c4e0d8effb809e3fbaba2007388a3d52346 --- /dev/null +++ b/lib/constants/pull-requests.ts @@ -0,0 +1,5 @@ +export const PR_STATE_MERGED = 'merged'; +export const PR_STATE_OPEN = 'open'; +export const PR_STATE_CLOSED = 'closed'; +export const PR_STATE_ALL = 'all'; +export const PR_STATE_NOT_OPEN = '!open'; diff --git a/lib/platform/azure/azure-helper.ts b/lib/platform/azure/azure-helper.ts index 294971af8330f2fb0230f11a75519a9202e09e3e..1732baed5d9979e65712db718213c82ffd651446 100644 --- a/lib/platform/azure/azure-helper.ts +++ b/lib/platform/azure/azure-helper.ts @@ -8,6 +8,11 @@ import { import * as azureApi from './azure-got-wrapper'; import { logger } from '../../logger'; import { Pr } from '../common'; +import { + PR_STATE_CLOSED, + PR_STATE_MERGED, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; const mergePolicyGuid = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab'; // Magic GUID for merge strategy policy configurations @@ -173,11 +178,11 @@ export function getRenovatePRFormat(azurePr: GitPullRequest): Pr { // All = 4, // } if (azurePr.status === 2) { - pr.state = 'closed'; + pr.state = PR_STATE_CLOSED; } else if (azurePr.status === 3) { - pr.state = 'merged'; + pr.state = PR_STATE_MERGED; } else { - pr.state = 'open'; + pr.state = PR_STATE_OPEN; } // mergeStatus diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index b9facb5f288488f2d7f7e3e14a5ba7320a921852..b6a7c90d5873b22a9bacf701b2167e66f166dc96 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -26,6 +26,11 @@ import { sanitize } from '../../util/sanitize'; import { smartTruncate } from '../utils/pr-body'; import { REPOSITORY_DISABLED } from '../../constants/error-messages'; import { PLATFORM_TYPE_AZURE } from '../../constants/platforms'; +import { + PR_STATE_ALL, + PR_STATE_NOT_OPEN, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; import { BRANCH_STATUS_FAILED, BRANCH_STATUS_PENDING, @@ -291,11 +296,10 @@ export async function getPr(pullRequestId: number): Promise<Pr | null> { return azurePr; } - export async function findPr({ branchName, prTitle, - state = 'all', + state = PR_STATE_ALL, }: FindPRConfig): Promise<Pr | null> { let prsFiltered: Pr[] = []; try { @@ -310,11 +314,11 @@ export async function findPr({ } switch (state) { - case 'all': + case PR_STATE_ALL: // no more filter needed, we can go further... break; - case '!open': - prsFiltered = prsFiltered.filter(item => item.state !== 'open'); + case PR_STATE_NOT_OPEN: + prsFiltered = prsFiltered.filter(item => item.state !== PR_STATE_OPEN); break; default: prsFiltered = prsFiltered.filter(item => item.state === state); @@ -331,7 +335,10 @@ export async function findPr({ export async function getBranchPr(branchName: string): Promise<Pr | null> { logger.debug(`getBranchPr(${branchName})`); - const existingPr = await findPr({ branchName, state: 'open' }); + const existingPr = await findPr({ + branchName, + state: PR_STATE_OPEN, + }); return existingPr ? getPr(existingPr.pullRequestId) : null; } diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index d6f35472ab6a928c5750f1b6b29f04e834050d46..ad8d95862fb9d201f412b576d6961b9811e5b603 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -30,6 +30,7 @@ import { REPOSITORY_DISABLED, REPOSITORY_NOT_FOUND, } from '../../constants/error-messages'; +import { PR_STATE_ALL, PR_STATE_OPEN } from '../../constants/pull-requests'; import { BRANCH_STATUS_FAILED, BRANCH_STATUS_FAILURE, @@ -307,7 +308,7 @@ export async function getPr( pr.version = updatePrVersion(pr.number, pr.version); - if (pr.state === 'open') { + if (pr.state === PR_STATE_OPEN) { const mergeRes = await api.get( `./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/pull-requests/${prNo}/merge`, { useCache: !refreshCache } @@ -352,7 +353,7 @@ export async function getPr( // TODO: coverage // istanbul ignore next function matchesState(state: string, desiredState: string): boolean { - if (desiredState === 'all') { + if (desiredState === PR_STATE_ALL) { return true; } if (desiredState.startsWith('!')) { @@ -400,7 +401,7 @@ export async function getPrList(_args?: any): Promise<Pr[]> { export async function findPr({ branchName, prTitle, - state = 'all', + state = PR_STATE_ALL, refreshCache, }: FindPRConfig): Promise<Pr | null> { logger.debug(`findPr(${branchName}, "${prTitle}", "${state}")`); @@ -422,7 +423,7 @@ export async function getBranchPr( logger.debug(`getBranchPr(${branchName})`); const existingPr = await findPr({ branchName, - state: 'open', + state: PR_STATE_OPEN, }); return existingPr ? getPr(existingPr.number, refreshCache) : null; } diff --git a/lib/platform/bitbucket-server/utils.ts b/lib/platform/bitbucket-server/utils.ts index 0de65c5bd28b2d0333908f84a137413755125000..315c8961571488dd2e01dfb530ad3009237bb87e 100644 --- a/lib/platform/bitbucket-server/utils.ts +++ b/lib/platform/bitbucket-server/utils.ts @@ -2,12 +2,17 @@ import url from 'url'; import { api } from './bb-got-wrapper'; import { Pr } from '../common'; +import { + PR_STATE_CLOSED, + PR_STATE_MERGED, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; // https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp250 const prStateMapping: any = { - MERGED: 'merged', - DECLINED: 'closed', - OPEN: 'open', + MERGED: PR_STATE_MERGED, + DECLINED: PR_STATE_CLOSED, + OPEN: PR_STATE_OPEN, }; export function prInfo(pr: any): Pr { diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 5c872d33c9055868ce7798c25e151fb410994b6b..8a319aee4fe56dc43c2d58de641dc4b82670b26b 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -28,6 +28,7 @@ import { REPOSITORY_DISABLED, REPOSITORY_NOT_FOUND, } from '../../constants/error-messages'; +import { PR_STATE_ALL, PR_STATE_OPEN } from '../../constants/pull-requests'; import { PLATFORM_TYPE_BITBUCKET } from '../../constants/platforms'; import { BRANCH_STATUS_FAILED, @@ -210,7 +211,7 @@ export function getFile( // istanbul ignore next function matchesState(state: string, desiredState: string): boolean { - if (desiredState === 'all') { + if (desiredState === PR_STATE_ALL) { return true; } if (desiredState.startsWith('!')) { @@ -235,7 +236,7 @@ export async function getPrList(): Promise<Pr[]> { export async function findPr({ branchName, prTitle, - state = 'all', + state = PR_STATE_ALL, }: FindPRConfig): Promise<Pr | null> { logger.debug(`findPr(${branchName}, ${prTitle}, ${state})`); const prList = await getPrList(); @@ -256,7 +257,7 @@ export async function deleteBranch( closePr?: boolean ): Promise<void> { if (closePr) { - const pr = await findPr({ branchName, state: 'open' }); + const pr = await findPr({ branchName, state: PR_STATE_OPEN }); if (pr) { await api.post( `/2.0/repositories/${config.repository}/pullrequests/${pr.number}/decline` @@ -387,7 +388,10 @@ async function getBranchCommit(branchName: string): Promise<string | null> { // Returns the Pull Request for a branch. Null if not exists. export async function getBranchPr(branchName: string): Promise<Pr | null> { logger.debug(`getBranchPr(${branchName})`); - const existingPr = await findPr({ branchName, state: 'open' }); + const existingPr = await findPr({ + branchName, + state: PR_STATE_OPEN, + }); return existingPr ? getPr(existingPr.number) : null; } diff --git a/lib/platform/bitbucket/utils.ts b/lib/platform/bitbucket/utils.ts index 51d004006875f08c3e4bcf421408ee34723b7b7d..fa7dee409750517d8b486c26a3e815fb1826acbe 100644 --- a/lib/platform/bitbucket/utils.ts +++ b/lib/platform/bitbucket/utils.ts @@ -2,6 +2,7 @@ import url from 'url'; import { api } from './bb-got-wrapper'; import { Storage } from '../git/storage'; import { GotResponse, Pr } from '../common'; +import { PR_STATE_CLOSED } from '../../constants/pull-requests'; export interface Config { baseBranch: string; @@ -121,7 +122,7 @@ export function prInfo(pr: any): Pr { targetBranch: pr.destination.branch.name, title: pr.title, state: prStates.closed.includes(pr.state) - ? /* istanbul ignore next */ 'closed' + ? /* istanbul ignore next */ PR_STATE_CLOSED : pr.state.toLowerCase(), createdAt: pr.created_on, }; diff --git a/lib/platform/gitea/gitea-helper.ts b/lib/platform/gitea/gitea-helper.ts index c96b559a9301816913c5bca606ffa3bf5c9fe786..8614ddb67daafb2001fa5177461feb59349d35db 100644 --- a/lib/platform/gitea/gitea-helper.ts +++ b/lib/platform/gitea/gitea-helper.ts @@ -1,6 +1,7 @@ import { URLSearchParams } from 'url'; import { api, GiteaGotOptions } from './gitea-got-wrapper'; import { GotResponse } from '../common'; +import { PR_STATE_CLOSED } from '../../constants/pull-requests'; export type PRState = 'open' | 'closed' | 'all'; export type IssueState = 'open' | 'closed' | 'all'; @@ -287,7 +288,7 @@ export async function closePR( ): Promise<void> { await updatePR(repoPath, idx, { ...options, - state: 'closed', + state: PR_STATE_CLOSED, }); } diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index b6ac40abeb90a287ada645941c7dab0e7678c643..b1034da6f9c120c6dc1b87a7debda5b9aace81be 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -38,6 +38,7 @@ import { BRANCH_STATUS_SUCCESS, } from '../../constants/branch-constants'; import * as helper from './gitea-helper'; +import { PR_STATE_ALL, PR_STATE_OPEN } from '../../constants/pull-requests'; type GiteaRenovateConfig = { endpoint: string; @@ -112,7 +113,7 @@ function toRenovatePR(data: helper.PR): Pr | null { } function matchesState(actual: string, expected: string): boolean { - if (expected === 'all') { + if (expected === PR_STATE_ALL) { return true; } if (expected.startsWith('!')) { @@ -484,7 +485,7 @@ const platform: Platform = { async findPr({ branchName, prTitle: title, - state = 'all', + state = PR_STATE_ALL, }: FindPRConfig): Promise<Pr> { logger.debug(`findPr(${branchName}, ${title}, ${state})`); const prList = await platform.getPrList(); @@ -549,7 +550,7 @@ const platform: Platform = { config.prList = null; const pr = await platform.findPr({ branchName, - state: 'open', + state: PR_STATE_OPEN, }); // If a valid PR was found, return and gracefully recover from the error. Otherwise, abort and throw error. @@ -810,7 +811,7 @@ const platform: Platform = { async getBranchPr(branchName: string): Promise<Pr | null> { logger.debug(`getBranchPr(${branchName})`); - const pr = await platform.findPr({ branchName, state: 'open' }); + const pr = await platform.findPr({ branchName, state: PR_STATE_OPEN }); return pr ? platform.getPr(pr.number) : null; }, diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index de873490641c246695e532a8c308f2ff9be6b52f..84b55efbbb6148ded630e2c30e0d6943d9c61ffc 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -46,6 +46,11 @@ import { BRANCH_STATUS_PENDING, BRANCH_STATUS_SUCCESS, } from '../../constants/branch-constants'; +import { + PR_STATE_ALL, + PR_STATE_CLOSED, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; const defaultConfigFile = configFileNames[0]; @@ -759,7 +764,7 @@ async function getOpenPrs(): Promise<PrList> { for (const pr of res.data.repository.pullRequests.nodes) { // https://developer.github.com/v4/object/pullrequest/ pr.displayNumber = `Pull Request #${pr.number}`; - pr.state = 'open'; + pr.state = PR_STATE_OPEN; pr.branchName = pr.headRefName; const branchName = pr.branchName; const prNo = pr.number; @@ -882,7 +887,7 @@ export async function getPr(prNo: number): Promise<Pr | null> { } // Harmonise PR values pr.displayNumber = `Pull Request #${pr.number}`; - if (pr.state === 'open') { + if (pr.state === PR_STATE_OPEN) { pr.isModified = true; pr.branchName = pr.head ? pr.head.ref : undefined; pr.sha = pr.head ? pr.head.sha : undefined; @@ -975,7 +980,7 @@ export async function getPr(prNo: number): Promise<Pr | null> { } function matchesState(state: string, desiredState: string): boolean { - if (desiredState === 'all') { + if (desiredState === PR_STATE_ALL) { return true; } if (desiredState.startsWith('!')) { @@ -1014,7 +1019,7 @@ export async function getPrList(): Promise<Pr[]> { sha: pr.head.sha, title: pr.title, state: - pr.state === 'closed' && pr.merged_at && pr.merged_at.length + pr.state === PR_STATE_CLOSED && pr.merged_at && pr.merged_at.length ? /* istanbul ignore next */ 'merged' : pr.state, createdAt: pr.created_at, @@ -1031,7 +1036,7 @@ export async function getPrList(): Promise<Pr[]> { export async function findPr({ branchName, prTitle, - state = 'all', + state = PR_STATE_ALL, }: FindPRConfig): Promise<Pr | null> { logger.debug(`findPr(${branchName}, ${prTitle}, ${state})`); const prList = await getPrList(); @@ -1051,7 +1056,10 @@ export async function findPr({ // Returns the Pull Request for a branch. Null if not exists. export async function getBranchPr(branchName: string): Promise<Pr | null> { logger.debug(`getBranchPr(${branchName})`); - const existingPr = await findPr({ branchName, state: 'open' }); + const existingPr = await findPr({ + branchName, + state: PR_STATE_OPEN, + }); return existingPr ? getPr(existingPr.number) : null; } diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 49b159d9783357d87ae0c04ca405e7735169cdf1..4a8c3d9b63dd2fc6217e0ee82b252eb22b755b08 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -34,6 +34,7 @@ import { REPOSITORY_MIRRORED, REPOSITORY_NOT_FOUND, } from '../../constants/error-messages'; +import { PR_STATE_ALL, PR_STATE_OPEN } from '../../constants/pull-requests'; import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; import { BRANCH_STATUS_FAILED, @@ -421,13 +422,13 @@ export async function getPr(iid: number): Promise<Pr> { pr.displayNumber = `Merge Request #${pr.iid}`; pr.body = pr.description; pr.isStale = pr.diverged_commits_count > 0; - pr.state = pr.state === 'opened' ? 'open' : pr.state; + pr.state = pr.state === 'opened' ? PR_STATE_OPEN : pr.state; pr.isModified = true; if (pr.merge_status === 'cannot_be_merged') { logger.debug('pr cannot be merged'); pr.canMerge = false; pr.isConflicted = true; - } else if (pr.state === 'open') { + } else if (pr.state === PR_STATE_OPEN) { const branchStatus = await getBranchStatus(pr.branchName, []); if (branchStatus === BRANCH_STATUS_SUCCESS) { pr.canMerge = true; @@ -454,7 +455,7 @@ export async function getPr(iid: number): Promise<Pr> { } } catch (err) { logger.debug({ err }, 'Error getting PR branch'); - if (pr.state === 'open' || err.statusCode !== 404) { + if (pr.state === PR_STATE_OPEN || err.statusCode !== 404) { logger.warn({ err }, 'Error getting PR branch'); pr.isConflicted = true; } @@ -946,7 +947,7 @@ const mapPullRequests = (pr: { number: pr.iid, branchName: pr.source_branch, title: pr.title, - state: pr.state === 'opened' ? 'open' : pr.state, + state: pr.state === 'opened' ? PR_STATE_OPEN : pr.state, createdAt: pr.created_at, }); @@ -976,7 +977,7 @@ export async function getPrList(): Promise<Pr[]> { } function matchesState(state: string, desiredState: string): boolean { - if (desiredState === 'all') { + if (desiredState === PR_STATE_ALL) { return true; } if (desiredState.startsWith('!')) { @@ -988,7 +989,7 @@ function matchesState(state: string, desiredState: string): boolean { export async function findPr({ branchName, prTitle, - state = 'all', + state = PR_STATE_ALL, }: FindPRConfig): Promise<Pr> { logger.debug(`findPr(${branchName}, ${prTitle}, ${state})`); const prList = await getPrList(); diff --git a/lib/workers/branch/check-existing.ts b/lib/workers/branch/check-existing.ts index 011c23ed7cae4a19f07e211629ec0e65b5b0317f..2fbd161fad5501f645abcaf150f1597a7663e0bd 100644 --- a/lib/workers/branch/check-existing.ts +++ b/lib/workers/branch/check-existing.ts @@ -2,6 +2,10 @@ import { logger } from '../../logger'; import { platform } from '../../platform'; import { REPOSITORY_CHANGED } from '../../constants/error-messages'; import { BranchConfig } from '../common'; +import { + PR_STATE_NOT_OPEN, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; /** TODO: Proper return type */ export async function prAlreadyExisted( @@ -17,13 +21,13 @@ export async function prAlreadyExisted( const pr = await platform.findPr({ branchName: config.branchName, prTitle: config.prTitle, - state: '!open', + state: PR_STATE_NOT_OPEN, }); if (pr) { logger.debug('Found closed PR with current title'); const prDetails = await platform.getPr(pr.number); // istanbul ignore if - if (prDetails.state === 'open') { + if (prDetails.state === PR_STATE_OPEN) { logger.debug('PR reopened'); throw new Error(REPOSITORY_CHANGED); } diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index c66d4e5108626d6acf716a8c785a7b0cf81768ce..c4189c94c962421148561f3bc6cf2014feed957e 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -32,6 +32,11 @@ import { DATASOURCE_FAILURE, PLATFORM_FAILURE, } from '../../constants/error-messages'; +import { + PR_STATE_CLOSED, + PR_STATE_MERGED, + PR_STATE_OPEN, +} from '../../constants/pull-requests'; import { BRANCH_STATUS_FAILURE } from '../../constants/branch-constants'; import { exec } from '../../util/exec'; import { regEx } from '../../util/regex'; @@ -87,7 +92,7 @@ export async function processBranch( { prTitle: config.prTitle }, 'Closed PR already exists. Skipping branch.' ); - if (existingPr.state === 'closed') { + if (existingPr.state === PR_STATE_CLOSED) { const topic = `Renovate Ignore Notification`; let content; if (config.updateType === 'major') { @@ -120,7 +125,7 @@ export async function processBranch( await platform.deleteBranch(config.branchName); } } - } else if (existingPr.state === 'merged') { + } else if (existingPr.state === PR_STATE_MERGED) { logger.debug( { pr: existingPr.number }, 'Merged PR is blocking this branch' @@ -152,7 +157,7 @@ export async function processBranch( logger.debug('Checking if PR has been edited'); if (branchPr) { logger.debug('Found existing branch PR'); - if (branchPr.state !== 'open') { + if (branchPr.state !== PR_STATE_OPEN) { logger.debug( 'PR has been closed or merged since this run started - aborting' ); diff --git a/lib/workers/repository/error-config.ts b/lib/workers/repository/error-config.ts index e556f5078345d4bdb27b3677993bf01aea729acf..c4d04e37deafc101916f7d8f01549e7cb4b0d50c 100644 --- a/lib/workers/repository/error-config.ts +++ b/lib/workers/repository/error-config.ts @@ -1,6 +1,7 @@ import { logger } from '../../logger'; import { platform } from '../../platform'; import { RenovateConfig } from '../../config'; +import { PR_STATE_OPEN } from '../../constants/pull-requests'; export async function raiseConfigWarningIssue( config: RenovateConfig, @@ -16,7 +17,7 @@ export async function raiseConfigWarningIssue( body += `Message: \`${error.validationMessage}\`\n`; } const pr = await platform.getBranchPr(config.onboardingBranch); - if (pr && pr.state && pr.state.startsWith('open')) { + if (pr && pr.state && pr.state === PR_STATE_OPEN) { logger.debug('Updating onboarding PR with config error notice'); body = `## Action Required: Fix Renovate Configuration\n\n${body}`; body += `\n\nOnce you have resolved this problem (in this onboarding branch), Renovate will return to providing you with a preview of your repository's configuration.`; diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index eb50c9e0d4b5e1dc597ca89a091fbbedfafd5b9e..b4b0e34768ddc6c41609a9088a4f15fcaeb92481 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -1,6 +1,7 @@ import { logger } from '../../../logger'; import { platform } from '../../../platform'; import { RenovateConfig } from '../../../config'; +import { PR_STATE_OPEN } from '../../../constants/pull-requests'; import { REPOSITORY_CHANGED } from '../../../constants/error-messages'; async function cleanUpBranches( @@ -11,7 +12,7 @@ async function cleanUpBranches( try { const pr = await platform.findPr({ branchName, - state: 'open', + state: PR_STATE_OPEN, }); const branchPr = await platform.getBranchPr(branchName); const skipAutoclose = branchPr && branchPr.isModified; diff --git a/lib/workers/repository/finalise/validate.ts b/lib/workers/repository/finalise/validate.ts index 7ce1441c9836e988b2e189c93dfecff22b03c397..51d5792653c7203555b716fd1db24e25d3d3df76 100644 --- a/lib/workers/repository/finalise/validate.ts +++ b/lib/workers/repository/finalise/validate.ts @@ -4,6 +4,7 @@ import { migrateAndValidate } from '../../../config/migrate-validate'; import { configFileNames } from '../../../config/app-strings'; import { platform, Pr } from '../../../platform'; import { RenovateConfig } from '../../../config'; +import { PR_STATE_OPEN } from '../../../constants/pull-requests'; import { REPOSITORY_CHANGED } from '../../../constants/error-messages'; import { BRANCH_STATUS_FAILURE, @@ -12,7 +13,7 @@ import { async function getRenovatePrs(branchPrefix: string): Promise<Pr[]> { return (await platform.getPrList()) - .filter(pr => pr.state === 'open') + .filter(pr => pr.state === PR_STATE_OPEN) .filter(pr => pr.branchName && !pr.branchName.startsWith(branchPrefix)) .filter(pr => new RegExp('renovate', 'i').test(pr.title)); } diff --git a/lib/workers/repository/master-issue.ts b/lib/workers/repository/master-issue.ts index 7d24177db09eef1b63de596728289096b0ddaed1..a1fc371d0fceabbabe9650d8102bc201b42b98f5 100644 --- a/lib/workers/repository/master-issue.ts +++ b/lib/workers/repository/master-issue.ts @@ -2,6 +2,7 @@ import { logger } from '../../logger'; import { platform, Pr } from '../../platform'; import { BranchConfig } from '../common'; import { RenovateConfig } from '../../config'; +import { PR_STATE_NOT_OPEN } from '../../constants/pull-requests'; function getListItem(branch: BranchConfig, type: string, pr?: Pr): string { let item = ' - [ ] '; @@ -182,7 +183,7 @@ export async function ensureMasterIssue( const pr = await platform.findPr({ branchName: branch.branchName, prTitle: branch.prTitle, - state: '!open', + state: PR_STATE_NOT_OPEN, }); issueBody += getListItem(branch, 'recreate', pr); } diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts index 0f420ea2e10dc8a6fdf4be2ac04da8bf53bada32..8cc6d85965eceaac554b3ff8bd081707c96347f4 100644 --- a/lib/workers/repository/onboarding/branch/check.ts +++ b/lib/workers/repository/onboarding/branch/check.ts @@ -3,6 +3,7 @@ import { platform } from '../../../../platform'; import { configFileNames } from '../../../../config/app-strings'; import { RenovateConfig } from '../../../../config'; import { REPOSITORY_DISABLED } from '../../../../constants/error-messages'; +import { PR_STATE_NOT_OPEN } from '../../../../constants/pull-requests'; const findFile = async (fileName: string): Promise<boolean> => { logger.debug(`findFile(${fileName})`); @@ -38,7 +39,7 @@ const closedPrExists = (config: RenovateConfig): Promise<Pr> => platform.findPr({ branchName: config.onboardingBranch, prTitle: config.onboardingPrTitle, - state: '!open', + state: PR_STATE_NOT_OPEN, }); export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => { diff --git a/test/platform/bitbucket-server/index.spec.ts b/test/platform/bitbucket-server/index.spec.ts index 03bae0122044fdeac85340f78339c4486b23f8f9..c3a48b1b74cfa336d07a63a304162c97df0b9a9d 100644 --- a/test/platform/bitbucket-server/index.spec.ts +++ b/test/platform/bitbucket-server/index.spec.ts @@ -6,6 +6,10 @@ import { REPOSITORY_DISABLED, REPOSITORY_NOT_FOUND, } from '../../../lib/constants/error-messages'; +import { + PR_STATE_CLOSED, + PR_STATE_OPEN, +} from '../../../lib/constants/pull-requests'; import { BRANCH_STATUS_FAILED, BRANCH_STATUS_FAILURE, @@ -499,7 +503,7 @@ describe('platform/bitbucket-server', () => { await bitbucket.findPr({ branchName: 'userName1/pullRequest5', prTitle: 'title', - state: 'open', + state: PR_STATE_OPEN, }) ).toMatchSnapshot(); expect(api.get.mock.calls).toMatchSnapshot(); @@ -511,7 +515,7 @@ describe('platform/bitbucket-server', () => { await bitbucket.findPr({ branchName: 'userName1/pullRequest5', prTitle: 'title', - state: 'closed', + state: PR_STATE_CLOSED, }) ).toBeUndefined(); expect(api.get.mock.calls).toMatchSnapshot(); diff --git a/test/platform/gitea/gitea-helper.spec.ts b/test/platform/gitea/gitea-helper.spec.ts index 5ff1cf830a0fbce196e93b15d34e3497976c23b3..c1848f021948a0d3897cc9a48ae853f96a643dc6 100644 --- a/test/platform/gitea/gitea-helper.spec.ts +++ b/test/platform/gitea/gitea-helper.spec.ts @@ -7,6 +7,7 @@ import { } from '../../../lib/platform/gitea/gitea-got-wrapper'; import * as ght from '../../../lib/platform/gitea/gitea-helper'; import { PRSearchParams } from '../../../lib/platform/gitea/gitea-helper'; +import { PR_STATE_CLOSED } from '../../../lib/constants/pull-requests'; describe('platform/gitea/gitea-helper', () => { let helper: typeof import('../../../lib/platform/gitea/gitea-helper'); @@ -409,7 +410,7 @@ describe('platform/gitea/gitea-helper', () => { ); const res = await helper.updatePR(mockRepo.full_name, mockPR.number, { - state: 'closed', + state: PR_STATE_CLOSED, title: 'new-title', body: 'new-body', assignees: [otherMockUser.username], diff --git a/test/platform/gitlab/index.spec.ts b/test/platform/gitlab/index.spec.ts index 3f24ec90cf4b10b9fb3cf44d370fdbb234241437..a0b2afc1e0ad7b245ad051b31f5d0cc034d654bf 100644 --- a/test/platform/gitlab/index.spec.ts +++ b/test/platform/gitlab/index.spec.ts @@ -6,6 +6,10 @@ import { REPOSITORY_EMPTY, REPOSITORY_MIRRORED, } from '../../../lib/constants/error-messages'; +import { + PR_STATE_NOT_OPEN, + PR_STATE_OPEN, +} from '../../../lib/constants/pull-requests'; import { BRANCH_STATUS_FAILED, BRANCH_STATUS_FAILURE, @@ -886,7 +890,7 @@ describe('platform/gitlab', () => { ); const res = await gitlab.findPr({ branchName: 'branch-a', - state: '!open', + state: PR_STATE_NOT_OPEN, }); expect(res).toBeDefined(); }); @@ -907,7 +911,7 @@ describe('platform/gitlab', () => { const res = await gitlab.findPr({ branchName: 'branch-a', prTitle: 'branch a pr', - state: 'open', + state: PR_STATE_OPEN, }); expect(res).toBeDefined(); }); diff --git a/test/workers/branch/check-existing.spec.ts b/test/workers/branch/check-existing.spec.ts index 61ac20beea56d010e1a5c22b47facf4d9dacd2ff..7604dc621868efa70e3509c08c834f0e5167cc6e 100644 --- a/test/workers/branch/check-existing.spec.ts +++ b/test/workers/branch/check-existing.spec.ts @@ -1,6 +1,7 @@ import { prAlreadyExisted } from '../../../lib/workers/branch/check-existing'; import { defaultConfig, platform, partial } from '../../util'; import { BranchConfig } from '../../../lib/workers/common'; +import { PR_STATE_CLOSED } from '../../../lib/constants/pull-requests'; describe('workers/branch/check-existing', () => { describe('prAlreadyExisted', () => { @@ -27,7 +28,7 @@ describe('workers/branch/check-existing', () => { platform.findPr.mockResolvedValueOnce({ number: 12 } as never); platform.getPr.mockResolvedValueOnce({ number: 12, - state: 'closed', + state: PR_STATE_CLOSED, } as never); expect(await prAlreadyExisted(config)).toEqual({ number: 12 }); expect(platform.findPr).toHaveBeenCalledTimes(1); diff --git a/test/workers/branch/index.spec.ts b/test/workers/branch/index.spec.ts index 11c56e81b3c4fc90f9e2e0a987d82d9d8fd1679f..e04271af4ab08913ba66604d01054a89e5006eec 100644 --- a/test/workers/branch/index.spec.ts +++ b/test/workers/branch/index.spec.ts @@ -16,6 +16,11 @@ import { MANAGER_LOCKFILE_ERROR, REPOSITORY_CHANGED, } from '../../../lib/constants/error-messages'; +import { + PR_STATE_CLOSED, + PR_STATE_MERGED, + PR_STATE_OPEN, +} from '../../../lib/constants/pull-requests'; import { BRANCH_STATUS_PENDING } from '../../../lib/constants/branch-constants'; import { StatusResult } from '../../../lib/platform/git/storage'; @@ -108,7 +113,7 @@ describe('workers/branch', () => { config.updateNotScheduled = true; platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'open', + state: PR_STATE_OPEN, isModified: false, } as never); await branchWorker.processBranch(config); @@ -119,7 +124,7 @@ describe('workers/branch', () => { config.updateType = 'major'; checkExisting.prAlreadyExisted.mockResolvedValueOnce({ number: 13, - state: 'closed', + state: PR_STATE_CLOSED, } as never); await branchWorker.processBranch(config); expect(parent.getParentBranch).toHaveBeenCalledTimes(0); @@ -130,7 +135,7 @@ describe('workers/branch', () => { config.updateType = 'digest'; checkExisting.prAlreadyExisted.mockResolvedValueOnce({ number: 13, - state: 'closed', + state: PR_STATE_CLOSED, }); await branchWorker.processBranch(config); expect(parent.getParentBranch).toHaveBeenCalledTimes(0); @@ -140,7 +145,7 @@ describe('workers/branch', () => { platform.branchExists.mockResolvedValueOnce(true); checkExisting.prAlreadyExisted.mockResolvedValueOnce({ number: 13, - state: 'closed', + state: PR_STATE_CLOSED, }); await branchWorker.processBranch(config); expect(parent.getParentBranch).toHaveBeenCalledTimes(0); @@ -150,7 +155,7 @@ describe('workers/branch', () => { platform.branchExists.mockResolvedValueOnce(true); checkExisting.prAlreadyExisted.mockResolvedValueOnce({ number: 13, - state: 'merged', + state: PR_STATE_MERGED, }); await branchWorker.processBranch(config); expect(parent.getParentBranch).toHaveBeenCalledTimes(0); @@ -159,7 +164,7 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'merged', + state: PR_STATE_MERGED, isModified: true, } as never); await expect(branchWorker.processBranch(config)).rejects.toThrow( @@ -170,7 +175,7 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'open', + state: PR_STATE_OPEN, isModified: true, labels: ['rebase'], } as never); @@ -181,7 +186,7 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'open', + state: PR_STATE_OPEN, isModified: true, } as never); const res = await branchWorker.processBranch(config); @@ -191,7 +196,7 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'open', + state: PR_STATE_OPEN, isModified: false, targetBranch: 'v6', } as never); @@ -477,7 +482,9 @@ describe('workers/branch', () => { it('closed pr (dry run)', async () => { platform.branchExists.mockResolvedValueOnce(true); - checkExisting.prAlreadyExisted.mockResolvedValueOnce({ state: 'closed' }); + checkExisting.prAlreadyExisted.mockResolvedValueOnce({ + state: PR_STATE_CLOSED, + }); expect( await branchWorker.processBranch({ ...config, dryRun: true }) ).toEqual('already-existed'); @@ -486,7 +493,7 @@ describe('workers/branch', () => { it('branch pr no rebase (dry run)', async () => { platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ - state: 'open', + state: PR_STATE_OPEN, isModified: true, } as never); expect( @@ -506,7 +513,7 @@ describe('workers/branch', () => { platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ title: 'rebase!', - state: 'open', + state: PR_STATE_OPEN, body: `- [x] <!-- rebase-check -->`, isModified: true, } as never); @@ -537,7 +544,7 @@ describe('workers/branch', () => { platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ title: 'rebase!', - state: 'open', + state: PR_STATE_OPEN, body: `- [x] <!-- rebase-check -->`, isModified: true, } as never); @@ -566,7 +573,7 @@ describe('workers/branch', () => { platform.branchExists.mockResolvedValueOnce(true); platform.getBranchPr.mockResolvedValueOnce({ title: 'rebase!', - state: 'open', + state: PR_STATE_OPEN, body: `- [x] <!-- rebase-check -->`, isModified: true, } as never); diff --git a/test/workers/branch/parent.spec.ts b/test/workers/branch/parent.spec.ts index 91d5a7cb85a9dab1c8ef6518851b45f60b3df0e0..4add641edaf5c496b712817b95859a0f44b34ba3 100644 --- a/test/workers/branch/parent.spec.ts +++ b/test/workers/branch/parent.spec.ts @@ -2,10 +2,15 @@ import { getParentBranch } from '../../../lib/workers/branch/parent'; import { platform } from '../../util'; import { RenovateConfig } from '../../../lib/config'; import { Pr } from '../../../lib/platform'; +import { PR_STATE_OPEN } from '../../../lib/constants/pull-requests'; describe('workers/branch/parent', () => { describe('getParentBranch(config)', () => { - const pr: Pr = { branchName: 'master', state: 'open', title: 'any' }; + const pr: Pr = { + branchName: 'master', + state: PR_STATE_OPEN, + title: 'any', + }; let config: RenovateConfig; beforeEach(() => { config = { diff --git a/test/workers/repository/error-config.spec.ts b/test/workers/repository/error-config.spec.ts index caae622188625ee4ec514600181a91bfb27ab71b..92391e2e6f948318fd0e6f072c2b902bc1524764 100644 --- a/test/workers/repository/error-config.spec.ts +++ b/test/workers/repository/error-config.spec.ts @@ -3,6 +3,7 @@ import { CONFIG_VALIDATION } from '../../../lib/constants/error-messages'; import { raiseConfigWarningIssue } from '../../../lib/workers/repository/error-config'; import { RenovateConfig, getConfig, platform } from '../../util'; import { Pr } from '../../../lib/platform'; +import { PR_STATE_OPEN } from '../../../lib/constants/pull-requests'; jest.mock('../../../lib/platform'); @@ -40,7 +41,7 @@ describe('workers/repository/error-config', () => { platform.getBranchPr.mockResolvedValue({ ...mock<Pr>(), number: 1, - state: 'open', + state: PR_STATE_OPEN, }); const res = await raiseConfigWarningIssue(config, error); expect(res).toBeUndefined(); @@ -52,7 +53,7 @@ describe('workers/repository/error-config', () => { platform.getBranchPr.mockResolvedValue({ ...mock<Pr>(), number: 1, - state: 'open', + state: PR_STATE_OPEN, }); const res = await raiseConfigWarningIssue( { ...config, dryRun: true }, diff --git a/test/workers/repository/finalise/validate.spec.ts b/test/workers/repository/finalise/validate.spec.ts index 53a4e28328e1560170360d08311708bfb71cfb64..bbc3144572f27e288b6cf99ce397a193653e5d31 100644 --- a/test/workers/repository/finalise/validate.spec.ts +++ b/test/workers/repository/finalise/validate.spec.ts @@ -1,5 +1,6 @@ import * as validate from '../../../../lib/workers/repository/finalise/validate'; import { platform } from '../../../util'; +import { PR_STATE_OPEN } from '../../../../lib/constants/pull-requests'; import { BRANCH_STATUS_FAILURE, BRANCH_STATUS_SUCCESS, @@ -17,7 +18,7 @@ describe('workers/repository/validate', () => { it('catches error', async () => { platform.getPrList.mockResolvedValueOnce([ { - state: 'open', + state: PR_STATE_OPEN, branchName: 'some/branch', title: 'Update Renovate', }, @@ -30,7 +31,7 @@ describe('workers/repository/validate', () => { it('returns if no matching files', async () => { platform.getPrList.mockResolvedValueOnce([ { - state: 'open', + state: PR_STATE_OPEN, branchName: 'some/branch', title: 'Update Renovate', }, @@ -44,7 +45,7 @@ describe('workers/repository/validate', () => { it('validates failures if cannot parse', async () => { platform.getPrList.mockResolvedValueOnce([ { - state: 'open', + state: PR_STATE_OPEN, branchName: 'some/branch', title: 'Update Renovate', }, @@ -62,7 +63,7 @@ describe('workers/repository/validate', () => { it('validates failures if config validation fails', async () => { platform.getPrList.mockResolvedValueOnce([ { - state: 'open', + state: PR_STATE_OPEN, branchName: 'some/branch', title: 'Update Renovate', }, @@ -80,7 +81,7 @@ describe('workers/repository/validate', () => { it('validates successfully', async () => { platform.getPrList.mockResolvedValueOnce([ { - state: 'open', + state: PR_STATE_OPEN, branchName: 'some/branch', title: 'Update Renovate', }, diff --git a/test/workers/repository/master-issue.spec.ts b/test/workers/repository/master-issue.spec.ts index 3cabeadfc1b2fbf6e2fadee3dbd9be4604261a4e..a292bd4129084a02bc118c976410e7e8d2b938b6 100644 --- a/test/workers/repository/master-issue.spec.ts +++ b/test/workers/repository/master-issue.spec.ts @@ -5,6 +5,7 @@ import * as masterIssue from '../../../lib/workers/repository/master-issue'; import { RenovateConfig, getConfig, platform } from '../../util'; import { BranchConfig, BranchUpgradeConfig } from '../../../lib/workers/common'; import { Pr } from '../../../lib/platform'; +import { PR_STATE_NOT_OPEN } from '../../../lib/constants/pull-requests'; import { PLATFORM_TYPE_GITHUB } from '../../../lib/constants/platforms'; type PrUpgrade = BranchUpgradeConfig; @@ -354,10 +355,10 @@ describe('workers/repository/master-issue', () => { expect(platform.findPr).toHaveBeenCalledTimes(2); expect(platform.findPr.mock.calls[0][0].branchName).toBe('branchName1'); expect(platform.findPr.mock.calls[0][0].prTitle).toBe('pr1'); - expect(platform.findPr.mock.calls[0][0].state).toBe('!open'); + expect(platform.findPr.mock.calls[0][0].state).toBe(PR_STATE_NOT_OPEN); expect(platform.findPr.mock.calls[1][0].branchName).toBe('branchName2'); expect(platform.findPr.mock.calls[1][0].prTitle).toBe('pr2'); - expect(platform.findPr.mock.calls[1][0].state).toBe('!open'); + expect(platform.findPr.mock.calls[1][0].state).toBe(PR_STATE_NOT_OPEN); // same with dry run await dryRun(branches, platform, 0, 0, 0, 2); diff --git a/test/workers/repository/onboarding/branch/index.spec.ts b/test/workers/repository/onboarding/branch/index.spec.ts index 72ca8c9abea439b53fdc7f6e2d6ede8ac2ad22e4..2482dc1c70b2dd765544b4f6581809ebace56c0b 100644 --- a/test/workers/repository/onboarding/branch/index.spec.ts +++ b/test/workers/repository/onboarding/branch/index.spec.ts @@ -3,6 +3,7 @@ import { RenovateConfig, platform, getConfig } from '../../../../util'; import { checkOnboardingBranch } from '../../../../../lib/workers/repository/onboarding/branch'; import { Pr } from '../../../../../lib/platform'; import * as _rebase from '../../../../../lib/workers/repository/onboarding/branch/rebase'; +import { PR_STATE_OPEN } from '../../../../../lib/constants/pull-requests'; const rebase: any = _rebase; @@ -73,7 +74,11 @@ describe('workers/repository/onboarding/branch', () => { config.requireConfig = true; platform.findPr.mockResolvedValue(mock<Pr>()); platform.getPrList.mockResolvedValueOnce([ - { ...mock<Pr>(), branchName: 'renovate/something', state: 'open' }, + { + ...mock<Pr>(), + branchName: 'renovate/something', + state: PR_STATE_OPEN, + }, ]); await expect(checkOnboardingBranch(config)).rejects.toThrow(); });