diff --git a/lib/workers/pr/changelog/__snapshots__/index.spec.ts.snap b/lib/workers/pr/changelog/__snapshots__/index.spec.ts.snap index 426d781813623a26045966528fa1d8c66b814e88..4b8e0f9f1e38b944c036a561760c5b08795cbbf6 100644 --- a/lib/workers/pr/changelog/__snapshots__/index.spec.ts.snap +++ b/lib/workers/pr/changelog/__snapshots__/index.spec.ts.snap @@ -153,57 +153,6 @@ Object { } `; -exports[`workers/pr/changelog getChangeLogJSON supports github.com and github enterprise changelog 1`] = ` -Object { - "hasReleaseNotes": true, - "project": Object { - "apiBaseUrl": "https://github-enterprise.example.com/", - "baseUrl": "https://github-enterprise.example.com/", - "depName": "renovate", - "github": "chalk/chalk", - "repository": "https://github-enterprise.example.com/chalk/chalk", - }, - "versions": Array [ - Object { - "changes": Array [], - "compare": Object {}, - "date": undefined, - "releaseNotes": null, - "version": "2.5.2", - }, - Object { - "changes": Array [], - "compare": Object {}, - "date": "2017-12-24T03:20:46.238Z", - "releaseNotes": null, - "version": "2.4.2", - }, - Object { - "changes": Array [], - "compare": Object { - "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", - }, - "date": "2017-10-24T03:20:46.238Z", - "releaseNotes": Object { - "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", - }, - "version": "2.3.0", - }, - Object { - "changes": Array [], - "compare": Object { - "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", - }, - "date": undefined, - "releaseNotes": Object { - "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", - }, - "version": "2.2.2", - }, - ], -} -`; - exports[`workers/pr/changelog getChangeLogJSON supports node engines 1`] = ` Object { "hasReleaseNotes": true, diff --git a/lib/workers/pr/changelog/index.spec.ts b/lib/workers/pr/changelog/index.spec.ts index 999df65afd4c44954cc3464a0657939e6286ad75..aa5c65db5eed619e86ca537e58a33d5e8ba10ae0 100644 --- a/lib/workers/pr/changelog/index.spec.ts +++ b/lib/workers/pr/changelog/index.spec.ts @@ -175,19 +175,6 @@ describe('workers/pr/changelog', () => { endpoint: 'https://github-enterprise.example.com/', }) ).toMatchSnapshot(); - expect(ghGot).toHaveBeenNthCalledWith( - 1, - 'https://github.com/repos/chalk/chalk/tags?per_page=100', - { paginate: true } - ); - expect(ghGot).toHaveBeenNthCalledWith( - 2, - 'https://api.github.com/repos/chalk/chalk/contents/' - ); - expect(ghGot).toHaveBeenNthCalledWith( - 3, - 'https://api.github.com/repos/chalk/chalk/releases?per_page=100' - ); }); it('supports github enterprise and github enterprise changelog', async () => { hostRules.add({ @@ -203,46 +190,6 @@ describe('workers/pr/changelog', () => { endpoint: 'https://github-enterprise.example.com/', }) ).toMatchSnapshot(); - expect(ghGot).toHaveBeenNthCalledWith( - 1, - 'https://github-enterprise.example.com/repos/chalk/chalk/tags?per_page=100', - { paginate: true } - ); - expect(ghGot).toHaveBeenNthCalledWith( - 2, - 'https://github-enterprise.example.com/repos/chalk/chalk/contents/' - ); - expect(ghGot).toHaveBeenNthCalledWith( - 3, - 'https://github-enterprise.example.com/repos/chalk/chalk/releases?per_page=100' - ); - }); - - it('supports github.com and github enterprise changelog', async () => { - hostRules.add({ - hostType: PLATFORM_TYPE_GITHUB, - baseUrl: 'https://github-enterprise.example.com/', - token: 'abc', - }); - expect( - await getChangeLogJSON({ - ...upgrade, - sourceUrl: 'https://github-enterprise.example.com/chalk/chalk', - }) - ).toMatchSnapshot(); - expect(ghGot).toHaveBeenNthCalledWith( - 1, - 'https://github-enterprise.example.com/repos/chalk/chalk/tags?per_page=100', - { paginate: true } - ); - expect(ghGot).toHaveBeenNthCalledWith( - 2, - 'https://github-enterprise.example.com/repos/chalk/chalk/contents/' - ); - expect(ghGot).toHaveBeenNthCalledWith( - 3, - 'https://github-enterprise.example.com/repos/chalk/chalk/releases?per_page=100' - ); }); }); }); diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts index e204ea078cb9a5461d4c9f59dff0f536ae3f9b3c..5b035840e95008995c712bf6235d7c4ce6650b23 100644 --- a/lib/workers/pr/changelog/source-github.ts +++ b/lib/workers/pr/changelog/source-github.ts @@ -13,9 +13,13 @@ const { get: ghGot } = api; async function getTags( endpoint: string, + versioning: string, repository: string ): Promise<string[]> { - const url = `${endpoint}repos/${repository}/tags?per_page=100`; + let url = endpoint + ? endpoint.replace(/\/?$/, '/') + : /* istanbul ignore next: not possible to test, maybe never possible? */ 'https://api.github.com/'; + url += `repos/${repository}/tags?per_page=100`; try { const res = await ghGot<{ name: string }[]>(url, { paginate: true, @@ -41,6 +45,7 @@ async function getTags( } export async function getChangeLogJSON({ + endpoint, versioning, fromVersion, toVersion, @@ -65,7 +70,8 @@ export async function getChangeLogJSON({ }); // istanbul ignore if if (!config.token) { - if (host.endsWith('github.com')) { + // prettier-ignore + if (URL.parse(sourceUrl).host.endsWith('github.com')) { // lgtm [js/incomplete-url-substring-sanitization] logger.warn( { manager, depName, sourceUrl }, 'No github.com token has been configured. Skipping release notes retrieval' @@ -80,7 +86,7 @@ export async function getChangeLogJSON({ } const apiBaseUrl = sourceUrl.startsWith('https://github.com/') ? 'https://api.github.com/' - : baseUrl; + : endpoint; // TODO FIX const repository = pathname.slice(1).replace(/\/$/, ''); if (repository.split('/').length !== 2) { logger.debug({ sourceUrl }, 'Invalid github URL found'); @@ -104,7 +110,7 @@ export async function getChangeLogJSON({ async function getRef(release: Release): Promise<string | null> { if (!tags) { - tags = await getTags(baseUrl, repository); + tags = await getTags(endpoint, versioning, repository); } const regex = new RegExp(`${depName}[@-]`); const tagName = tags @@ -137,7 +143,6 @@ export async function getChangeLogJSON({ cacheNamespace, getCacheKey(prev.version, next.version) ); - // istanbul ignore else if (!release) { release = { version: next.version,