Skip to content

Commit

Permalink
Add rocket chat support (#103)
Browse files Browse the repository at this point in the history
* Add Rocket (#1)

* Remove workflows

* Fix offenses
  • Loading branch information
armandfardeau authored Apr 17, 2023
1 parent ba34f53 commit cf7bb41
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 70 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/pr-reviews-reminder-msteams-mention.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/pr-reviews-reminder-msteams.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Pull Request reviews reminder action
[![](https://github.com/davideviolante/pr-reviews-reminder-action/workflows/Node.js%20CI/badge.svg)](https://github.com/DavideViolante/pr-reviews-reminder-action/actions?query=workflow%3A%22Node.js+CI%22) [![Coverage Status](https://coveralls.io/repos/github/DavideViolante/pr-reviews-reminder-action/badge.svg?branch=master)](https://coveralls.io/github/DavideViolante/pr-reviews-reminder-action?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/60f9b3a6b4177a0bfe77/maintainability)](https://codeclimate.com/github/DavideViolante/pr-reviews-reminder-action/maintainability) [![Donate](https://img.shields.io/badge/paypal-donate-179BD7.svg)](https://www.paypal.me/dviolante)

Action to send Slack/Teams notifications when there are pull requests pending for reviews.
Action to send Slack/Rocket/Teams notifications when there are pull requests pending for reviews.

## Preview
![Preview](https://raw.githubusercontent.com/DavideViolante/pr-reviews-reminder-action/master/preview.png "Preview")
Expand All @@ -14,7 +14,7 @@ The webhook URL (required). More info [here (Slack)](https://api.slack.com/messa

### provider

Chat provider, `slack` or `msteams` (required). Default `slack`.
Chat provider, `slack`, `Rocket` or `msteams` (required). Default `slack`.

### channel

Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
webhook-url: '' # Required
provider: '' # Required (slack or msteams)
provider: '' # Required (slack, rocket or msteams)
channel: '' # Optional, eg: #general
github-provider-map: '' # Optional, eg: DavideViolante:UEABCDEFG,foobar:UAABCDEFG
ignore-label: '' # Optional, eg: no-reminder,ignore me
Expand Down
121 changes: 84 additions & 37 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ function prettyMessage(pr2user, github2provider, provider) {
message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`;
break;
}
case 'rocket': {
const mention = github2provider[obj.login] ?
`<@${github2provider[obj.login]}>` :
`@${obj.login}`;
message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`;
break;
}
case 'msteams': {
const mention = github2provider[obj.login] ?
`<at>${obj.login}</at>` :
Expand Down Expand Up @@ -163,6 +170,21 @@ function formatSlackMessage(channel, message) {
return messageData;
}

/**
* Formats channel and rocket message text into a request object
* @param {String} channel channel to send the message to
* @param {String} message rocket message text
* @return {Object} rocket message data object
*/
function formatRocketMessage(channel, message) {
const messageData = {
channel: channel,
username: 'Pull Request reviews reminder',
text: message,
};
return messageData;
}

/**
* Format the MS Teams message request object
* Docs: https://bit.ly/3UlOoqo
Expand Down Expand Up @@ -209,6 +231,7 @@ module.exports = {
prettyMessage,
getTeamsMentions,
formatTeamsMessage,
formatRocketMessage,
formatSlackMessage,
};

Expand Down Expand Up @@ -6470,14 +6493,15 @@ module.exports = require("zlib");
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

"use strict";
// Axios v1.3.0 Copyright (c) 2023 Matt Zabriskie and contributors
// Axios v1.3.4 Copyright (c) 2023 Matt Zabriskie and contributors


const FormData$1 = __nccwpck_require__(4334);
const url = __nccwpck_require__(7310);
const proxyFromEnv = __nccwpck_require__(3329);
const http = __nccwpck_require__(3685);
const https = __nccwpck_require__(5687);
const util = __nccwpck_require__(3837);
const followRedirects = __nccwpck_require__(7707);
const zlib = __nccwpck_require__(9796);
const stream = __nccwpck_require__(2781);
Expand All @@ -6489,6 +6513,7 @@ const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);
const url__default = /*#__PURE__*/_interopDefaultLegacy(url);
const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
const https__default = /*#__PURE__*/_interopDefaultLegacy(https);
const util__default = /*#__PURE__*/_interopDefaultLegacy(util);
const followRedirects__default = /*#__PURE__*/_interopDefaultLegacy(followRedirects);
const zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
const stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
Expand Down Expand Up @@ -7450,7 +7475,7 @@ function toFormData(obj, formData, options) {
value = JSON.stringify(value);
} else if (
(utils.isArray(value) && isFlatArray(value)) ||
(utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value))
)) {
// eslint-disable-next-line no-param-reassign
key = removeBrackets(key);
Expand Down Expand Up @@ -8051,11 +8076,15 @@ function isValidHeaderName(str) {
return /^[-_a-zA-Z]+$/.test(str.trim());
}

function matchHeaderValue(context, value, header, filter) {
function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
if (utils.isFunction(filter)) {
return filter.call(this, value, header);
}

if (isHeaderNameFilter) {
value = header;
}

if (!utils.isString(value)) return;

if (utils.isString(filter)) {
Expand Down Expand Up @@ -8159,7 +8188,7 @@ class AxiosHeaders {
if (header) {
const key = utils.findKey(this, header);

return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
}

return false;
Expand Down Expand Up @@ -8199,7 +8228,7 @@ class AxiosHeaders {

while (i--) {
const key = keys[i];
if(!matcher || matchHeaderValue(this, this[key], key, matcher)) {
if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
delete this[key];
deleted = true;
}
Expand Down Expand Up @@ -8418,7 +8447,7 @@ function buildFullPath(baseURL, requestedURL) {
return requestedURL;
}

const VERSION = "1.3.0";
const VERSION = "1.3.4";

function parseProtocol(url) {
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
Expand Down Expand Up @@ -8758,7 +8787,7 @@ const readBlob$1 = readBlob;

const BOUNDARY_ALPHABET = utils.ALPHABET.ALPHA_DIGIT + '-_';

const textEncoder = new TextEncoder();
const textEncoder = new util.TextEncoder();

const CRLF = '\r\n';
const CRLF_BYTES = textEncoder.encode(CRLF);
Expand Down Expand Up @@ -8980,25 +9009,47 @@ function setProxy(options, configProxy, location) {

const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';

// temporary hotfix

const wrapAsync = (asyncExecutor) => {
return new Promise((resolve, reject) => {
let onDone;
let isDone;

const done = (value, isRejected) => {
if (isDone) return;
isDone = true;
onDone && onDone(value, isRejected);
};

const _resolve = (value) => {
done(value);
resolve(value);
};

const _reject = (reason) => {
done(reason, true);
reject(reason);
};

asyncExecutor(_resolve, _reject, (onDoneHandler) => (onDone = onDoneHandler)).catch(_reject);
})
};

/*eslint consistent-return:0*/
const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
let data = config.data;
const responseType = config.responseType;
const responseEncoding = config.responseEncoding;
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
let {data} = config;
const {responseType, responseEncoding} = config;
const method = config.method.toUpperCase();
let isFinished;
let isDone;
let rejected = false;
let req;

// temporary internal emitter until the AxiosRequest class will be implemented
const emitter = new EventEmitter__default["default"]();

function onFinished() {
if (isFinished) return;
isFinished = true;

const onFinished = () => {
if (config.cancelToken) {
config.cancelToken.unsubscribe(abort);
}
Expand All @@ -9008,28 +9059,15 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
}

emitter.removeAllListeners();
}

function done(value, isRejected) {
if (isDone) return;
};

onDone((value, isRejected) => {
isDone = true;

if (isRejected) {
rejected = true;
onFinished();
}

isRejected ? rejectPromise(value) : resolvePromise(value);
}

const resolve = function resolve(value) {
done(value);
};

const reject = function reject(value) {
done(value, true);
};
});

function abort(reason) {
emitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
Expand All @@ -9046,7 +9084,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {

// Parse url
const fullPath = buildFullPath(config.baseURL, config.url);
const parsed = new URL(fullPath);
const parsed = new URL(fullPath, 'http://localhost');
const protocol = parsed.protocol || supportedProtocols[0];

if (protocol === 'data:') {
Expand All @@ -9073,7 +9111,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
convertedData = convertedData.toString(responseEncoding);

if (!responseEncoding || responseEncoding === 'utf8') {
data = utils.stripBOM(convertedData);
convertedData = utils.stripBOM(convertedData);
}
} else if (responseType === 'stream') {
convertedData = stream__default["default"].Readable.from(convertedData);
Expand Down Expand Up @@ -9123,9 +9161,14 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
// support for https://www.npmjs.com/package/form-data api
} else if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
headers.set(data.getHeaders());
if (utils.isFunction(data.getLengthSync)) { // check if the undocumented API exists
const knownLength = data.getLengthSync();
!utils.isUndefined(knownLength) && headers.setContentLength(knownLength, false);

if (!headers.hasContentLength()) {
try {
const knownLength = await util__default["default"].promisify(data.getLength).call(data);
Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
/*eslint no-empty:0*/
} catch (e) {
}
}
} else if (utils.isBlob(data)) {
data.size && headers.setContentType(data.type || 'application/octet-stream');
Expand Down Expand Up @@ -10707,6 +10750,7 @@ const {
stringToObject,
getTeamsMentions,
formatSlackMessage,
formatRocketMessage,
formatTeamsMessage,
} = __nccwpck_require__(3505);

Expand Down Expand Up @@ -10771,6 +10815,9 @@ async function main() {
case 'slack':
messageObject = formatSlackMessage(channel, messageText);
break;
case 'rocket':
messageObject = formatRocketMessage(channel, messageText);
break;
case 'msteams': {
const msTeamsMentions = getTeamsMentions(github2provider, pr2user);
messageObject = formatTeamsMessage(messageText, msTeamsMentions);
Expand Down
23 changes: 23 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ function prettyMessage(pr2user, github2provider, provider) {
message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`;
break;
}
case 'rocket': {
const mention = github2provider[obj.login] ?
`<@${github2provider[obj.login]}>` :
`@${obj.login}`;
message += `Hey ${mention}, the PR "${obj.title}" is waiting for your review: ${obj.url}\n`;
break;
}
case 'msteams': {
const mention = github2provider[obj.login] ?
`<at>${obj.login}</at>` :
Expand Down Expand Up @@ -157,6 +164,21 @@ function formatSlackMessage(channel, message) {
return messageData;
}

/**
* Formats channel and rocket message text into a request object
* @param {String} channel channel to send the message to
* @param {String} message rocket message text
* @return {Object} rocket message data object
*/
function formatRocketMessage(channel, message) {
const messageData = {
channel: channel,
username: 'Pull Request reviews reminder',
text: message,
};
return messageData;
}

/**
* Format the MS Teams message request object
* Docs: https://bit.ly/3UlOoqo
Expand Down Expand Up @@ -203,5 +225,6 @@ module.exports = {
prettyMessage,
getTeamsMentions,
formatTeamsMessage,
formatRocketMessage,
formatSlackMessage,
};
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
stringToObject,
getTeamsMentions,
formatSlackMessage,
formatRocketMessage,
formatTeamsMessage,
} = require('./functions');

Expand Down Expand Up @@ -76,6 +77,9 @@ async function main() {
case 'slack':
messageObject = formatSlackMessage(channel, messageText);
break;
case 'rocket':
messageObject = formatRocketMessage(channel, messageText);
break;
case 'msteams': {
const msTeamsMentions = getTeamsMentions(github2provider, pr2user);
messageObject = formatTeamsMessage(messageText, msTeamsMentions);
Expand Down
Loading

0 comments on commit cf7bb41

Please sign in to comment.