UNPKG

@pagopa/danger-plugin

Version:

Shared rules for DangerJS, used in the PagoPA projects

57 lines (56 loc) 3.38 kB
"use strict"; /** * Implements methods for update a PR title and label with tickets / stories information via danger */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updatePrTitle = exports.updatePrLabel = void 0; const function_1 = require("fp-ts/lib/function"); const TE = __importStar(require("fp-ts/TaskEither")); const boolean_1 = require("fp-ts/boolean"); const ticketChangelog_1 = require("./changelog/ticketChangelog"); const titleParser_1 = require("./utils/titleParser"); const ticketParser_1 = require("./utils/ticketParser"); const updatePrLabel = (ticketList) => (configuration) => (0, function_1.pipe)(configuration.updateLabel, (0, boolean_1.match)(() => TE.right(""), () => (0, function_1.pipe)((0, ticketChangelog_1.getTicketsScope)(ticketList)(configuration), TE.fromEither, TE.chain((sc) => (0, function_1.pipe)(TE.tryCatch(() => danger.github.utils.createOrAddLabel({ name: sc, // The color is not used and can be customized from the "label" tab in the github page color: "#FFFFFF", description: sc, }), () => new Error("Error during github label update")), TE.map(() => "✅ Label added\n")))))); exports.updatePrLabel = updatePrLabel; const updatePrTitle = (ticketList) => (configuration) => (0, function_1.pipe)(configuration.updateTitle, (0, boolean_1.match)(() => TE.right(""), () => (0, function_1.pipe)((0, ticketChangelog_1.getTicketsScope)(ticketList)(configuration), TE.fromEither, TE.chain((scope) => { const tag = (0, function_1.pipe)(ticketList, ticketParser_1.getTagFromTickets); const finalTitle = (0, function_1.pipe)(danger.github.pr.title, titleParser_1.composeTitle); return (0, function_1.pipe)(TE.tryCatch(() => danger.github.api.pulls.update({ owner: danger.github.thisPR.owner, repo: danger.github.thisPR.repo, pull_number: danger.github.thisPR.number, title: `${tag}${scope}: ${finalTitle}`, }), () => new Error("Eror during github title update")), TE.map(() => (0, function_1.pipe)(ticketList, ticketParser_1.areMultipleTicketsType, (check) => check ? "⚠ Multiple stories with different types are associated with this Pull request.\n" + "Only one tag will be added, following the order: `feature > bug > chore`\n" : "✅ Title updated\n"))); })))); exports.updatePrTitle = updatePrTitle;