- introduce better handling of cases in which invalid references are provided, return an empty changelog and send out error

This commit is contained in:
Mike Penz
2020-10-17 17:38:08 +02:00
parent 5ce9cb0351
commit 619d3f460e
3 changed files with 47 additions and 6 deletions
+17
View File
@@ -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)
+20
View File
@@ -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"
}
+10 -6
View File
@@ -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 []
}