-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathfail.js
More file actions
58 lines (53 loc) · 2.06 KB
/
fail.js
File metadata and controls
58 lines (53 loc) · 2.06 KB
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
import {template} from 'lodash-es';
import debugFactory from 'debug';
import parseGithubUrl from './parse-github-url.js';
import {ISSUE_ID} from './definitions/constants.js';
import resolveConfig from './resolve-config.js';
import getClient from './get-client.js';
import findSRIssues from './find-sr-issues.js';
import getFailComment from './get-fail-comment.js';
const debug = debugFactory('semantic-release:github');
export default async function fail(pluginConfig, context) {
const {
options: {repositoryUrl},
branch,
errors,
logger,
} = context;
const {githubToken, githubUrl, githubApiPathPrefix, proxy, failComment, failTitle, labels, assignees} = resolveConfig(
pluginConfig,
context
);
if (failComment === false || failTitle === false) {
logger.log('Skip issue creation.');
} else {
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
const [owner, repo] = (await github.repos.get(parseGithubUrl(repositoryUrl))).data.full_name.split('/');
const body = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors);
const [srIssue] = await findSRIssues(github, failTitle, owner, repo);
if (srIssue) {
logger.log('Found existing semantic-release issue #%d.', srIssue.number);
const comment = {owner, repo, issue_number: srIssue.number, body};
debug('create comment: %O', comment);
const {
data: {html_url: url},
} = await github.issues.createComment(comment);
logger.log('Added comment to issue #%d: %s.', srIssue.number, url);
} else {
const newIssue = {
owner,
repo,
title: failTitle,
body: `${body}\n\n${ISSUE_ID}`,
labels: labels || [],
assignees,
};
debug('create issue: %O', newIssue);
const {
data: {html_url: url, number},
} = await github.issues.create(newIssue);
logger.log('Created issue #%d: %s.', number, url);
}
}
}