diff --git a/lib/platform/bitbucket-server/index.js b/lib/platform/bitbucket-server/index.js index 0bbed8dd66555aa2d89d6f5120ff32196bea6e9c..6584931ed0ca3817364844d1c9873cf61f1c8a72 100644 --- a/lib/platform/bitbucket-server/index.js +++ b/lib/platform/bitbucket-server/index.js @@ -69,11 +69,11 @@ async function getRepos(token, endpoint) { } hostRules.update({ ...opts, platform, default: true }); try { - const projects = await utils.accumulateValues('/rest/api/1.0/projects'); + const projects = await utils.accumulateValues('./rest/api/1.0/projects'); const repos = await Promise.all( projects.map(({ key }) => // TODO: can we filter this by permission=REPO_WRITE? - utils.accumulateValues(`/rest/api/1.0/projects/${key}/repos`) + utils.accumulateValues(`./rest/api/1.0/projects/${key}/repos`) ) ); const result = _.flatten(repos).map( @@ -142,7 +142,7 @@ async function initRepo({ repository, endpoint, gitFs, localDir }) { try { const info = (await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }` )).body; @@ -152,7 +152,7 @@ async function initRepo({ repository, endpoint, gitFs, localDir }) { config.owner = info.project.key; logger.debug(`${repository} owner = ${config.owner}`); config.defaultBranch = (await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/branches/default` )).body.displayId; @@ -259,7 +259,7 @@ async function deleteBranch(branchName, closePr = false) { const pr = await getBranchPr(branchName); if (pr) { await api.post( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${pr.number}/decline?version=${pr.version + 1}` ); @@ -303,7 +303,7 @@ async function getBranchStatus(branchName, requiredStatusChecks) { logger.debug({ prForBranch }, 'PRFORBRANCH'); const res = await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prForBranch.number}/merge` ); @@ -325,7 +325,7 @@ async function getBranchStatusCheck(branchName, context) { return null; } const res = await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prForBranch.number}/merge` ); @@ -391,7 +391,7 @@ async function addReviewers(iid, reviewers) { logger.debug(`Adding reviewers ${reviewers} to #${iid}`); for (const name of reviewers) { await api.post( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${iid}/participants`, { body: { user: { name }, role: 'REVIEWER' } } @@ -426,7 +426,7 @@ async function getPrList() { logger.debug(`getPrList()`); if (!config.prList) { const values = await utils.accumulateValues( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests?state=OPEN` ); @@ -498,7 +498,7 @@ async function createPr( let prInfoRes; try { prInfoRes = await api.post( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests`, { body } @@ -541,7 +541,7 @@ async function getPr(prNo) { return null; } const res = await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}` ); @@ -553,7 +553,7 @@ async function getPr(prNo) { if (pr.state === 'open') { const mergeRes = await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}/merge` ); @@ -577,13 +577,13 @@ async function updatePr(prNo, title, description) { logger.debug(`updatePr(${prNo}, title=${title})`); const { version } = (await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}` )).body; await api.put( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}`, { body: { title, description, version } } @@ -595,12 +595,12 @@ async function mergePr(prNo) { // TODO: Needs implementation // Used for "automerge" feature const { version } = (await api.get( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}` )).body; await api.post( - `/rest/api/1.0/projects/${config.projectKey}/repos/${ + `./rest/api/1.0/projects/${config.projectKey}/repos/${ config.repositorySlug }/pull-requests/${prNo}/merge?version=${version}` ); diff --git a/test/_fixtures/bitbucket-server/responses.js b/test/_fixtures/bitbucket-server/responses.js index 47b21ec3c5f0822e8dda7b65b82753a4454af08b..392d89e889d0ffbdc1d4c26723a9ebc430eb5354 100644 --- a/test/_fixtures/bitbucket-server/responses.js +++ b/test/_fixtures/bitbucket-server/responses.js @@ -464,4 +464,5 @@ function generateServerResponses(endpoint) { module.exports = { 'endpoint with no path': generateServerResponses('https://stash.renovatebot.com'), + 'endpoint with path': generateServerResponses('https://stash.renovatebot.com/vcs'), }; diff --git a/test/platform/bitbucket-server/__snapshots__/index.spec.js.snap b/test/platform/bitbucket-server/__snapshots__/index.spec.js.snap index 7d9a83bc64179bcd080b7e74596cc55a9a1ce615..65655872533898beb45c75e248127ecdf5b85f49 100644 --- a/test/platform/bitbucket-server/__snapshots__/index.spec.js.snap +++ b/test/platform/bitbucket-server/__snapshots__/index.spec.js.snap @@ -3,7 +3,7 @@ exports[`platform/bitbucket-server endpoint with no path addReviewers sends the reviewer name as a reviewer 1`] = ` Array [ Array [ - "/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/participants", + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/participants", Object { "body": Object { "role": "REVIEWER", @@ -19,7 +19,7 @@ Array [ exports[`platform/bitbucket-server endpoint with no path createPr() posts PR 1`] = ` Array [ Array [ - "/rest/api/1.0/projects/SOME/repos/repo/pull-requests", + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests", Object { "body": Object { "description": "body", @@ -66,7 +66,7 @@ Object { exports[`platform/bitbucket-server endpoint with no path mergePr() posts Merge 1`] = ` Array [ Array [ - "/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1", + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1", ], ] `; @@ -74,10 +74,10 @@ Array [ exports[`platform/bitbucket-server endpoint with no path setBaseBranch() updates file list 1`] = ` Array [ Array [ - "/rest/api/1.0/projects/SOME/repos/repo", + "./rest/api/1.0/projects/SOME/repos/repo", ], Array [ - "/rest/api/1.0/projects/SOME/repos/repo/branches/default", + "./rest/api/1.0/projects/SOME/repos/repo/branches/default", ], ] `; @@ -85,7 +85,104 @@ Array [ exports[`platform/bitbucket-server endpoint with no path updatePr() puts PR 1`] = ` Array [ Array [ - "/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5", + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5", + Object { + "body": Object { + "description": "body", + "title": "title", + "version": 1, + }, + }, + ], +] +`; + +exports[`platform/bitbucket-server endpoint with path addReviewers sends the reviewer name as a reviewer 1`] = ` +Array [ + Array [ + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/participants", + Object { + "body": Object { + "role": "REVIEWER", + "user": Object { + "name": "name", + }, + }, + }, + ], +] +`; + +exports[`platform/bitbucket-server endpoint with path createPr() posts PR 1`] = ` +Array [ + Array [ + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests", + Object { + "body": Object { + "description": "body", + "fromRef": Object { + "id": "refs/heads/branch", + }, + "title": "title", + "toRef": Object { + "id": "refs/heads/master", + }, + }, + }, + ], +] +`; + +exports[`platform/bitbucket-server endpoint with path getPr() gets a PR 1`] = ` +Object { + "body": "* Line 1 +* Line 2", + "branchName": "userName1/pullRequest5", + "canMerge": false, + "canRebase": true, + "createdAt": undefined, + "displayNumber": "Pull Request #5", + "isConflicted": false, + "number": 5, + "state": "open", + "title": "title", + "version": 1, +} +`; + +exports[`platform/bitbucket-server endpoint with path getPrBody() returns diff files 1`] = `"**foo**bartext"`; + +exports[`platform/bitbucket-server endpoint with path initRepo() works 1`] = ` +Object { + "isFork": false, + "privateRepo": undefined, + "repoFullName": "repo", +} +`; + +exports[`platform/bitbucket-server endpoint with path mergePr() posts Merge 1`] = ` +Array [ + Array [ + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1", + ], +] +`; + +exports[`platform/bitbucket-server endpoint with path setBaseBranch() updates file list 1`] = ` +Array [ + Array [ + "./rest/api/1.0/projects/SOME/repos/repo", + ], + Array [ + "./rest/api/1.0/projects/SOME/repos/repo/branches/default", + ], +] +`; + +exports[`platform/bitbucket-server endpoint with path updatePr() puts PR 1`] = ` +Array [ + Array [ + "./rest/api/1.0/projects/SOME/repos/repo/pull-requests/5", Object { "body": Object { "description": "body",