- introduce better more stable fallbacks in case the configuration is missing
- move configurations into subfolder for easier discovery - simplify missing value fallback specification
This commit is contained in:
+17
-6
@@ -4,6 +4,7 @@ import {ReleaseNotes} from './releaseNotes'
|
||||
import {createCommandManager} from './git-helper'
|
||||
import * as github from '@actions/github'
|
||||
import * as path from 'path'
|
||||
import {DefaultConfiguration} from './configuration'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
@@ -19,12 +20,22 @@ async function run(): Promise<void> {
|
||||
core.debug(`repositoryPath = '${repositoryPath}'`)
|
||||
|
||||
const configurationFile: string = core.getInput('configuration')
|
||||
const configurationPath = path.resolve(
|
||||
githubWorkspacePath,
|
||||
configurationFile
|
||||
)
|
||||
core.debug(`configurationPath = '${configurationPath}'`)
|
||||
const configuration = readConfiguration(configurationPath)
|
||||
let configuration = DefaultConfiguration
|
||||
if (configurationFile) {
|
||||
const configurationPath = path.resolve(
|
||||
githubWorkspacePath,
|
||||
configurationFile
|
||||
)
|
||||
core.debug(`configurationPath = '${configurationPath}'`)
|
||||
const providedConfiguration = readConfiguration(configurationPath)
|
||||
if (!providedConfiguration) {
|
||||
core.error(
|
||||
`Configuration provided, but it couldn't be found, or failed to parse`
|
||||
)
|
||||
} else {
|
||||
configuration = providedConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
const token = core.getInput('token')
|
||||
let owner = core.getInput('owner')
|
||||
|
||||
+10
-14
@@ -1,5 +1,5 @@
|
||||
import {Octokit} from '@octokit/rest'
|
||||
import { Commits, CommitInfo } from './commits';
|
||||
import {Commits, CommitInfo} from './commits'
|
||||
import {PullRequestInfo, PullRequests} from './pullRequests'
|
||||
import {buildChangelog} from './transform'
|
||||
import * as core from '@actions/core'
|
||||
@@ -34,17 +34,15 @@ export class ReleaseNotes {
|
||||
repo,
|
||||
toTag,
|
||||
ignorePreReleases,
|
||||
configuration.max_tags_to_fetch
|
||||
? configuration.max_tags_to_fetch
|
||||
: DefaultConfiguration.max_tags_to_fetch
|
||||
configuration.max_tags_to_fetch ??
|
||||
DefaultConfiguration.max_tags_to_fetch
|
||||
)
|
||||
if (previousTag == null) {
|
||||
core.error(`Unable to retrieve previous tag given ${toTag}`)
|
||||
return configuration.empty_template
|
||||
? configuration.empty_template
|
||||
: DefaultConfiguration.empty_template
|
||||
return (
|
||||
configuration.empty_template ?? DefaultConfiguration.empty_template
|
||||
)
|
||||
}
|
||||
|
||||
this.options.fromTag = previousTag.name
|
||||
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`)
|
||||
}
|
||||
@@ -53,9 +51,7 @@ export class ReleaseNotes {
|
||||
|
||||
if (mergedPullRequests.length === 0) {
|
||||
core.warning(`No pull requests found`)
|
||||
return configuration.empty_template
|
||||
? configuration.empty_template
|
||||
: DefaultConfiguration.empty_template
|
||||
return configuration.empty_template ?? DefaultConfiguration.empty_template
|
||||
}
|
||||
|
||||
return buildChangelog(mergedPullRequests, configuration)
|
||||
@@ -85,9 +81,9 @@ export class ReleaseNotes {
|
||||
let fromDate = firstCommit.date
|
||||
const toDate = lastCommit.date
|
||||
|
||||
const maxDays = configuration.max_back_track_time_days
|
||||
? configuration.max_back_track_time_days
|
||||
: DefaultConfiguration.max_back_track_time_days
|
||||
const maxDays =
|
||||
configuration.max_back_track_time_days ??
|
||||
DefaultConfiguration.max_back_track_time_days
|
||||
const maxFromDate = toDate.clone().subtract(maxDays, 'days')
|
||||
if (maxFromDate.isAfter(fromDate)) {
|
||||
core.info(`Adjusted 'fromDate' to go max ${maxDays} back`)
|
||||
|
||||
+8
-4
@@ -1,8 +1,12 @@
|
||||
import * as fs from 'fs'
|
||||
import {Configuration} from './configuration'
|
||||
|
||||
export function readConfiguration(filename: string): Configuration {
|
||||
const rawdata = fs.readFileSync(filename, 'utf8')
|
||||
const configurationJSON: Configuration = JSON.parse(rawdata)
|
||||
return configurationJSON
|
||||
export function readConfiguration(filename: string): Configuration | null {
|
||||
try {
|
||||
const rawdata = fs.readFileSync(filename, 'utf8')
|
||||
const configurationJSON: Configuration = JSON.parse(rawdata)
|
||||
return configurationJSON
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user