Skip to content

Commit

Permalink
[#3] Merge branch 'master' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Jun 27, 2020
2 parents 4c9a0b0 + b0ac551 commit 0f58c8f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
57 changes: 57 additions & 0 deletions __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -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: '',
Expand Down
2 changes: 1 addition & 1 deletion docs/content/with.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|`''`|
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "action-slack",
"version": "3.2.0",
"version": "3.3.0",
"private": true,
"description": "You can notify slack of GitHub Actions.",
"main": "lib/main.js",
Expand Down
8 changes: 7 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Field {
}

const groupMention = ['here', 'channel'];
const subteamMention = 'subteam^';

export class Client {
private webhook: IncomingWebhook;
Expand Down Expand Up @@ -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,
Expand All @@ -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} `;
}
Expand Down

0 comments on commit 0f58c8f

Please sign in to comment.