Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook #4045

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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';

Check failure on line 1 in lib/plugins/webhook/cli.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not use "use strict" directive

module.exports = {

Check failure on line 3 in lib/plugins/webhook/cli.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not use "module"
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';

Check failure on line 1 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not use "use strict" directive

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

link(url, name) {
switch (this.style) {
case 'html':

Check failure on line 11 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing braces in case clause
return `<a href="${url}">${name ? name : url}</a>`;

Check failure on line 12 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Prefer using a logical operator over a ternary
case 'markdown':

Check failure on line 13 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing braces in case clause
return `[${name ? name : url}](${url})`;

Check failure on line 14 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Prefer using a logical operator over a ternary
default:

Check failure on line 15 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing braces in case clause
return url;
}
}

heading(text) {
switch (this.style) {
case 'html':

Check failure on line 22 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing braces in case clause
return `<h1>${text}</h1>`;
case 'markdown':

Check failure on line 24 in lib/plugins/webhook/format.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing braces in case clause
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
Loading