Compare commits

..

7 Commits

10 changed files with 217840 additions and 73697 deletions

View File

@ -1,11 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"

View File

@ -1,18 +0,0 @@
{
"problemMatcher": [
{
"owner": "eslint-compact",
"pattern": [
{
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}

View File

@ -1,22 +0,0 @@
{
"problemMatcher": [
{
"owner": "eslint-stylish",
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
]
}

17
.github/tsc.json vendored
View File

@ -1,17 +0,0 @@
{
"problemMatcher": [
{
"owner": "tsc",
"pattern": [
{
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
]
}
]
}

View File

@ -1,13 +0,0 @@
name: Linter
on: [push, pull_request]
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- run: npm ci
- run: ./node_modules/.bin/eslint -c ./.eslintrc.json -f compact *.js

View File

@ -17,9 +17,10 @@ inputs:
message:
description: 'The message you want to send'
required: true
messagetype:
description: 'Type of Matrix message (e.g. `m.text` or `m.notice`)'
default: 'm.notice'
status:
description: "Job status. Should be bound to job.status. Default to success."
required: false
default: ${{ job.status }}
runs:
using: 'node12'
main: 'dist/index.js'

275467
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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,14 +8,24 @@ try {
const channel = core.getInput('channel');
const token = core.getInput('token');
const message = core.getInput('message');
const messagetype = core.getInput('messagetype');
const status = core.getInput('status');
// Debug output
core.info(`homeserver: ${homeserver}`);
core.info(`channel: ${channel}`);
core.info(`token: ${token}`);
core.info(`message: ${message}`);
core.info(`messagetype: ${messagetype}`);
core.info(`status: ${status}`);
const ctx = github.context;
const { owner, repo } = ctx.repo;
const {
ref, workflow, actor, payload, serverUrl, runNumber,
} = ctx;
const repoURL = `${serverUrl}/${owner}/${repo}`;
const runURL = `${repoURL}/actions/runs/${runNumber}`;
// Create client object
const client = sdk.createClient({
@ -27,17 +38,42 @@ 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 data-mx-color="${statusOpts[status].color}">${statusOpts[status].status} ${workflow}</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>Ref</strong> ${ref}<br>
<strong>Triggered by</strong> ${userMention}<br>
<strong>Run</strong> <a href="${runURL}">#${runNumber}</a>
${md.render(message)}`;
// Send message
const content = {
msgtype: messagetype,
msgtype: (status === 'success') ? 'm.notice' : 'm.text',
format: 'org.matrix.custom.html',
body: message,
formatted_body: processedMessage,
body: `${statusOpts[status].status} ${workflow} @${actor}`,
formatted_body: formattedMessage,
};
if (status !== 'success') content['m.mentions'] = { user_ids: [`@${actor}:${homeserver}`] };
client.sendEvent(channel, 'm.room.message', content, '').then(() => {
// message sent successfully
}).catch((err) => {

20
package-lock.json generated
View File

@ -57,9 +57,9 @@
}
},
"@babel/runtime": {
"version": "7.24.7",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.7.tgz",
"integrity": "sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==",
"version": "7.24.5",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.5.tgz",
"integrity": "sha512-Nms86NXrsaeU9vbBJKni6gXiEXZ4CVpYVzEjDH9Sb8vmZ3UljyA1GSOJl/6LGPO8EHLuSF9H+IxNXHPX8QHJ4g==",
"requires": {
"regenerator-runtime": "^0.14.0"
}
@ -131,9 +131,9 @@
"dev": true
},
"@matrix-org/matrix-sdk-crypto-wasm": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-5.0.0.tgz",
"integrity": "sha512-37ASjCKSTU5ycGfkP+LUXG4Ok6OAf6vE+1qU6uwWhe6FwadCS3vVWzJYd/3d9BQFwsx4GhFTIAXrW4iLG85rmQ=="
"version": "4.9.0",
"resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.9.0.tgz",
"integrity": "sha512-/bgA4QfE7qkK6GFr9hnhjAvRSebGrmEJxukU0ukbudZcYvbzymoBBM8j3HeULXZT8kbw8WH6z63txYTMCBSDOA=="
},
"@nodelib/fs.scandir": {
"version": "2.1.5",
@ -2871,12 +2871,12 @@
"integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA=="
},
"matrix-js-sdk": {
"version": "33.1.0",
"resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-33.1.0.tgz",
"integrity": "sha512-Spf+g156eK+SqPd7EuulTVwpyHkVXR0Ikme04fMCKer+SbzuLPPnqV3gL5cSyTMmHbdNejEJaEvzNIMQoD7Xxw==",
"version": "32.2.0",
"resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-32.2.0.tgz",
"integrity": "sha512-LnfJNq5nMF/R+Wigv7dP+Q6I/D5zKHOIdGg9mYyQmhpLc+skWLCtjqa4cLH+hq5CUyppQXMuPH/FFQaGQQ3ImA==",
"requires": {
"@babel/runtime": "^7.12.5",
"@matrix-org/matrix-sdk-crypto-wasm": "^5.0.0",
"@matrix-org/matrix-sdk-crypto-wasm": "^4.9.0",
"another-json": "^0.2.0",
"bs58": "^5.0.0",
"content-type": "^1.0.4",

View File

@ -21,7 +21,7 @@
"@actions/github": "^6.0.0",
"@vercel/ncc": "^0.38.1",
"markdown-it": "^14.1.0",
"matrix-js-sdk": "^33.1.0"
"matrix-js-sdk": "^32.2.0"
},
"devDependencies": {
"eslint": "^8.57.0",