Merge pull request #32 from 8398a7/feature/26

[#26] If csv contains space, normalize it.
This commit is contained in:
839 2019-12-30 16:58:53 +09:00 коммит произвёл GitHub
Родитель 40a9dd2dee 7c36b2cdc8
Коммит 6a706b2cad
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 38 добавлений и 4 удалений

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

@ -246,6 +246,39 @@ describe('8398a7/action-slack', () => {
}); });
}); });
it('removes csv space', async () => {
const withParams: With = {
status: '',
mention: 'user_id, user_id2',
author_name: '',
only_mention_fail: '',
username: '',
icon_emoji: '',
icon_url: '',
channel: '',
};
let client = new Client(withParams, process.env.GITHUB_TOKEN, '');
const msg = 'hello';
let text = `<@user_id> <@user_id2> ${successMsg}\n${msg}`;
attachments[0].color = 'good';
expect(await client.success(msg)).toStrictEqual({
attachments,
text,
});
withParams.mention = '';
withParams.only_mention_fail = 'user_id, user_id2';
client = new Client(withParams, process.env.GITHUB_TOKEN, '');
text = `<@user_id> <@user_id2> ${failMsg}\n${msg}`;
attachments[0].color = 'danger';
expect(await client.fail(msg)).toStrictEqual({
attachments,
text,
});
});
it('returns the expected template', async () => { it('returns the expected template', async () => {
const withParams: With = { const withParams: With = {
status: '', status: '',

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

@ -167,10 +167,11 @@ export class Client {
} }
private mentionText(mention: string) { private mentionText(mention: string) {
if (groupMention.includes(mention)) { const normalized = mention.replace(/ /g, '');
return `<!${mention}> `; if (groupMention.includes(normalized)) {
} else if (mention !== '') { return `<!${normalized}> `;
const text = mention } else if (normalized !== '') {
const text = normalized
.split(',') .split(',')
.map(userId => `<@${userId}>`) .map(userId => `<@${userId}>`)
.join(' '); .join(' ');