forked from release-drafter/release-drafter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
59 lines (52 loc) · 1.58 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const core = require('@actions/core')
const { validateSchema } = require('./schema')
const log = require('./log')
const { runnerIsActions } = require('./utils')
const Table = require('cli-table3')
const DEFAULT_CONFIG_NAME = 'release-drafter.yml'
module.exports.getConfig = async function getConfig({ context, configName }) {
try {
const repoConfig = await context.config(
configName || DEFAULT_CONFIG_NAME,
null
)
if (repoConfig == null) {
// noinspection ExceptionCaughtLocallyJS
throw new Error(
'Configuration file .github/' +
(configName || DEFAULT_CONFIG_NAME) +
' is not found. The configuration file must reside in your default branch.'
)
}
const config = validateSchema(context, repoConfig)
return config
} catch (error) {
log({ context, error, message: 'Invalid config file' })
if (error.isJoi) {
log({
context,
message:
'Config validation errors, please fix the following issues in ' +
(configName || DEFAULT_CONFIG_NAME) +
':\n' +
joiValidationErrorsAsTable(error),
})
}
if (runnerIsActions()) {
core.setFailed('Invalid config file')
}
return null
}
}
function joiValidationErrorsAsTable(error) {
const table = new Table({ head: ['Property', 'Error'] })
error.details.forEach(({ path, message }) => {
const prettyPath = path
.map((pathPart) =>
Number.isInteger(pathPart) ? `[${pathPart}]` : pathPart
)
.join('.')
table.push([prettyPath, message])
})
return table.toString()
}