-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
52 lines (44 loc) · 1.5 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
const core = require('@actions/core');
const check = require('check-types');
const path = require('path');
let config = {};
function retrieveParameters() {
const conflictReviewers = splitCommaString(
core.getInput('conflict_reviewers', {required: false})
);
const localBranch = core.getInput('local_branch', {required: false}) || 'trunk';
const localPath = path.resolve(
core.getInput('local_path', {required: false}) ||
process.env.GITHUB_WORKSPACE
);
const targetTag = core.getInput('target_tag', {required: true});
const token = core.getInput('github_token', {required: true});
const upstreamBranch = core.getInput('upstream_branch', {required: false}) || localBranch;
const upstreamRepo = core.getInput('upstream_repo', {required: true});
const upstreamRepoURL = `https://github.com/${core.getInput('upstream_repo', {required: true})}`;
return Object.freeze({conflictReviewers, localBranch, localPath, targetTag, token, upstreamBranch, upstreamRepo, upstreamRepoURL});
}
function validateParameters(p) {
check.nonEmptyString(p.localBranch);
check.nonEmptyString(p.targetTag);
check.nonEmptyString(p.token);
check.nonEmptyString(p.upstreamBranch);
check.match(p.upstreamRepo, /\w+\/\w+/);
}
function splitCommaString(string) {
if (typeof string === 'string') {
return string.split(/, */)
.filter(i => i);
}
return [];
}
function get() {
try {
config = retrieveParameters();
validateParameters(config);
} catch (error) {
core.setFailed(error.message);
}
return config;
}
exports.get = get;