mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 06:19:53 +11:00
new build
This commit is contained in:
parent
06b07c2e70
commit
09331f990d
6 changed files with 133 additions and 45 deletions
88
dist/index.js
vendored
88
dist/index.js
vendored
|
|
@ -7,8 +7,8 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.createComment = exports.deleteComment = exports.updateComment = exports.getExistingCommentId = void 0;
|
exports.createComment = exports.deleteComment = exports.updateComment = exports.getExistingComment = void 0;
|
||||||
async function getExistingCommentId(octokit, owner, repo, issueNumber, messageId) {
|
async function getExistingComment(octokit, owner, repo, issueNumber, messageId) {
|
||||||
const parameters = {
|
const parameters = {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
|
|
@ -25,9 +25,13 @@ async function getExistingCommentId(octokit, owner, repo, issueNumber, messageId
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found === null || found === void 0 ? void 0 : found.id;
|
if (found) {
|
||||||
|
const { id, body } = found;
|
||||||
|
return { id, body };
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
exports.getExistingCommentId = getExistingCommentId;
|
exports.getExistingComment = getExistingComment;
|
||||||
async function updateComment(octokit, owner, repo, existingCommentId, body) {
|
async function updateComment(octokit, owner, repo, existingCommentId, body) {
|
||||||
const updatedComment = await octokit.rest.issues.updateComment({
|
const updatedComment = await octokit.rest.issues.updateComment({
|
||||||
comment_id: existingCommentId,
|
comment_id: existingCommentId,
|
||||||
|
|
@ -100,6 +104,8 @@ async function getInputs() {
|
||||||
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
||||||
const messageInput = core.getInput('message', { required: false });
|
const messageInput = core.getInput('message', { required: false });
|
||||||
const messagePath = core.getInput('message-path', { required: false });
|
const messagePath = core.getInput('message-path', { required: false });
|
||||||
|
const messageFind = core.getMultilineInput('find', { required: false });
|
||||||
|
const messageReplace = core.getMultilineInput('replace', { required: false });
|
||||||
const repoOwner = core.getInput('repo-owner', { required: true });
|
const repoOwner = core.getInput('repo-owner', { required: true });
|
||||||
const repoName = core.getInput('repo-name', { required: true });
|
const repoName = core.getInput('repo-name', { required: true });
|
||||||
const repoToken = core.getInput('repo-token', { required: true });
|
const repoToken = core.getInput('repo-token', { required: true });
|
||||||
|
|
@ -129,6 +135,8 @@ async function getInputs() {
|
||||||
messageCancelled,
|
messageCancelled,
|
||||||
messageSkipped,
|
messageSkipped,
|
||||||
messagePath,
|
messagePath,
|
||||||
|
messageFind,
|
||||||
|
messageReplace,
|
||||||
preformatted,
|
preformatted,
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
||||||
|
|
@ -265,9 +273,9 @@ const message_1 = __nccwpck_require__(3307);
|
||||||
const proxy_1 = __nccwpck_require__(8689);
|
const proxy_1 = __nccwpck_require__(8689);
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
try {
|
try {
|
||||||
const { allowRepeats, messagePath, messageInput, messageId, refreshMessagePosition, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, updateOnly, messageCancelled, messageFailure, messageSuccess, messageSkipped, preformatted, status, } = await (0, config_1.getInputs)();
|
const { allowRepeats, messagePath, messageInput, messageId, refreshMessagePosition, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, updateOnly, messageCancelled, messageFailure, messageSuccess, messageSkipped, preformatted, status, messageFind, messageReplace, } = await (0, config_1.getInputs)();
|
||||||
const octokit = github.getOctokit(repoToken);
|
const octokit = github.getOctokit(repoToken);
|
||||||
const message = await (0, message_1.getMessage)({
|
let message = await (0, message_1.getMessage)({
|
||||||
messagePath,
|
messagePath,
|
||||||
messageInput,
|
messageInput,
|
||||||
messageSkipped,
|
messageSkipped,
|
||||||
|
|
@ -293,25 +301,31 @@ const run = async () => {
|
||||||
core.setOutput('comment-created', 'false');
|
core.setOutput('comment-created', 'false');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let existingCommentId;
|
let existingComment;
|
||||||
if (!allowRepeats) {
|
if (!allowRepeats) {
|
||||||
core.debug('repeat comments are disallowed, checking for existing');
|
core.debug('repeat comments are disallowed, checking for existing');
|
||||||
existingCommentId = await (0, comments_1.getExistingCommentId)(octokit, owner, repo, issueNumber, messageId);
|
existingComment = await (0, comments_1.getExistingComment)(octokit, owner, repo, issueNumber, messageId);
|
||||||
if (existingCommentId) {
|
if (existingComment) {
|
||||||
core.debug(`existing comment found with id: ${existingCommentId}`);
|
core.debug(`existing comment found with id: ${existingComment.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no existing comment and updateOnly is true, exit
|
// if no existing comment and updateOnly is true, exit
|
||||||
if (!existingCommentId && updateOnly) {
|
if (!existingComment && updateOnly) {
|
||||||
core.info('no existing comment found and update-only is true, exiting');
|
core.info('no existing comment found and update-only is true, exiting');
|
||||||
core.setOutput('comment-created', 'false');
|
core.setOutput('comment-created', 'false');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let comment;
|
let comment;
|
||||||
const body = `${messageId}\n\n${message}`;
|
if ((messageFind === null || messageFind === void 0 ? void 0 : messageFind.length) && ((messageReplace === null || messageReplace === void 0 ? void 0 : messageReplace.length) || message) && (existingComment === null || existingComment === void 0 ? void 0 : existingComment.body)) {
|
||||||
|
message = (0, message_1.findAndReplaceInMessage)(messageFind, (messageReplace === null || messageReplace === void 0 ? void 0 : messageReplace.length) ? messageReplace : [message], (0, message_1.removeMessageHeader)(existingComment.body));
|
||||||
|
}
|
||||||
|
if (!message) {
|
||||||
|
throw new Error('no message, check your message inputs');
|
||||||
|
}
|
||||||
|
const body = (0, message_1.addMessageHeader)(messageId, message);
|
||||||
if (proxyUrl) {
|
if (proxyUrl) {
|
||||||
comment = await (0, proxy_1.createCommentProxy)({
|
comment = await (0, proxy_1.createCommentProxy)({
|
||||||
commentId: existingCommentId,
|
commentId: existingComment === null || existingComment === void 0 ? void 0 : existingComment.id,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issueNumber,
|
issueNumber,
|
||||||
|
|
@ -319,15 +333,15 @@ const run = async () => {
|
||||||
repoToken,
|
repoToken,
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
});
|
});
|
||||||
core.setOutput(existingCommentId ? 'comment-updated' : 'comment-created', 'true');
|
core.setOutput((existingComment === null || existingComment === void 0 ? void 0 : existingComment.id) ? 'comment-updated' : 'comment-created', 'true');
|
||||||
}
|
}
|
||||||
else if (existingCommentId) {
|
else if (existingComment === null || existingComment === void 0 ? void 0 : existingComment.id) {
|
||||||
if (refreshMessagePosition) {
|
if (refreshMessagePosition) {
|
||||||
await (0, comments_1.deleteComment)(octokit, owner, repo, existingCommentId, body);
|
await (0, comments_1.deleteComment)(octokit, owner, repo, existingComment.id, body);
|
||||||
comment = await (0, comments_1.createComment)(octokit, owner, repo, issueNumber, body);
|
comment = await (0, comments_1.createComment)(octokit, owner, repo, issueNumber, body);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingCommentId, body);
|
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingComment.id, body);
|
||||||
}
|
}
|
||||||
core.setOutput('comment-updated', 'true');
|
core.setOutput('comment-updated', 'true');
|
||||||
}
|
}
|
||||||
|
|
@ -371,7 +385,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getMessageFromPath = exports.getMessage = void 0;
|
exports.findAndReplaceInMessage = exports.removeMessageHeader = exports.addMessageHeader = exports.getMessageFromPath = exports.getMessage = void 0;
|
||||||
const promises_1 = __importDefault(__nccwpck_require__(3977));
|
const promises_1 = __importDefault(__nccwpck_require__(3977));
|
||||||
const files_1 = __nccwpck_require__(1743);
|
const files_1 = __nccwpck_require__(1743);
|
||||||
async function getMessage({ messageInput, messagePath, messageCancelled, messageSkipped, messageFailure, messageSuccess, preformatted, status, }) {
|
async function getMessage({ messageInput, messagePath, messageCancelled, messageSkipped, messageFailure, messageSuccess, preformatted, status, }) {
|
||||||
|
|
@ -396,13 +410,10 @@ async function getMessage({ messageInput, messagePath, messageCancelled, message
|
||||||
message = messageInput;
|
message = messageInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!message) {
|
|
||||||
throw new Error('no message, check your message inputs');
|
|
||||||
}
|
|
||||||
if (preformatted) {
|
if (preformatted) {
|
||||||
message = `\`\`\`\n${message}\n\`\`\``;
|
message = `\`\`\`\n${message}\n\`\`\``;
|
||||||
}
|
}
|
||||||
return message;
|
return message !== null && message !== void 0 ? message : '';
|
||||||
}
|
}
|
||||||
exports.getMessage = getMessage;
|
exports.getMessage = getMessage;
|
||||||
async function getMessageFromPath(searchPath) {
|
async function getMessageFromPath(searchPath) {
|
||||||
|
|
@ -417,6 +428,39 @@ async function getMessageFromPath(searchPath) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
exports.getMessageFromPath = getMessageFromPath;
|
exports.getMessageFromPath = getMessageFromPath;
|
||||||
|
function addMessageHeader(messageId, message) {
|
||||||
|
return `${messageId}\n\n${message}`;
|
||||||
|
}
|
||||||
|
exports.addMessageHeader = addMessageHeader;
|
||||||
|
function removeMessageHeader(message) {
|
||||||
|
return message.split('\n').slice(2).join('\n');
|
||||||
|
}
|
||||||
|
exports.removeMessageHeader = removeMessageHeader;
|
||||||
|
function splitFind(find) {
|
||||||
|
const matches = find.match(/\/((i|g|m|s|u|y){1,6})$/);
|
||||||
|
if (!matches) {
|
||||||
|
return {
|
||||||
|
regExp: find,
|
||||||
|
modifiers: 'gi',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const [, modifiers] = matches;
|
||||||
|
const regExp = find.replace(modifiers, '').slice(0, -1);
|
||||||
|
return {
|
||||||
|
regExp,
|
||||||
|
modifiers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function findAndReplaceInMessage(find, replacement, original) {
|
||||||
|
var _a;
|
||||||
|
let message = original;
|
||||||
|
for (const [i, f] of find.entries()) {
|
||||||
|
const { regExp, modifiers } = splitFind(f);
|
||||||
|
message = message.replace(new RegExp(regExp, modifiers), (_a = replacement[i]) !== null && _a !== void 0 ? _a : replacement[0]);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
exports.findAndReplaceInMessage = findAndReplaceInMessage;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.createComment = exports.deleteComment = exports.updateComment = exports.getExistingCommentId = void 0;
|
exports.createComment = exports.deleteComment = exports.updateComment = exports.getExistingComment = void 0;
|
||||||
async function getExistingCommentId(octokit, owner, repo, issueNumber, messageId) {
|
async function getExistingComment(octokit, owner, repo, issueNumber, messageId) {
|
||||||
const parameters = {
|
const parameters = {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
|
|
@ -18,9 +18,13 @@ async function getExistingCommentId(octokit, owner, repo, issueNumber, messageId
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found === null || found === void 0 ? void 0 : found.id;
|
if (found) {
|
||||||
|
const { id, body } = found;
|
||||||
|
return { id, body };
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
exports.getExistingCommentId = getExistingCommentId;
|
exports.getExistingComment = getExistingComment;
|
||||||
async function updateComment(octokit, owner, repo, existingCommentId, body) {
|
async function updateComment(octokit, owner, repo, existingCommentId, body) {
|
||||||
const updatedComment = await octokit.rest.issues.updateComment({
|
const updatedComment = await octokit.rest.issues.updateComment({
|
||||||
comment_id: existingCommentId,
|
comment_id: existingCommentId,
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ async function getInputs() {
|
||||||
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
||||||
const messageInput = core.getInput('message', { required: false });
|
const messageInput = core.getInput('message', { required: false });
|
||||||
const messagePath = core.getInput('message-path', { required: false });
|
const messagePath = core.getInput('message-path', { required: false });
|
||||||
|
const messageFind = core.getMultilineInput('find', { required: false });
|
||||||
|
const messageReplace = core.getMultilineInput('replace', { required: false });
|
||||||
const repoOwner = core.getInput('repo-owner', { required: true });
|
const repoOwner = core.getInput('repo-owner', { required: true });
|
||||||
const repoName = core.getInput('repo-name', { required: true });
|
const repoName = core.getInput('repo-name', { required: true });
|
||||||
const repoToken = core.getInput('repo-token', { required: true });
|
const repoToken = core.getInput('repo-token', { required: true });
|
||||||
|
|
@ -61,6 +63,8 @@ async function getInputs() {
|
||||||
messageCancelled,
|
messageCancelled,
|
||||||
messageSkipped,
|
messageSkipped,
|
||||||
messagePath,
|
messagePath,
|
||||||
|
messageFind,
|
||||||
|
messageReplace,
|
||||||
preformatted,
|
preformatted,
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
||||||
|
|
|
||||||
32
lib/main.js
32
lib/main.js
|
|
@ -32,9 +32,9 @@ const message_1 = require("./message");
|
||||||
const proxy_1 = require("./proxy");
|
const proxy_1 = require("./proxy");
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
try {
|
try {
|
||||||
const { allowRepeats, messagePath, messageInput, messageId, refreshMessagePosition, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, updateOnly, messageCancelled, messageFailure, messageSuccess, messageSkipped, preformatted, status, } = await (0, config_1.getInputs)();
|
const { allowRepeats, messagePath, messageInput, messageId, refreshMessagePosition, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, updateOnly, messageCancelled, messageFailure, messageSuccess, messageSkipped, preformatted, status, messageFind, messageReplace, } = await (0, config_1.getInputs)();
|
||||||
const octokit = github.getOctokit(repoToken);
|
const octokit = github.getOctokit(repoToken);
|
||||||
const message = await (0, message_1.getMessage)({
|
let message = await (0, message_1.getMessage)({
|
||||||
messagePath,
|
messagePath,
|
||||||
messageInput,
|
messageInput,
|
||||||
messageSkipped,
|
messageSkipped,
|
||||||
|
|
@ -60,25 +60,31 @@ const run = async () => {
|
||||||
core.setOutput('comment-created', 'false');
|
core.setOutput('comment-created', 'false');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let existingCommentId;
|
let existingComment;
|
||||||
if (!allowRepeats) {
|
if (!allowRepeats) {
|
||||||
core.debug('repeat comments are disallowed, checking for existing');
|
core.debug('repeat comments are disallowed, checking for existing');
|
||||||
existingCommentId = await (0, comments_1.getExistingCommentId)(octokit, owner, repo, issueNumber, messageId);
|
existingComment = await (0, comments_1.getExistingComment)(octokit, owner, repo, issueNumber, messageId);
|
||||||
if (existingCommentId) {
|
if (existingComment) {
|
||||||
core.debug(`existing comment found with id: ${existingCommentId}`);
|
core.debug(`existing comment found with id: ${existingComment.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no existing comment and updateOnly is true, exit
|
// if no existing comment and updateOnly is true, exit
|
||||||
if (!existingCommentId && updateOnly) {
|
if (!existingComment && updateOnly) {
|
||||||
core.info('no existing comment found and update-only is true, exiting');
|
core.info('no existing comment found and update-only is true, exiting');
|
||||||
core.setOutput('comment-created', 'false');
|
core.setOutput('comment-created', 'false');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let comment;
|
let comment;
|
||||||
const body = `${messageId}\n\n${message}`;
|
if ((messageFind === null || messageFind === void 0 ? void 0 : messageFind.length) && ((messageReplace === null || messageReplace === void 0 ? void 0 : messageReplace.length) || message) && (existingComment === null || existingComment === void 0 ? void 0 : existingComment.body)) {
|
||||||
|
message = (0, message_1.findAndReplaceInMessage)(messageFind, (messageReplace === null || messageReplace === void 0 ? void 0 : messageReplace.length) ? messageReplace : [message], (0, message_1.removeMessageHeader)(existingComment.body));
|
||||||
|
}
|
||||||
|
if (!message) {
|
||||||
|
throw new Error('no message, check your message inputs');
|
||||||
|
}
|
||||||
|
const body = (0, message_1.addMessageHeader)(messageId, message);
|
||||||
if (proxyUrl) {
|
if (proxyUrl) {
|
||||||
comment = await (0, proxy_1.createCommentProxy)({
|
comment = await (0, proxy_1.createCommentProxy)({
|
||||||
commentId: existingCommentId,
|
commentId: existingComment === null || existingComment === void 0 ? void 0 : existingComment.id,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issueNumber,
|
issueNumber,
|
||||||
|
|
@ -86,15 +92,15 @@ const run = async () => {
|
||||||
repoToken,
|
repoToken,
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
});
|
});
|
||||||
core.setOutput(existingCommentId ? 'comment-updated' : 'comment-created', 'true');
|
core.setOutput((existingComment === null || existingComment === void 0 ? void 0 : existingComment.id) ? 'comment-updated' : 'comment-created', 'true');
|
||||||
}
|
}
|
||||||
else if (existingCommentId) {
|
else if (existingComment === null || existingComment === void 0 ? void 0 : existingComment.id) {
|
||||||
if (refreshMessagePosition) {
|
if (refreshMessagePosition) {
|
||||||
await (0, comments_1.deleteComment)(octokit, owner, repo, existingCommentId, body);
|
await (0, comments_1.deleteComment)(octokit, owner, repo, existingComment.id, body);
|
||||||
comment = await (0, comments_1.createComment)(octokit, owner, repo, issueNumber, body);
|
comment = await (0, comments_1.createComment)(octokit, owner, repo, issueNumber, body);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingCommentId, body);
|
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingComment.id, body);
|
||||||
}
|
}
|
||||||
core.setOutput('comment-updated', 'true');
|
core.setOutput('comment-updated', 'true');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getMessageFromPath = exports.getMessage = void 0;
|
exports.findAndReplaceInMessage = exports.removeMessageHeader = exports.addMessageHeader = exports.getMessageFromPath = exports.getMessage = void 0;
|
||||||
const promises_1 = __importDefault(require("node:fs/promises"));
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
||||||
const files_1 = require("./files");
|
const files_1 = require("./files");
|
||||||
async function getMessage({ messageInput, messagePath, messageCancelled, messageSkipped, messageFailure, messageSuccess, preformatted, status, }) {
|
async function getMessage({ messageInput, messagePath, messageCancelled, messageSkipped, messageFailure, messageSuccess, preformatted, status, }) {
|
||||||
|
|
@ -28,13 +28,10 @@ async function getMessage({ messageInput, messagePath, messageCancelled, message
|
||||||
message = messageInput;
|
message = messageInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!message) {
|
|
||||||
throw new Error('no message, check your message inputs');
|
|
||||||
}
|
|
||||||
if (preformatted) {
|
if (preformatted) {
|
||||||
message = `\`\`\`\n${message}\n\`\`\``;
|
message = `\`\`\`\n${message}\n\`\`\``;
|
||||||
}
|
}
|
||||||
return message;
|
return message !== null && message !== void 0 ? message : '';
|
||||||
}
|
}
|
||||||
exports.getMessage = getMessage;
|
exports.getMessage = getMessage;
|
||||||
async function getMessageFromPath(searchPath) {
|
async function getMessageFromPath(searchPath) {
|
||||||
|
|
@ -49,3 +46,36 @@ async function getMessageFromPath(searchPath) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
exports.getMessageFromPath = getMessageFromPath;
|
exports.getMessageFromPath = getMessageFromPath;
|
||||||
|
function addMessageHeader(messageId, message) {
|
||||||
|
return `${messageId}\n\n${message}`;
|
||||||
|
}
|
||||||
|
exports.addMessageHeader = addMessageHeader;
|
||||||
|
function removeMessageHeader(message) {
|
||||||
|
return message.split('\n').slice(2).join('\n');
|
||||||
|
}
|
||||||
|
exports.removeMessageHeader = removeMessageHeader;
|
||||||
|
function splitFind(find) {
|
||||||
|
const matches = find.match(/\/((i|g|m|s|u|y){1,6})$/);
|
||||||
|
if (!matches) {
|
||||||
|
return {
|
||||||
|
regExp: find,
|
||||||
|
modifiers: 'gi',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const [, modifiers] = matches;
|
||||||
|
const regExp = find.replace(modifiers, '').slice(0, -1);
|
||||||
|
return {
|
||||||
|
regExp,
|
||||||
|
modifiers,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function findAndReplaceInMessage(find, replacement, original) {
|
||||||
|
var _a;
|
||||||
|
let message = original;
|
||||||
|
for (const [i, f] of find.entries()) {
|
||||||
|
const { regExp, modifiers } = splitFind(f);
|
||||||
|
message = message.replace(new RegExp(regExp, modifiers), (_a = replacement[i]) !== null && _a !== void 0 ? _a : replacement[0]);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
exports.findAndReplaceInMessage = findAndReplaceInMessage;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue