forked from semantic-release/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfail.js
More file actions
48 lines (45 loc) · 1.98 KB
/
Copy pathfail.js
File metadata and controls
48 lines (45 loc) · 1.98 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
const {template} = require('lodash');
const debug = require('debug')('semantic-release:github');
const parseGithubUrl = require('./parse-github-url');
const {ISSUE_ID} = require('./definitions/constants');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
const findSRIssues = require('./find-sr-issues');
const getFailComment = require('./get-fail-comment');
module.exports = async (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);
}
}
};