Skip to content
Open

Webhook #4045

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/plugins/webhook/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

module.exports = {
url: {
describe: 'The URL where to send the webhook.',
group: 'WebHook'
},
messages: {
describe: 'Choose what type of message to send',
choices: ['budget', 'errors', 'summary'],
default: 'summary',
group: 'WebHook'
},
style: {
describe: 'How to format the content of the webhook.',
choices: ['html', 'markdown', 'text'],
default: 'text',
group: 'WebHook'
}
};
107 changes: 107 additions & 0 deletions lib/plugins/webhook/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

const newLine = '\n';
class Format {
constructor(style) {
this.style = style;
}

link(url, name) {
switch (this.style) {
case 'html':
return `<a href="${url}">${name ? name : url}</a>`;
case 'markdown':
return `[${name ? name : url}](${url})`;
default:
return url;
}
}

heading(text) {
switch (this.style) {
case 'html':
return `<h1>${text}</h1>`;
case 'markdown':
return `# ${text}`;
default:
return text;
}
}

image(url, altText) {
switch (this.style) {
case 'html':
return `<img src="${url}"></img>`;
case 'markdown':
return `![${altText}](${url})`;
default:
return url;
}
}

bold(text) {
switch (this.style) {
case 'html':
return `<b>${text}"</b>`;
case 'markdown':
return `**${text})**`;
default:
return text;
}
}

pre(text) {
switch (this.style) {
case 'html':
return `<pre>${text}"</pre>`;
case 'markdown':
return `${text})`;
default:
return text;
}
}

p(text) {
switch (this.style) {
case 'html':
return `<p>${text}"</p>`;
case 'markdown':
return `${newLine}${newLine}${text}`;
default:
return `${newLine}${newLine}${text}`;
}
}

list(text) {
switch (this.style) {
case 'html':
return `<ul>${text}"</ul>`;
default:
return text;
}
}

listItem(text) {
switch (this.style) {
case 'html':
return `<li>${text}"</li>`;
case 'markdown':
return `* ${text})`;
default:
return `* ${text} ${newLine})`;
}
}

hr() {
switch (this.style) {
case 'html':
return `<hr>`;
case 'markdown':
return `---`;
default:
return `${newLine}`;
}
}
}

module.exports = Format;
Loading