UNPKG

@atomist/sdm-pack-fingerprints

Version:

an Atomist SDM Extension Pack for fingerprinting code

93 lines (90 loc) 3.67 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const automation_client_1 = require("@atomist/automation-client"); const clj_editors_1 = require("@atomist/clj-editors"); const slack_messages_1 = require("@atomist/slack-messages"); const preferences_1 = require("../adhoc/preferences"); const Aspects_1 = require("../machine/Aspects"); const util_1 = require("./util"); exports.updateableMessage = (shas, coordinate) => { return clj_editors_1.consistentHash([...shas, coordinate.owner, coordinate.repo]); }; function displayFingerprint(aspect, fp) { if (aspect.toDisplayableFingerprint) { return aspect.toDisplayableFingerprint(fp); } else { return JSON.stringify(fp.data); } } /** * get a diff summary if any registrations support one for this Fingerprint type */ function getDiffSummary(diff, target, aspect) { try { if (aspect.summary) { return aspect.summary(diff, target); } else { return { title: "Target diff", description: `from ${displayFingerprint(aspect, diff.from)} to ${displayFingerprint(aspect, diff.to)}`, }; } } catch (e) { automation_client_1.logger.warn(`failed to create summary: ${e}`); } return undefined; } exports.getDiffSummary = getDiffSummary; function applyFingerprintTitle(fp, aspects) { const aspect = Aspects_1.aspectOf(fp, aspects); if (!!aspect) { return `Apply policy for ${Aspects_1.displayName(aspect, fp)}`; } else { return `Apply policy for ${fp.name}`; } } exports.applyFingerprintTitle = applyFingerprintTitle; function prBodyFromFingerprint(fp, aspects) { const aspect = Aspects_1.aspectOf(fp, aspects); const fingerprint = preferences_1.toName(fp.type, fp.name); const intro = `Apply policy ${slack_messages_1.codeLine(fingerprint)}:`; const description = `${Aspects_1.displayName(aspect, fp)} (${Aspects_1.displayValue(aspect, fp)})`; return `${intro} ${slack_messages_1.italic(aspect.displayName)} ${slack_messages_1.codeBlock(description)}\n\n[fingerprint:${fingerprint}=${fp.sha}]`; } exports.prBodyFromFingerprint = prBodyFromFingerprint; function prBody(vote, aspects) { const title = util_1.orDefault(() => vote.summary.title, applyFingerprintTitle(vote.fpTarget, aspects)); const summary = util_1.orDefault(() => vote.summary.description, `no summary`); const fingerprint = preferences_1.toName(vote.fpTarget.type, vote.fpTarget.name); const intro = `Apply policy ${slack_messages_1.codeLine(fingerprint)}:`; const aspect = Aspects_1.aspectOf(vote.fpTarget, aspects); const description = `${Aspects_1.displayName(aspect, vote.fpTarget)} (${Aspects_1.displayValue(aspect, vote.fpTarget)})`; return `${intro} **${title}** ${summary} ${slack_messages_1.italic(aspect.displayName)} ${slack_messages_1.codeBlock(description)}\n\n[fingerprint:${fingerprint}=${vote.fpTarget.sha}]`; } exports.prBody = prBody; //# sourceMappingURL=messages.js.map