@pagopa/danger-plugin
Version:
Shared rules for DangerJS, used in the PagoPA projects
56 lines (55 loc) • 2.97 kB
JavaScript
;
/**
* Implements methods for working with ticket scopes, with the ability to search
* for common scopes both within the project and within the tags
*/
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.getTicketsScope = exports.getTicketScope = exports.getProjectScope = void 0;
const E = __importStar(require("fp-ts/Either"));
const RA = __importStar(require("fp-ts/ReadonlyArray"));
const R = __importStar(require("fp-ts/Record"));
const Rr = __importStar(require("fp-ts/Reader"));
const function_1 = require("fp-ts/lib/function");
const validator_1 = require("../utils/validator");
/**
*Try to detect the {@link Scope} of the ticket by projectId
*/
const getProjectScope = (ticket) => (configuration) => (0, function_1.pipe)(configuration.projectToScope, R.lookup(ticket.projectId), E.fromOption(() => new Error(`I can't find a scope related to the project ${ticket.projectId}`)));
exports.getProjectScope = getProjectScope;
/**
* Try to detect the {@link Scope} of the ticket by projectId
*/
const getTicketScope = (ticket) => (configuration) => (0, function_1.pipe)((0, exports.getProjectScope)(ticket)(configuration));
exports.getTicketScope = getTicketScope;
const findCommonScope = (scopes) => (0, function_1.pipe)(scopes, RA.sequence(E.Applicative), E.chain((el) => (0, validator_1.isSameScope)(el)
? (0, function_1.pipe)(RA.head(el), E.fromOption(() => new Error("I'm unable to find a common scope for this tickets")))
: E.left(new Error(`Different scopes were found on the stories related to the pull request: [${el.join(",")}].\n
It is not possible to assign a single scope to this pull request!`))));
/**
* Try to detect a common {@link Scope} for all @param tickets
*/
const getTicketsScope = (tickets) => (0, function_1.pipe)(tickets, RA.map(exports.getTicketScope), RA.sequence(Rr.Applicative), Rr.map(findCommonScope));
exports.getTicketsScope = getTicketsScope;