danger
Version:
Unit tests for Team Culture
77 lines • 4.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.inlineTemplate = exports.template = exports.messageForResultWithIssues = exports.dangerSignaturePostfix = exports.dangerSignature = exports.fileLineToString = exports.dangerIDToString = void 0;
// This unicode emojis also work for old versions of bitbucket server, were emojis are not supported
var noEntryEmoji = "\u274C";
var warningEmoji = "⚠️";
var messageEmoji = "\u2728";
/**
* Converts a set of violations into a Markdown section
*
* @param {string} name User facing title of section
* @param {string} emoji Emoji name to show
* @param {Violation[]} violations for section
* @returns {string} Markdown
*/
function resultsSection(name, emoji, violations) {
if (violations.length === 0 || violations.every(function (violation) { return !violation.message; })) {
return "";
}
return ("\n" +
"| ".concat(emoji, " | ").concat(name, "\n") +
"| --- | --- |\n" +
"\n" +
violations
.map(function (v) {
return ("> " +
v.message
.replace(/<\/?code>/g, "`")
.split("\n")
.join("\n> "));
})
.join("\n\n") +
"\n");
}
var dangerIDToString = function (id) { return "danger-id-".concat(id, ";"); };
exports.dangerIDToString = dangerIDToString;
var fileLineToString = function (file, line) { return " File: ".concat(file, ";\n Line: ").concat(line, ";"); };
exports.fileLineToString = fileLineToString;
var dangerSignature = function (results) {
var meta = results.meta || { runtimeName: "dangerJS", runtimeHref: "https://danger.systems/js" };
return "Generated by ".concat(warningEmoji, " [").concat(meta.runtimeName, "](").concat(meta.runtimeHref, ")");
};
exports.dangerSignature = dangerSignature;
/**
* Postfix signature to be attached comment generated / updated by danger.
*/
var dangerSignaturePostfix = function (results, commitID) {
var signature = (0, exports.dangerSignature)(results);
if (commitID !== undefined) {
signature = "".concat(signature, " against ").concat(commitID);
}
return "\n| |\n|---:|\n| _".concat(signature, "_ |\n");
};
exports.dangerSignaturePostfix = dangerSignaturePostfix;
/**
* Comment to add when updating the PR status when issues are found
*/
exports.messageForResultWithIssues = "".concat(warningEmoji, " Danger found some issues. Don't worry, everything is fixable.");
/**
* A template function for creating a GitHub issue comment from Danger Results
* @param {string} dangerID A string that represents a unique build
* @param {DangerResults} results Data to work with
* @param {string} commitID The hash that represents the latest commit
* @returns {string} HTML
*/
function template(dangerID, results, commitID) {
return "\n".concat(resultsSection("Fails", noEntryEmoji, results.fails), "\n").concat(resultsSection("Warnings", warningEmoji, results.warnings), "\n").concat(resultsSection("Messages", messageEmoji, results.messages), "\n\n").concat(results.markdowns.map(function (v) { return v.message; }).join("\n\n"), "\n\n").concat((0, exports.dangerSignaturePostfix)(results, commitID), "\n\n[](http://").concat((0, exports.dangerIDToString)(dangerID), ")\n");
}
exports.template = template;
function inlineTemplate(dangerID, results, file, line) {
var printViolation = function (emoji) { return function (violation) {
return "- ".concat(emoji, " ").concat(violation.message);
}; };
return "\n[//]: # (".concat((0, exports.dangerIDToString)(dangerID), ")\n[//]: # (").concat((0, exports.fileLineToString)(file, line), ")\n").concat(results.fails.map(printViolation(noEntryEmoji)).join("\n"), "\n").concat(results.warnings.map(printViolation(warningEmoji)).join("\n"), "\n").concat(results.messages.map(printViolation(messageEmoji)).join("\n"), "\n").concat(results.markdowns.map(function (v) { return v.message; }).join("\n\n"), "\n ");
}
exports.inlineTemplate = inlineTemplate;
//# sourceMappingURL=bitbucketServerTemplate.js.map
;