UNPKG

semantic-release-gh

Version:

The official GitHub plugin, modified to accept repositoryUrl as a parameter

49 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FailGitHub = void 0; const tslib_1 = require("tslib"); const debug_1 = tslib_1.__importDefault(require("debug")); const lodash_1 = require("lodash"); const constants_1 = require("./definitions/constants"); const find_sr_issues_1 = require("./find-sr-issues"); const get_client_1 = require("./get-client"); const get_fail_comment_1 = require("./get-fail-comment"); const parse_github_url_1 = require("./parse-github-url"); const resolve_config_1 = require("./resolve-config"); const debug = (0, debug_1.default)('semantic-release:github'); const FailGitHub = async (pluginConfig, context) => { const { options, branch, errors, logger } = context; const { githubToken, githubUrl, githubApiPathPrefix, proxy, failComment, failTitle, labels, assignees, repositoryUrl } = (0, resolve_config_1.ResolveConfig)(pluginConfig, context); debug('options: %O', options); if (failComment === false || failTitle === false) { logger.log('Skip issue creation.'); } else { const github = (0, get_client_1.GetClient)({ githubApiPathPrefix, githubToken, githubUrl, proxy }); const [owner, repo] = (await github.repos.get((0, parse_github_url_1.ParseGitHubURL)(repositoryUrl))).data.full_name.split('/'); const body = failComment ? (0, lodash_1.template)(failComment)({ branch, errors }) : (0, get_fail_comment_1.GetFailComment)(branch, errors); const [srIssue] = await (0, find_sr_issues_1.FindSRIssues)(github, failTitle, owner, repo); if (srIssue) { logger.log('Found existing semantic-release issue #%d.', srIssue.number); const comment = { body, issue_number: srIssue.number, owner, repo }; 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 = { assignees, body: `${body}\n\n${constants_1.ISSUE_ID}`, labels: labels || [], owner, repo, title: failTitle }; debug('create issue: %O', newIssue); const { data: { html_url: url, number } } = await github.issues.create(newIssue); logger.log('Created issue #%d: %s.', number, url); } } }; exports.FailGitHub = FailGitHub; //# sourceMappingURL=fail.js.map