From 619d3f460eb467222f275494158e1da89a4f43e9 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Sat, 17 Oct 2020 17:38:08 +0200 Subject: [PATCH] - introduce better handling of cases in which invalid references are provided, return an empty changelog and send out error --- __tests__/main.test.ts | 17 +++++++++++++++++ configs/configuration.json | 20 ++++++++++++++++++++ src/releaseNotes.ts | 16 ++++++++++------ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 configs/configuration.json diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b522ce3..54d8810 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -21,6 +21,23 @@ test('test runs', () => { console.log(cp.execSync(`node ${ip}`, options).toString()) }) */ +it('Should have empty changelog (tags)', async () => { + jest.setTimeout(180000) + + const configuration = readConfiguration('configs/configuration.json') + const releaseNotes = new ReleaseNotes({ + owner: 'mikepenz', + repo: 'release-changelog-builder-action', + fromTag: 'v0.0.1', + toTag: 'v0.0.2', + ignorePreReleases: false, + configuration: configuration + }) + + const changeLog = await releaseNotes.pull() + console.log(changeLog) + expect(changeLog).toStrictEqual(`- no changes`) +}) it('Should match generated changelog (tags)', async () => { jest.setTimeout(180000) diff --git a/configs/configuration.json b/configs/configuration.json new file mode 100644 index 0000000..3581236 --- /dev/null +++ b/configs/configuration.json @@ -0,0 +1,20 @@ +{ + "categories": [ + { + "title": "## ๐Ÿš€ Features", + "labels": ["feature"] + }, + { + "title": "## ๐Ÿ› Fixes", + "labels": ["fix"] + }, + { + "title": "## ๐Ÿงช Tests", + "labels": ["test"] + } + ], + "sort": "ASC", + "template": "${{CHANGELOG}}", + "pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}", + "empty_template": "- no changes" +} \ No newline at end of file diff --git a/src/releaseNotes.ts b/src/releaseNotes.ts index 5a3afb3..f7574c1 100755 --- a/src/releaseNotes.ts +++ b/src/releaseNotes.ts @@ -1,5 +1,5 @@ import {Octokit} from '@octokit/rest' -import {Commits} from './commits' +import { Commits, CommitInfo } from './commits'; import {PullRequestInfo, PullRequests} from './pullRequests' import {buildChangelog} from './transform' import * as core from '@actions/core' @@ -52,9 +52,7 @@ export class ReleaseNotes { const mergedPullRequests = await this.getMergedPullRequests(octokit) if (mergedPullRequests.length === 0) { - core.warning( - `No pull requests found for between ${this.options.fromTag}...${toTag}` - ) + core.warning(`No pull requests found`) return configuration.empty_template ? configuration.empty_template : DefaultConfiguration.empty_template @@ -70,9 +68,15 @@ export class ReleaseNotes { core.info(`Comparing ${owner}/${repo} - ${fromTag}...${toTag}`) const commitsApi = new Commits(octokit) - const commits = await commitsApi.getDiff(owner, repo, fromTag!!, toTag) - + let commits: CommitInfo[] + try { + commits = await commitsApi.getDiff(owner, repo, fromTag!!, toTag) + } catch (error) { + core.error(`Failed to retrieve - Invalid tag? - Because of: ${error}`) + return [] + } if (commits.length === 0) { + core.warning(`No commits found between - ${fromTag}...${toTag}`) return [] }