diff --git a/README.md b/README.md index 90e1973..6318450 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ Another hacky way (no code) to find the MS Teams UPN is the following: open MS T Ignore Pull Requests with that label(s), eg: `no-reminder` or `no-reminder,ignore me` (optional). +### message-template + +The message template to render (optional). Default: `Hey {mention}, the PR "{title}" is waiting for your review: {url}`. + + ## Example usage ```yaml @@ -55,6 +60,7 @@ jobs: channel: '' # Optional, eg: #general github-provider-map: '' # Optional, eg: DavideViolante:UEABCDEFG,foobar:UAABCDEFG ignore-label: '' # Optional, eg: no-reminder,ignore me + message-template: '' # Optional, eg: Hey {mention}, the PR "{title}" is waiting for your review: {url}' ``` ## Bug or feedback? diff --git a/action.yml b/action.yml index 20edf74..c60ad2f 100644 --- a/action.yml +++ b/action.yml @@ -23,6 +23,10 @@ inputs: description: 'Ignore Pull Requests with that label' required: false default: '' + message-template: + description: 'Message template to render' + required: false + default: 'Hey {mention}, the PR "{title}" is waiting for your review: {url}' runs: using: 'node16' main: 'dist/index.js' \ No newline at end of file diff --git a/functions.js b/functions.js index 12d2b64..5da81fb 100644 --- a/functions.js +++ b/functions.js @@ -84,6 +84,20 @@ function stringToObject(str) { return map; } +/** + * Format the message to print + * @param {String} mention Username to mention as the reviewer + * @param {String} title PR title + * @param {String} url PR URL + * @param {String} messageTemplate Message template to render + */ +function formatMessage(mention, title, url, messageTemplate) { + return messageTemplate + .replace('{mention}', mention) + .replace('{title}', title) + .replace('{url}', url); +} + /** * Create a pretty message to print * @param {Array} pr2user Array of Object with these properties { url, title, login } @@ -91,7 +105,11 @@ function stringToObject(str) { * @param {String} provider Service to use: slack or msteams * @return {String} Pretty message to print */ -function prettyMessage(pr2user, github2provider, provider) { +function prettyMessage(pr2user, github2provider, provider, messageTemplate) { + if (!messageTemplate) { + messageTemplate = 'Hey {mention}, the PR "{title}" is waiting for your review: {url}'; + } + let message = ''; for (const obj of pr2user) { switch (provider) { @@ -99,21 +117,22 @@ function prettyMessage(pr2user, github2provider, provider) { const mention = github2provider[obj.login] ? `<@${github2provider[obj.login]}>` : `@${obj.login}`; - message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`; + message += messageTemplate.for + message += formatMessage(mention, title, url, messageTemplate) + "\n"; break; } case 'rocket': { const mention = github2provider[obj.login] ? `<@${github2provider[obj.login]}>` : `@${obj.login}`; - message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`; + message += formatMessage(mention, title, url, messageTemplate) + "\n"; break; } case 'msteams': { const mention = github2provider[obj.login] ? `${obj.login}` : `@${obj.login}`; - message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: [${obj.url}](${obj.url}) \n`; + message += formatMessage(mention, title, url, messageTemplate) + "\n"; break; } } diff --git a/index.js b/index.js index 75c99be..09ed700 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,7 @@ async function main() { const channel = core.getInput('channel'); const github2providerString = core.getInput('github-provider-map'); const ignoreLabel = core.getInput('ignore-label'); + const messageTemplate = core.getInput('message-template'); core.info('Getting open pull requests...'); const pullRequests = await getPullRequests(); const totalReviewers = await getPullRequestsReviewersCount(pullRequests.data); @@ -71,7 +72,7 @@ async function main() { return core.setFailed(`The github-provider-map string is not in correct format: "name1:id1,name2:id2,..."`); } const github2provider = stringToObject(github2providerString); - const messageText = prettyMessage(pr2user, github2provider, provider); + const messageText = prettyMessage(pr2user, github2provider, provider, messageTemplate); let messageObject; switch (provider) { case 'slack':