forked from semantic-release/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (53 loc) · 2.21 KB
/
index.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
60
61
62
63
64
65
66
67
/* eslint require-atomic-updates: off */
const {defaultTo, castArray} = require('lodash');
const verifyGitHub = require('./lib/verify');
const addChannelGitHub = require('./lib/add-channel');
const publishGitHub = require('./lib/publish');
const successGitHub = require('./lib/success');
const failGitHub = require('./lib/fail');
let verified;
async function verifyConditions(pluginConfig, context) {
const {options} = context;
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
if (options.publish) {
const publishPlugin =
castArray(options.publish).find((config) => config.path && config.path === '@semantic-release/github') || {};
pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets);
pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment);
pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment);
pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle);
pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels);
pluginConfig.assignees = defaultTo(pluginConfig.assignees, publishPlugin.assignees);
}
await verifyGitHub(pluginConfig, context);
verified = true;
}
async function publish(pluginConfig, context) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
verified = true;
}
return publishGitHub(pluginConfig, context);
}
async function addChannel(pluginConfig, context) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
verified = true;
}
return addChannelGitHub(pluginConfig, context);
}
async function success(pluginConfig, context) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
verified = true;
}
await successGitHub(pluginConfig, context);
}
async function fail(pluginConfig, context) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
verified = true;
}
await failGitHub(pluginConfig, context);
}
module.exports = {verifyConditions, addChannel, publish, success, fail};