-
Notifications
You must be signed in to change notification settings - Fork 128
/
index.js
105 lines (91 loc) · 2.85 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* eslint require-atomic-updates: off */
import { defaultTo, castArray } from "lodash-es";
import verifyGitHub from "./lib/verify.js";
import addChannelGitHub from "./lib/add-channel.js";
import publishGitHub from "./lib/publish.js";
import successGitHub from "./lib/success.js";
import failGitHub from "./lib/fail.js";
import { SemanticReleaseOctokit } from "./lib/octokit.js";
let verified;
export async function verifyConditions(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {},
) {
const { options } = context;
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels`, `discussionCategoryName` 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,
);
pluginConfig.discussionCategoryName = defaultTo(
pluginConfig.discussionCategoryName,
publishPlugin.discussionCategoryName,
);
}
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}
export async function publish(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {},
) {
if (!verified) {
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}
return publishGitHub(pluginConfig, context, { Octokit });
}
export async function addChannel(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {},
) {
if (!verified) {
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}
return addChannelGitHub(pluginConfig, context, { Octokit });
}
export async function success(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {},
) {
if (!verified) {
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}
await successGitHub(pluginConfig, context, { Octokit });
}
export async function fail(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {},
) {
if (!verified) {
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}
await failGitHub(pluginConfig, context, { Octokit });
}