From 0248f956d55aed0a3f45ff606752bfacba0d6b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= <atorrescogollo@gmail.com> Date: Thu, 9 Jun 2022 13:48:55 +0200 Subject: [PATCH] fix(changelog): gitRef check (#15869) * fix: GitRef match when getting GitHub Changelog * Fix tests * Updated snaps to support gitref field * gitRef check support for gitlab * Check with extractVersion * Fixed tests for release-notes.spec.ts * Fixed tests and created test case for extractVersion flow * Revert "Fixed tests and created test case for extractVersion flow" This reverts commit b018a6415a30e894d5477f8df912147524e9aa73. * Revert "Fixed tests for release-notes.spec.ts" This reverts commit d0d4c004bfc63430a40e734420757f676f52147f. * Revert "Check with extractVersion" This reverts commit bb9b7953681165e3355d0a1717b956d094acfdbb. * Fixed tests Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- .../__snapshots__/github.spec.ts.snap | 24 ++++ .../__snapshots__/gitlab.spec.ts.snap | 24 ++++ .../__snapshots__/index.spec.ts.snap | 28 ++++ .../update/pr/changelog/release-notes.spec.ts | 130 ++++++++++++++---- .../update/pr/changelog/release-notes.ts | 17 ++- .../update/pr/changelog/source-github.ts | 1 + .../update/pr/changelog/source-gitlab.ts | 1 + .../repository/update/pr/changelog/types.ts | 1 + .../repository/update/pr/index.spec.ts | 1 + 9 files changed, 196 insertions(+), 31 deletions(-) diff --git a/lib/workers/repository/update/pr/changelog/__snapshots__/github.spec.ts.snap b/lib/workers/repository/update/pr/changelog/__snapshots__/github.spec.ts.snap index 57f6a7c913..0fd0d55de4 100644 --- a/lib/workers/repository/update/pr/changelog/__snapshots__/github.spec.ts.snap +++ b/lib/workers/repository/update/pr/changelog/__snapshots__/github.spec.ts.snap @@ -17,6 +17,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -24,6 +25,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -33,6 +35,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -45,6 +48,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -72,6 +76,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -79,6 +84,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -88,6 +94,7 @@ 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", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -100,6 +107,7 @@ Object { "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -127,6 +135,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -134,6 +143,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -143,6 +153,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -155,6 +166,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -182,6 +194,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -189,6 +202,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -198,6 +212,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -210,6 +225,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -237,6 +253,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -244,6 +261,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -253,6 +271,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -265,6 +284,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -292,6 +312,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -299,6 +320,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -308,6 +330,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -320,6 +343,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", diff --git a/lib/workers/repository/update/pr/changelog/__snapshots__/gitlab.spec.ts.snap b/lib/workers/repository/update/pr/changelog/__snapshots__/gitlab.spec.ts.snap index 5ea9435c49..6fac436072 100644 --- a/lib/workers/repository/update/pr/changelog/__snapshots__/gitlab.spec.ts.snap +++ b/lib/workers/repository/update/pr/changelog/__snapshots__/gitlab.spec.ts.snap @@ -17,6 +17,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "5.6.1", }, @@ -24,6 +25,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.6.0", }, @@ -31,6 +33,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": null, "version": "5.5.0", }, @@ -38,6 +41,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.4.0", }, @@ -62,6 +66,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "5.6.1", }, @@ -69,6 +74,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.6.0", }, @@ -76,6 +82,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": null, "version": "5.5.0", }, @@ -83,6 +90,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.4.0", }, @@ -107,6 +115,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "5.6.1", }, @@ -114,6 +123,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.6.0", }, @@ -121,6 +131,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": null, "version": "5.5.0", }, @@ -128,6 +139,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.4.0", }, @@ -154,6 +166,7 @@ Object { "url": "https://gitlab.com/meno/dropzone/compare/v5.6.0...v5.6.1", }, "date": undefined, + "gitRef": undefined, "releaseNotes": Object { "notesSourceUrl": "", "url": "https://gitlab.com/meno/dropzone/compare/v5.6.0...v5.6.1", @@ -166,6 +179,7 @@ Object { "url": "https://gitlab.com/meno/dropzone/compare/v5.5.0...v5.6.0", }, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": Object { "notesSourceUrl": "", "url": "https://gitlab.com/meno/dropzone/compare/v5.5.0...v5.6.0", @@ -178,6 +192,7 @@ Object { "url": "https://gitlab.com/meno/dropzone/compare/v5.4.0...v5.5.0", }, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://gitlab.com/meno/dropzone/compare/v5.4.0...v5.5.0", @@ -190,6 +205,7 @@ Object { "url": "https://gitlab.com/meno/dropzone/compare/v5.2.0...v5.4.0", }, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": Object { "notesSourceUrl": "", "url": "https://gitlab.com/meno/dropzone/compare/v5.2.0...v5.4.0", @@ -217,6 +233,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "5.6.1", }, @@ -224,6 +241,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.6.0", }, @@ -231,6 +249,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": null, "version": "5.5.0", }, @@ -238,6 +257,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.4.0", }, @@ -262,6 +282,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "5.6.1", }, @@ -269,6 +290,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2020-02-13T15:37:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.6.0", }, @@ -276,6 +298,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": "eba303e91c930292198b2fc57040145682162a1b", "releaseNotes": null, "version": "5.5.0", }, @@ -283,6 +306,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2018-08-24T14:23:00.000Z", + "gitRef": undefined, "releaseNotes": null, "version": "5.4.0", }, diff --git a/lib/workers/repository/update/pr/changelog/__snapshots__/index.spec.ts.snap b/lib/workers/repository/update/pr/changelog/__snapshots__/index.spec.ts.snap index 7fe27ef13f..0bc6c5831b 100644 --- a/lib/workers/repository/update/pr/changelog/__snapshots__/index.spec.ts.snap +++ b/lib/workers/repository/update/pr/changelog/__snapshots__/index.spec.ts.snap @@ -17,6 +17,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -24,6 +25,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -33,6 +35,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -45,6 +48,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -72,6 +76,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -79,6 +84,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -88,6 +94,7 @@ 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", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -100,6 +107,7 @@ Object { "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -127,6 +135,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -134,6 +143,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -143,6 +153,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -155,6 +166,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -182,6 +194,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -189,6 +202,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -198,6 +212,7 @@ 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", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -210,6 +225,7 @@ Object { "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github-enterprise.example.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -237,6 +253,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -244,6 +261,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -253,6 +271,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -265,6 +284,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", @@ -292,6 +312,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -301,6 +322,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/v2.3.0...v2.4.2", }, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/v2.3.0...v2.4.2", @@ -313,6 +335,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/2.2.2...v2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/2.2.2...v2.3.0", @@ -325,6 +348,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/1.0.0...2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/1.0.0...2.2.2", @@ -352,6 +376,7 @@ Object { "changes": Array [], "compare": Object {}, "date": undefined, + "gitRef": undefined, "releaseNotes": null, "version": "2.5.2", }, @@ -359,6 +384,7 @@ Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", + "gitRef": undefined, "releaseNotes": null, "version": "2.4.2", }, @@ -368,6 +394,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", }, "date": "2017-10-24T03:20:46.238Z", + "gitRef": "npm_2.3.0", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_2.2.2...npm_2.3.0", @@ -380,6 +407,7 @@ Object { "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", }, "date": undefined, + "gitRef": "npm_2.2.2", "releaseNotes": Object { "notesSourceUrl": "", "url": "https://github.com/chalk/chalk/compare/npm_1.0.0...npm_2.2.2", diff --git a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts index aa94a95e66..226cfb3dd6 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -277,7 +277,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/repository', depName: 'some', }, - '1.0.0' + { + version: '1.0.0', + gitRef: '1.0.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -297,7 +300,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n', @@ -325,7 +331,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n', @@ -354,7 +363,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n', @@ -383,7 +395,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n', @@ -411,7 +426,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'other', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n', @@ -445,7 +463,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body #123, [#124](https://gitlab.com/some/yet-other-repository/issues/124)', @@ -478,7 +499,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body #123, [#124](https://gitlab.com/some/yet-other-repository/issues/124)', @@ -511,7 +535,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { depName: 'other', apiBaseUrl: 'https://api.gitlab.com/', }, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toEqual({ body: 'some body #123, [#124](https://gitlab.com/some/yet-other-repository/issues/124)', @@ -531,7 +558,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { apiBaseUrl: 'https://api.lol.lol/', baseUrl: 'https://lol.lol/', } as ChangeLogProject, - '1.0.1' + { + version: '1.0.1', + gitRef: '1.0.1', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -555,7 +585,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'some/other-repository', depName: 'exampleDep', }, - '1.0.0' + { + version: '1.0.0', + gitRef: '1.0.0', + } as ChangeLogRelease ); expect(res).toEqual({ url: 'correct/url/tag.com', @@ -577,7 +610,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'chalk', }, - '2.0.0' + { + version: '2.0.0', + gitRef: '2.0.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -599,7 +635,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'chalk', }, - '2.0.0' + { + version: '2.0.0', + gitRef: '2.0.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -620,7 +659,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'some/repository1', }, - '1.0.0' + { + version: '1.0.0', + gitRef: '1.0.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -641,7 +683,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'some/repository2', }, - '1.0.0' + { + version: '1.0.0', + gitRef: '1.0.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -662,7 +707,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'angular/angular.js', }, - '1.6.9' + { + version: '1.6.9', + gitRef: '1.6.9', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ notesSourceUrl: @@ -687,7 +735,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'gitlab-org/gitter/webapp', apiBaseUrl: 'https://api.gitlab.com/', }, - '20.26.0' + { + version: '20.26.0', + gitRef: '20.26.0', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ @@ -715,7 +766,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { apiBaseUrl: 'https://my.custom.domain/', baseUrl: 'https://my.custom.domain/', }, - '20.26.0' + { + version: '20.26.0', + gitRef: '20.26.0', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ @@ -741,7 +795,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'facebook/jest', }, - '22.0.0' + { + version: '22.0.0', + gitRef: '22.0.0', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ @@ -773,7 +830,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'nodeca/js-yaml', sourceDirectory, }, - '3.10.0' + { + version: '3.10.0', + gitRef: '3.10.0', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ @@ -799,7 +859,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'nodeca/js-yaml', }, - '3.10.0' + { + version: '3.10.0', + gitRef: '3.10.0', + } as ChangeLogRelease ); expect(res).toMatchSnapshot({ @@ -814,7 +877,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { { repository: 'nodeca/js-yaml', } as ChangeLogProject, - '3.10.0' + { + version: '3.10.0', + gitRef: '3.10.0', + } as ChangeLogRelease ); expect(res).toBeNull(); }); @@ -839,7 +905,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'yargs/yargs', }, - '15.3.0' + { + version: '15.3.0', + gitRef: '15.3.0', + } as ChangeLogRelease ); versionOneNotes = res; @@ -866,7 +935,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...githubProject, repository: 'yargs/yargs', }, - '15.2.0' + { + version: '15.2.0', + gitRef: '15.2.0', + } as ChangeLogRelease ); versionTwoNotes = res; @@ -893,7 +965,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { ...gitlabProject, repository: 'itentialopensource/adapter-utils', }, - '4.33.0' + { + version: '4.33.0', + gitRef: '4.33.0', + } as ChangeLogRelease ); versionTwoNotes = res; @@ -926,7 +1001,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { repository: 'itentialopensource/adapter-utils', sourceDirectory, }, - '4.33.0' + { + version: '4.33.0', + gitRef: '4.33.0', + } as ChangeLogRelease ); versionTwoNotes = res; diff --git a/lib/workers/repository/update/pr/changelog/release-notes.ts b/lib/workers/repository/update/pr/changelog/release-notes.ts index 1709d6cf04..616f4f6316 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.ts @@ -13,6 +13,7 @@ import type { ChangeLogFile, ChangeLogNotes, ChangeLogProject, + ChangeLogRelease, ChangeLogResult, } from './types'; @@ -95,9 +96,10 @@ export function massageBody( export async function getReleaseNotes( project: ChangeLogProject, - version: string + release: ChangeLogRelease ): Promise<ChangeLogNotes | null> { const { depName, repository } = project; + const { version, gitRef } = release; logger.trace(`getReleaseNotes(${repository}, ${version}, ${depName})`); const releases = await getCachedReleaseList(project); logger.trace({ releases }, 'Release list from getReleaseList'); @@ -107,7 +109,11 @@ export async function getReleaseNotes( if (is.undefined(matchedRelease)) { // no exact match of a release then check other cases matchedRelease = releases.find( - (r) => r.tag === version || r.tag === `v${version}` + (r) => + r.tag === version || + r.tag === `v${version}` || + r.tag === gitRef || + r.tag === `v${gitRef}` ); } releaseNotes = await releaseNotesResult(matchedRelease, project); @@ -256,9 +262,10 @@ export function getReleaseNotesMdFile( export async function getReleaseNotesMd( project: ChangeLogProject, - version: string + release: ChangeLogRelease ): Promise<ChangeLogNotes | null> { const { baseUrl, repository } = project; + const version = release.version; logger.trace(`getReleaseNotesMd(${repository}, ${version})`); const skippedRepos = ['facebook/react-native']; // istanbul ignore if @@ -373,10 +380,10 @@ export async function addReleaseNotes( releaseNotes = await packageCache.get(cacheNamespace, cacheKey); // istanbul ignore else: no cache tests if (!releaseNotes) { - releaseNotes = await getReleaseNotesMd(input.project, v.version); + releaseNotes = await getReleaseNotesMd(input.project, v); // istanbul ignore else: should be tested if (!releaseNotes) { - releaseNotes = await getReleaseNotes(input.project, v.version); + releaseNotes = await getReleaseNotes(input.project, v); } // Small hack to force display of release notes when there is a compare url if (!releaseNotes && v.compare.url) { diff --git a/lib/workers/repository/update/pr/changelog/source-github.ts b/lib/workers/repository/update/pr/changelog/source-github.ts index 8d62b41dce..474ae3a468 100644 --- a/lib/workers/repository/update/pr/changelog/source-github.ts +++ b/lib/workers/repository/update/pr/changelog/source-github.ts @@ -141,6 +141,7 @@ export async function getChangeLogJSON( if (!release) { release = { version: next.version, + gitRef: next.gitRef, date: next.releaseTimestamp, // put empty changes so that existing templates won't break changes: [], diff --git a/lib/workers/repository/update/pr/changelog/source-gitlab.ts b/lib/workers/repository/update/pr/changelog/source-gitlab.ts index 04815f531e..679d7836a7 100644 --- a/lib/workers/repository/update/pr/changelog/source-gitlab.ts +++ b/lib/workers/repository/update/pr/changelog/source-gitlab.ts @@ -110,6 +110,7 @@ export async function getChangeLogJSON( release = { version: next.version, date: next.releaseTimestamp, + gitRef: next.gitRef, // put empty changes so that existing templates won't break changes: [], compare: {}, diff --git a/lib/workers/repository/update/pr/changelog/types.ts b/lib/workers/repository/update/pr/changelog/types.ts index ba737409d7..a3184672a6 100644 --- a/lib/workers/repository/update/pr/changelog/types.ts +++ b/lib/workers/repository/update/pr/changelog/types.ts @@ -20,6 +20,7 @@ export interface ChangeLogRelease { date: string | Date; releaseNotes?: ChangeLogNotes; version: string; + gitRef: string; } export interface ChangeLogProject { diff --git a/lib/workers/repository/update/pr/index.spec.ts b/lib/workers/repository/update/pr/index.spec.ts index 345301637b..912284d763 100644 --- a/lib/workers/repository/update/pr/index.spec.ts +++ b/lib/workers/repository/update/pr/index.spec.ts @@ -566,6 +566,7 @@ describe('workers/repository/update/pr/index', () => { const dummyRelease: ChangeLogRelease = { version: '', + gitRef: '', changes: dummyChanges, compare: {}, date: '', -- GitLab