From 000142e5d54ad3e965c2a41be686eefbbcbb6e6e Mon Sep 17 00:00:00 2001 From: Richard Versteeg Date: Wed, 2 Feb 2022 11:20:51 +0100 Subject: [PATCH] feat(changelogs): Add `github-changelog` and `gitlab-changelog` hosttypes (#13695) Co-authored-by: Michael Kriese --- lib/constants/platform.spec.ts | 8 ++ lib/constants/platforms.ts | 2 + lib/util/http/host-rules.spec.ts | 93 +++++++++++++++++++----- lib/workers/pr/changelog/github/index.ts | 3 +- lib/workers/pr/changelog/gitlab/index.ts | 3 +- 5 files changed, 90 insertions(+), 19 deletions(-) diff --git a/lib/constants/platform.spec.ts b/lib/constants/platform.spec.ts index 3fe0b31b3..30c8572b8 100644 --- a/lib/constants/platform.spec.ts +++ b/lib/constants/platform.spec.ts @@ -5,6 +5,8 @@ import { GitlabPackagesDatasource } from '../datasource/gitlab-packages'; import { GitlabReleasesDatasource } from '../datasource/gitlab-releases'; import { id as GL_TAGS_DS } from '../datasource/gitlab-tags'; import { id as POD_DS } from '../datasource/pod'; +import { id as GITHUB_CHANGELOG_ID } from '../workers/pr/changelog/github'; +import { id as GITLAB_CHANGELOG_ID } from '../workers/pr/changelog/gitlab'; import { BITBUCKET_API_USING_HOST_TYPES, GITHUB_API_USING_HOST_TYPES, @@ -21,6 +23,9 @@ describe('constants/platform', () => { expect( GITLAB_API_USING_HOST_TYPES.includes(GitlabPackagesDatasource.id) ).toBeTrue(); + expect( + GITLAB_API_USING_HOST_TYPES.includes(GITLAB_CHANGELOG_ID) + ).toBeTrue(); expect(GITLAB_API_USING_HOST_TYPES.includes(PlatformId.Gitlab)).toBeTrue(); }); @@ -32,6 +37,9 @@ describe('constants/platform', () => { expect(GITHUB_API_USING_HOST_TYPES.includes(GH_TAGS_DS)).toBeTrue(); expect(GITHUB_API_USING_HOST_TYPES.includes(GH_RELEASES_DS)).toBeTrue(); expect(GITHUB_API_USING_HOST_TYPES.includes(POD_DS)).toBeTrue(); + expect( + GITHUB_API_USING_HOST_TYPES.includes(GITHUB_CHANGELOG_ID) + ).toBeTrue(); expect(GITHUB_API_USING_HOST_TYPES.includes(PlatformId.Github)).toBeTrue(); }); diff --git a/lib/constants/platforms.ts b/lib/constants/platforms.ts index 71a7f4413..c97722d42 100644 --- a/lib/constants/platforms.ts +++ b/lib/constants/platforms.ts @@ -13,6 +13,7 @@ export const GITHUB_API_USING_HOST_TYPES = [ 'github-releases', 'github-tags', 'pod', + 'github-changelog', ]; export const GITLAB_API_USING_HOST_TYPES = [ @@ -20,6 +21,7 @@ export const GITLAB_API_USING_HOST_TYPES = [ 'gitlab-releases', 'gitlab-tags', 'gitlab-packages', + 'gitlab-changelog', ]; export const BITBUCKET_API_USING_HOST_TYPES = [ diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index fa33fa9df..f99503877 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -39,12 +39,6 @@ describe('util/http/host-rules', () => { token: 'abc', }); - hostRules.add({ - hostType: 'github-releases', - username: 'some', - password: 'xxx', - }); - hostRules.add({ hostType: PlatformId.Bitbucket, token: 'cdef', @@ -135,7 +129,25 @@ describe('util/http/host-rules', () => { `); }); - it('no fallback', () => { + it('no fallback to github', () => { + hostRules.add({ + hostType: 'github-tags', + username: 'some2', + password: 'xxx2', + }); + hostRules.add({ + hostType: 'github-changelog', + token: 'changelogtoken', + }); + hostRules.add({ + hostType: 'pod', + token: 'pod-token', + }); + hostRules.add({ + hostType: 'github-releases', + username: 'some', + password: 'xxx', + }); expect( applyHostRules(url, { ...options, hostType: 'github-releases' }) ).toEqual({ @@ -143,19 +155,57 @@ describe('util/http/host-rules', () => { username: 'some', password: 'xxx', }); + expect( + applyHostRules(url, { ...options, hostType: 'github-tags' }) + ).toEqual({ + hostType: 'github-tags', + username: 'some2', + password: 'xxx2', + }); + expect(applyHostRules(url, { ...options, hostType: 'pod' })).toEqual({ + context: { + authType: undefined, + }, + hostType: 'pod', + token: 'pod-token', + }); + expect( + applyHostRules(url, { ...options, hostType: 'github-changelog' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'github-changelog', + token: 'changelogtoken', + }); }); it('fallback to github', () => { - expect(applyHostRules(url, { ...options, hostType: 'github-tags' })) - .toMatchInlineSnapshot(` - Object { - "context": Object { - "authType": undefined, - }, - "hostType": "github-tags", - "token": "token", - } - `); + expect( + applyHostRules(url, { ...options, hostType: 'github-tags' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'github-tags', + token: 'token', + }); + expect( + applyHostRules(url, { ...options, hostType: 'github-changelog' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'github-changelog', + token: 'token', + }); + expect(applyHostRules(url, { ...options, hostType: 'pod' })).toEqual({ + context: { + authType: undefined, + }, + hostType: 'pod', + token: 'token', + }); }); it('no fallback to gitlab', () => { @@ -228,6 +278,15 @@ describe('util/http/host-rules', () => { hostType: 'gitlab-packages', token: 'abc', }); + expect( + applyHostRules(url, { ...options, hostType: 'gitlab-changelog' }) + ).toEqual({ + context: { + authType: undefined, + }, + hostType: 'gitlab-changelog', + token: 'abc', + }); }); it('no fallback to bitbucket', () => { diff --git a/lib/workers/pr/changelog/github/index.ts b/lib/workers/pr/changelog/github/index.ts index 89ab93060..b18793950 100644 --- a/lib/workers/pr/changelog/github/index.ts +++ b/lib/workers/pr/changelog/github/index.ts @@ -11,7 +11,8 @@ import { GithubHttp } from '../../../../util/http/github'; import { ensureTrailingSlash } from '../../../../util/url'; import type { ChangeLogFile, ChangeLogNotes } from '../types'; -const http = new GithubHttp(); +export const id = 'github-changelog'; +const http = new GithubHttp(id); export async function getTags( endpoint: string, diff --git a/lib/workers/pr/changelog/gitlab/index.ts b/lib/workers/pr/changelog/gitlab/index.ts index d966779ce..16f9c5030 100644 --- a/lib/workers/pr/changelog/gitlab/index.ts +++ b/lib/workers/pr/changelog/gitlab/index.ts @@ -7,7 +7,8 @@ import { GitlabHttp } from '../../../../util/http/gitlab'; import { ensureTrailingSlash } from '../../../../util/url'; import type { ChangeLogFile, ChangeLogNotes } from '../types'; -const http = new GitlabHttp(); +export const id = 'gitlab-changelog'; +const http = new GitlabHttp(id); export async function getTags( endpoint: string,