- move fromTag resolving to main.ts and remove dependency on checks from ReleaseNotes.ts

- require fromTag for ReleaseNotes
- adjust tests, split into according test classes
- simplify transform.ts
This commit is contained in:
Mike Penz
2020-10-19 16:33:00 +02:00
parent 2fb7019ca5
commit d9c1239d34
5 changed files with 170 additions and 171 deletions
+36 -4
View File
@@ -8,6 +8,8 @@ import {ReleaseNotes} from './releaseNotes'
import {createCommandManager} from './gitHelper'
import * as github from '@actions/github'
import {DefaultConfiguration} from './configuration'
import {Octokit} from '@octokit/rest'
import {Tags} from './tags'
async function run(): Promise<void> {
core.setOutput('failed', false) // mark the action not failed by default
@@ -30,7 +32,7 @@ async function run(): Promise<void> {
const owner = core.getInput('owner') || github.context.repo.owner
const repo = core.getInput('repo') || github.context.repo.repo
// read in from, to tag inputs
const fromTag = core.getInput('fromTag')
let fromTag = core.getInput('fromTag')
let toTag = core.getInput('toTag')
// read in flags
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true'
@@ -80,19 +82,49 @@ async function run(): Promise<void> {
}
core.endGroup()
const releaseNotes = new ReleaseNotes({
// load octokit instance
const octokit = new Octokit({
auth: `token ${token || process.env.GITHUB_TOKEN}`
})
// ensure to resolve the fromTag if it was not provided specifically
if (!fromTag) {
core.startGroup(`🔖 Resolve previous tag`)
core.debug(`fromTag undefined, trying to resolve via API`)
const tagsApi = new Tags(octokit)
const previousTag = await tagsApi.findPredecessorTag(
owner,
repo,
toTag,
ignorePreReleases,
configuration.max_tags_to_fetch ||
DefaultConfiguration.max_tags_to_fetch
)
if (previousTag == null) {
failOrError(
`💥 Unable to retrieve previous tag given ${toTag}`,
failOnError
)
return
}
fromTag = previousTag.name
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`)
core.endGroup()
}
const releaseNotes = new ReleaseNotes(octokit, {
owner,
repo,
fromTag,
toTag,
ignorePreReleases,
failOnError,
configuration
})
core.setOutput(
'changelog',
(await releaseNotes.pull(token)) ||
(await releaseNotes.pull()) ||
configuration.empty_template ||
DefaultConfiguration.empty_template
)