UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const ActionResult_1 = require("../../action/ActionResult");
4const gitHub_1 = require("../../util/gitHub");
5const GitHubRepoRef_1 = require("../common/GitHubRepoRef");
6/**
7 * Create an issue from a review, using Markdown
8 * @param {ProjectReview} pr
9 * @param {AllReposByDefaultParameters} params
10 * @param {string} name
11 * @return {any}
12 */
13exports.issueRaisingReviewRouter = (pr, params, name) => {
14 if (GitHubRepoRef_1.isGitHubRepoRef(pr.repoId)) {
15 const issue = toIssue(pr, name);
16 return gitHub_1.raiseIssue(params.targets.credentials.token, pr.repoId, issue)
17 .then(ap => ActionResult_1.successOn(pr.repoId));
18 }
19 else {
20 return Promise.resolve(ActionResult_1.failureOn(pr.repoId, new Error(`Not a GitHub Repo: ${JSON.stringify(pr.repoId)}`)));
21 }
22};
23function toIssue(pr, name) {
24 return {
25 title: `${pr.comments.length} problems found by ${name}`,
26 body: "Problems:\n\n" + pr.comments.map(c => toMarkdown(pr.repoId, c)).join("\n"),
27 };
28}
29function toMarkdown(grr, rc) {
30 return `-\t**${rc.severity}** - ${rc.category}: [${rc.detail}](${gitHub_1.deepLink(grr, rc.sourceLocation)})`;
31}
32//# sourceMappingURL=issueRaisingReviewRouter.js.map
\No newline at end of file