diff --git a/lib/platform/bitbucket-server/index.js b/lib/platform/bitbucket-server/index.js index 6584931ed0ca3817364844d1c9873cf61f1c8a72..f1592af5173463b35649561225465b57b6e41cf8 100644 --- a/lib/platform/bitbucket-server/index.js +++ b/lib/platform/bitbucket-server/index.js @@ -428,7 +428,7 @@ async function getPrList() { const values = await utils.accumulateValues( `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug - }/pull-requests?state=OPEN` + }/pull-requests?state=ALL&limit=100` ); config.prList = values.map(utils.prInfo); @@ -441,30 +441,29 @@ async function getPrList() { // TODO: coverage // istanbul ignore next -const isRelevantPr = (branchName, prTitle, states) => p => +function matchesState(state, desiredState) { + if (desiredState === 'all') { + return true; + } + if (desiredState[0] === '!') { + return state !== desiredState.substring(1); + } + return state === desiredState; +} + +// TODO: coverage +// istanbul ignore next +const isRelevantPr = (branchName, prTitle, state) => p => p.branchName === branchName && (!prTitle || p.title === prTitle) && - states.includes(p.state); + matchesState(p.state, state); // TODO: coverage // istanbul ignore next -async function findPr( - branchName, - prTitle, - inputStates = utils.prStates.all, - refreshCache -) { - logger.debug(`findPr(${branchName})`); - let states; - // istanbul ignore if - if (inputStates === '!open') { - states = utils.prStates.notOpen; - } else { - states = inputStates; - } - logger.debug(`findPr(${branchName}, "${prTitle}", "${states}")`); +async function findPr(branchName, prTitle, state = 'all', refreshCache) { + logger.debug(`findPr(${branchName}, "${prTitle}", "${state}")`); const prList = await getPrList({ refreshCache }); - const pr = prList.find(isRelevantPr(branchName, prTitle, states)); + const pr = prList.find(isRelevantPr(branchName, prTitle, state)); if (pr) { logger.debug(`Found PR #${pr.number}`); } else { diff --git a/lib/platform/bitbucket-server/utils.js b/lib/platform/bitbucket-server/utils.js index 13d3c9ed55becaf1588a2d6acf127190711dcd11..2f035ace33436d4ae2002a8e1c5cb282baef8756 100644 --- a/lib/platform/bitbucket-server/utils.js +++ b/lib/platform/bitbucket-server/utils.js @@ -2,13 +2,11 @@ const url = require('url'); const api = require('./bb-got-wrapper'); -// TODO: Are the below states correct? -const prStates = { - open: ['OPEN'], - notOpen: ['MERGED', 'DECLINED', 'SUPERSEDED'], - merged: ['MERGED'], - closed: ['DECLINED', 'SUPERSEDED'], - all: ['OPEN', 'MERGED', 'DECLINED', 'SUPERSEDED'], +// https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp250 +const prStateMapping = { + MERGED: 'merged', + DECLINED: 'closed', + OPEN: 'open', }; const prInfo = pr => ({ @@ -17,7 +15,7 @@ const prInfo = pr => ({ body: pr.description, branchName: pr.fromRef.displayId, title: pr.title, - state: prStates.closed.includes(pr.state) ? 'closed' : pr.state.toLowerCase(), + state: prStateMapping[pr.state], createdAt: pr.created_on, }); @@ -53,7 +51,6 @@ const accumulateValues = async (reqUrl, method = 'get', options, limit) => { }; module.exports = { - prStates, // buildStates, prInfo, accumulateValues,