Merge pull request #74 from nileshr/user-group-mention

Allow User Group Mentions
This commit is contained in:
839 2020-06-27 19:11:22 +09:00 коммит произвёл GitHub
Родитель ba323e2a1a a567092bda
Коммит 1ccfa85b17
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 65 добавлений и 2 удалений

Просмотреть файл

@ -443,6 +443,44 @@ describe('8398a7/action-slack', () => {
expect(await client.success(msg)).toStrictEqual(payload);
});
it('mentions a user group', async () => {
const withParams: With = {
status: '',
mention: 'subteam^user_group_id',
author_name: '',
if_mention: Success,
username: '',
icon_emoji: '',
icon_url: '',
channel: '',
fields: '',
};
const client = new Client(withParams, process.env.GITHUB_TOKEN, '');
const msg = 'mention test';
const payload = getTemplate(client, `<!subteam^user_group_id> ${msg}`);
payload.attachments[0].color = 'good';
expect(await client.success(msg)).toStrictEqual(payload);
});
it('mentions multiple user groups', async () => {
const withParams: With = {
status: '',
mention: 'subteam^user_group_id,subteam^user_group_id2',
author_name: '',
if_mention: Success,
username: '',
icon_emoji: '',
icon_url: '',
channel: '',
fields: '',
};
const client = new Client(withParams, process.env.GITHUB_TOKEN, '');
const msg = 'mention test';
const payload = getTemplate(client, `<!subteam^user_group_id> <!subteam^user_group_id2> ${msg}`);
payload.attachments[0].color = 'good';
expect(await client.success(msg)).toStrictEqual(payload);
});
it('mentions multiple users', async () => {
const withParams: With = {
status: '',
@ -462,6 +500,25 @@ describe('8398a7/action-slack', () => {
expect(await client.success(msg)).toStrictEqual(payload);
});
it('mentions mix of user and user group', async () => {
const withParams: With = {
status: '',
mention: 'user_id,subteam^user_group_id',
author_name: '',
if_mention: Success,
username: '',
icon_emoji: '',
icon_url: '',
channel: '',
fields: '',
};
const client = new Client(withParams, process.env.GITHUB_TOKEN, '');
const msg = 'mention test';
const payload = getTemplate(client, `<@user_id> <!subteam^user_group_id> ${msg}`);
payload.attachments[0].color = 'good';
expect(await client.success(msg)).toStrictEqual(payload);
});
it('removes csv space', async () => {
const withParams: With = {
status: '',

Просмотреть файл

@ -14,7 +14,7 @@ This page describes the elements that can be specified in with.
|[fields](/with#fields)|You can choose the items you want to add to the fields at the time of notification.|`'repo,commit'`|
|[text](/with#text)|Specify the text you want to add.|`''`|
|[author_name](/with#author_name)|It can be overwritten by specifying. The job name is recommend.|`'8398a7@action-slack'`|
|[mention](/with#mention)|`'here'` or `'channel'` or [user_id](https://api.slack.com/reference/surfaces/formatting#mentioning-users)|`''`|
|[mention](/with#mention)|`'here'` or `'channel'` or [user_group_id](https://api.slack.com/reference/surfaces/formatting#mentioning-groups) or [user_id](https://api.slack.com/reference/surfaces/formatting#mentioning-users)|`''`|
|[if_mention](/with#mention)|Specify `'success'` or `'failure'` or `'cancelled'` or `'custom'` or `'always'`.|`''`|
|[username](/with#username)|Override the legacy integration's default name.|`''`|
|[icon_emoji](/with#icon_emoji)|[emoji code](https://www.webfx.com/tools/emoji-cheat-sheet/) string to use in place of the default icon.|`''`|

Просмотреть файл

@ -31,6 +31,7 @@ export interface Field {
}
const groupMention = ['here', 'channel'];
const subteamMention = 'subteam^';
export class Client {
private webhook: IncomingWebhook;
@ -288,6 +289,11 @@ export class Client {
};
}
private getIdString(id: string): string {
if (id.includes(subteamMention)) return `<!${id}>`;
else return `<@${id}>`;
}
private mentionText(
mention: string,
status: SuccessType | FailureType | CancelledType | AlwaysType,
@ -305,7 +311,7 @@ export class Client {
} else if (normalized !== '') {
const text = normalized
.split(',')
.map(userId => `<@${userId}>`)
.map(id => this.getIdString(id))
.join(' ');
return `${text} `;
}