- use different pen for write logs

- remove default value for configuration, to cleanly fallback to defaults
- rename gitHelper, move dir exists helper
- add reading input values group
- improve warning for configuration
This commit is contained in:
Mike Penz
2020-10-17 19:37:11 +02:00
parent 1e0f6ab49e
commit bd49950417
7 changed files with 78 additions and 76 deletions
+1 -31
View File
@@ -1,6 +1,7 @@
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as io from '@actions/io'
import { directoryExistsSync } from './utils';
export async function createCommandManager(
workingDirectory: string
@@ -8,37 +9,6 @@ export async function createCommandManager(
return await GitCommandManager.createCommandManager(workingDirectory)
}
function directoryExistsSync(path: string, required?: boolean): boolean {
if (!path) {
throw new Error("Arg 'path' must not be empty")
}
let stats: fs.Stats
try {
stats = fs.statSync(path)
} catch (error) {
if (error.code === 'ENOENT') {
if (!required) {
return false
}
throw new Error(`Directory '${path}' does not exist`)
}
throw new Error(
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
)
}
if (stats.isDirectory()) {
return true
} else if (!required) {
return false
}
throw new Error(`Directory '${path}' does not exist`)
}
class GitCommandManager {
private gitPath = ''
private workingDirectory = ''
+4 -4
View File
@@ -1,12 +1,13 @@
import * as core from '@actions/core'
import {readConfiguration} from './utils'
import {ReleaseNotes} from './releaseNotes'
import {createCommandManager} from './git-helper'
import {createCommandManager} from './gitHelper'
import * as github from '@actions/github'
import * as path from 'path'
import {DefaultConfiguration} from './configuration'
async function run(): Promise<void> {
core.startGroup(`📘 Reading input values`)
try {
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
if (!githubWorkspacePath) {
@@ -29,9 +30,7 @@ async function run(): Promise<void> {
core.debug(`configurationPath = '${configurationPath}'`)
const providedConfiguration = readConfiguration(configurationPath)
if (!providedConfiguration) {
core.error(
`Configuration provided, but it couldn't be found, or failed to parse`
)
core.info(`⚠️ Configuration provided, but it couldn't be found, or failed to parse. Fallback to Defaults`)
} else {
configuration = providedConfiguration
}
@@ -94,6 +93,7 @@ async function run(): Promise<void> {
} else {
core.debug(`Resolved 'toTag' as ${toTag}`)
}
core.endGroup()
const releaseNotes = new ReleaseNotes({
owner,
+3 -3
View File
@@ -35,7 +35,7 @@ export function buildChangelog(
)
}
core.info(`️ Used ${validateTransfomers.length} transformers to adjust message`)
core.info(` Wrote messages for ${prs.length} pull requests`)
core.info(` Wrote messages for ${prs.length} pull requests`)
// bring PRs into the order of categories
const categorized = new Map<Category, string[]>()
@@ -76,13 +76,13 @@ export function buildChangelog(
changelog = `${changelog}\n`
}
}
core.info(` Wrote ${categorized.size} categorized pull requests down`)
core.info(` Wrote ${categorized.size} categorized pull requests down`)
let changelogUncategorized = ''
for (const pr of uncategorized) {
changelogUncategorized = `${changelogUncategorized + pr}\n`
}
core.info(` Wrote ${changelogUncategorized.length} non categorized pull requests down`)
core.info(` Wrote ${changelogUncategorized.length} non categorized pull requests down`)
// fill template
let transformedChangelog = config.template ?? DefaultConfiguration.template
+31
View File
@@ -10,3 +10,34 @@ export function readConfiguration(filename: string): Configuration | null {
return null
}
}
export function directoryExistsSync(path: string, required?: boolean): boolean {
if (!path) {
throw new Error("Arg 'path' must not be empty")
}
let stats: fs.Stats
try {
stats = fs.statSync(path)
} catch (error) {
if (error.code === 'ENOENT') {
if (!required) {
return false
}
throw new Error(`Directory '${path}' does not exist`)
}
throw new Error(
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
)
}
if (stats.isDirectory()) {
return true
} else if (!required) {
return false
}
throw new Error(`Directory '${path}' does not exist`)
}