|
1 | | -const {template} = require('lodash'); |
2 | | -const urlJoin = require('url-join'); |
3 | | -const got = require('got'); |
4 | | -const debug = require('debug')('semantic-release:gitlab'); |
5 | | -const resolveConfig = require('./resolve-config'); |
6 | | -const getRepoId = require('./get-repo-id'); |
7 | | -const getFailComment = require('./get-fail-comment'); |
8 | | - |
9 | | -module.exports = async (pluginConfig, context) => { |
| 1 | +import { template } from "lodash-es"; |
| 2 | +import urlJoin from "url-join"; |
| 3 | +import got from "got"; |
| 4 | +import _debug from "debug"; |
| 5 | +const debug = _debug("semantic-release:gitlab"); |
| 6 | +import resolveConfig from "./resolve-config.js"; |
| 7 | +import getRepoId from "./get-repo-id.js"; |
| 8 | +import getFailComment from "./get-fail-comment.js"; |
| 9 | + |
| 10 | +export default async (pluginConfig, context) => { |
10 | 11 | const { |
11 | | - options: {repositoryUrl}, |
| 12 | + options: { repositoryUrl }, |
12 | 13 | branch, |
13 | 14 | errors, |
14 | 15 | logger, |
15 | 16 | } = context; |
16 | | - const {gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee} = resolveConfig( |
| 17 | + const { gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee } = resolveConfig( |
17 | 18 | pluginConfig, |
18 | 19 | context |
19 | 20 | ); |
20 | 21 | const repoId = getRepoId(context, gitlabUrl, repositoryUrl); |
21 | 22 | const encodedRepoId = encodeURIComponent(repoId); |
22 | | - const apiOptions = {headers: {'PRIVATE-TOKEN': gitlabToken}}; |
| 23 | + const apiOptions = { headers: { "PRIVATE-TOKEN": gitlabToken } }; |
23 | 24 |
|
24 | 25 | if (failComment === false || failTitle === false) { |
25 | | - logger.log('Skip issue creation.'); |
| 26 | + logger.log("Skip issue creation."); |
26 | 27 | } else { |
27 | 28 | const encodedFailTitle = encodeURIComponent(failTitle); |
28 | | - const description = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors); |
| 29 | + const description = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors); |
29 | 30 |
|
30 | 31 | const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/issues`); |
31 | 32 | const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`); |
32 | 33 |
|
33 | | - const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json(); |
| 34 | + const openFailTitleIssues = await got(openFailTitleIssueEndpoint, { ...apiOptions }).json(); |
34 | 35 | const existingIssue = openFailTitleIssues.find((openFailTitleIssue) => openFailTitleIssue.title === failTitle); |
35 | 36 |
|
36 | 37 | if (existingIssue) { |
37 | | - debug('comment on issue: %O', existingIssue); |
| 38 | + debug("comment on issue: %O", existingIssue); |
38 | 39 |
|
39 | 40 | const issueNotesEndpoint = urlJoin( |
40 | 41 | gitlabApiUrl, |
41 | 42 | `/projects/${existingIssue.project_id}/issues/${existingIssue.iid}/notes` |
42 | 43 | ); |
43 | 44 | await got.post(issueNotesEndpoint, { |
44 | 45 | ...apiOptions, |
45 | | - json: {body: description}, |
| 46 | + json: { body: description }, |
46 | 47 | }); |
47 | 48 |
|
48 | | - const {id, web_url} = existingIssue; |
49 | | - logger.log('Commented on issue #%d: %s.', id, web_url); |
| 49 | + const { id, web_url } = existingIssue; |
| 50 | + logger.log("Commented on issue #%d: %s.", id, web_url); |
50 | 51 | } else { |
51 | | - const newIssue = {id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee}; |
52 | | - debug('create issue: %O', newIssue); |
| 52 | + const newIssue = { id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee }; |
| 53 | + debug("create issue: %O", newIssue); |
53 | 54 |
|
54 | 55 | /* eslint camelcase: off */ |
55 | | - const {id, web_url} = await got.post(issuesEndpoint, { |
| 56 | + const { id, web_url } = await got.post(issuesEndpoint, { |
56 | 57 | ...apiOptions, |
57 | 58 | json: newIssue, |
58 | 59 | }); |
59 | | - logger.log('Created issue #%d: %s.', id, web_url); |
| 60 | + logger.log("Created issue #%d: %s.", id, web_url); |
60 | 61 | } |
61 | 62 | } |
62 | 63 | }; |
0 commit comments