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
291362
dist/index.js
vendored
291362
dist/index.js
vendored
File diff suppressed because one or more lines are too long
45
index.js
45
index.js
@ -1,4 +1,5 @@
|
||||
const core = require('@actions/core');
|
||||
const github = require('@actions/github');
|
||||
const sdk = require('matrix-js-sdk');
|
||||
const md = require('markdown-it')();
|
||||
|
||||
@ -7,6 +8,7 @@ try {
|
||||
const channel = core.getInput('channel');
|
||||
const token = core.getInput('token');
|
||||
const message = core.getInput('message');
|
||||
const status = core.getInput('status');
|
||||
const messagetype = core.getInput('messagetype');
|
||||
|
||||
// Debug output
|
||||
@ -14,8 +16,19 @@ try {
|
||||
core.info(`channel: ${channel}`);
|
||||
core.info(`token: ${token}`);
|
||||
core.info(`message: ${message}`);
|
||||
core.info(`status: ${status}`);
|
||||
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
|
||||
const client = sdk.createClient({
|
||||
baseUrl: `https://${homeserver}`,
|
||||
@ -27,19 +40,43 @@ try {
|
||||
core.info('Joined channel');
|
||||
});
|
||||
|
||||
// render markdown in message
|
||||
const processedMessage = md.render(message);
|
||||
const statusOpts = {
|
||||
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
|
||||
const content = {
|
||||
msgtype: messagetype,
|
||||
format: 'org.matrix.custom.html',
|
||||
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(() => {
|
||||
// message sent successfully
|
||||
// message sent successfully
|
||||
}).catch((err) => {
|
||||
core.error(err);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user