Added own custom message and mentions.
Some checks failed
Linter / eslint (push) Has been cancelled
Some checks failed
Linter / eslint (push) Has been cancelled
This commit is contained in:
parent
00ac13e905
commit
18ea2450af
277330
dist/index.js
vendored
277330
dist/index.js
vendored
File diff suppressed because one or more lines are too long
43
index.js
43
index.js
@ -1,4 +1,5 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
const github = require('@actions/github');
|
||||||
const sdk = require('matrix-js-sdk');
|
const sdk = require('matrix-js-sdk');
|
||||||
const md = require('markdown-it')();
|
const md = require('markdown-it')();
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ try {
|
|||||||
const channel = core.getInput('channel');
|
const channel = core.getInput('channel');
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
const message = core.getInput('message');
|
const message = core.getInput('message');
|
||||||
|
const status = core.getInput('status');
|
||||||
const messagetype = core.getInput('messagetype');
|
const messagetype = core.getInput('messagetype');
|
||||||
|
|
||||||
// Debug output
|
// Debug output
|
||||||
@ -14,8 +16,19 @@ try {
|
|||||||
core.info(`channel: ${channel}`);
|
core.info(`channel: ${channel}`);
|
||||||
core.info(`token: ${token}`);
|
core.info(`token: ${token}`);
|
||||||
core.info(`message: ${message}`);
|
core.info(`message: ${message}`);
|
||||||
|
core.info(`status: ${status}`);
|
||||||
core.info(`messagetype: ${messagetype}`);
|
core.info(`messagetype: ${messagetype}`);
|
||||||
|
|
||||||
|
const ctx = github.context;
|
||||||
|
|
||||||
|
const { owner, repo } = ctx.repo;
|
||||||
|
const {
|
||||||
|
workflow, actor, payload, serverUrl, runNumber,
|
||||||
|
} = ctx;
|
||||||
|
|
||||||
|
const repoURL = `${serverUrl}/${owner}/${repo}`;
|
||||||
|
const runURL = `${repoURL}/actions/runs/${runNumber}`;
|
||||||
|
|
||||||
// Create client object
|
// Create client object
|
||||||
const client = sdk.createClient({
|
const client = sdk.createClient({
|
||||||
baseUrl: `https://${homeserver}`,
|
baseUrl: `https://${homeserver}`,
|
||||||
@ -27,17 +40,41 @@ try {
|
|||||||
core.info('Joined channel');
|
core.info('Joined channel');
|
||||||
});
|
});
|
||||||
|
|
||||||
// render markdown in message
|
const statusOpts = {
|
||||||
const processedMessage = md.render(message);
|
success: {
|
||||||
|
status: 'Success',
|
||||||
|
color: 0x28A745,
|
||||||
|
},
|
||||||
|
failure: {
|
||||||
|
status: 'Failure',
|
||||||
|
color: 0xCB2431,
|
||||||
|
},
|
||||||
|
cancelled: {
|
||||||
|
status: 'Cancelled',
|
||||||
|
color: 0xDBAB09,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const userMention = status === 'success' ? actor : `<a href="https://matrix.to/#/@${actor}:${homeserver}">${actor}</a>`;
|
||||||
|
|
||||||
|
const formattedMessage = `
|
||||||
|
<h4 style="color: ${statusOpts[status].color}">${statusOpts[status].status} ${workflow.name}</h4>
|
||||||
|
<p><strong>Repository</strong> <a href="${repoURL}">${owner}/${repo}</a><br>
|
||||||
|
<strong>Commit</strong> <a href="${payload.head_commit.url}">${payload.head_commit.id.substring(0, 7)}</a> ${payload.head_commit.message}<br>
|
||||||
|
<strong>Triggered by</strong> ${userMention}<br>
|
||||||
|
<strong>Run</strong> <a href="${runURL}">#${runNumber}</a><br>
|
||||||
|
${md.render(message)}`;
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
const content = {
|
const content = {
|
||||||
msgtype: messagetype,
|
msgtype: messagetype,
|
||||||
format: 'org.matrix.custom.html',
|
format: 'org.matrix.custom.html',
|
||||||
body: message,
|
body: message,
|
||||||
formatted_body: processedMessage,
|
formatted_body: formattedMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (status === 'success') content['m.mentions'] = { user_ids: [`@${actor}:${homeserver}`] };
|
||||||
|
|
||||||
client.sendEvent(channel, 'm.room.message', content, '').then(() => {
|
client.sendEvent(channel, 'm.room.message', content, '').then(() => {
|
||||||
// message sent successfully
|
// message sent successfully
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user