From 5f7914062f153bc3aadb8c654699f9d9ff6e19b5 Mon Sep 17 00:00:00 2001 From: Jeff Wen Date: Tue, 15 Jan 2019 23:32:22 +0800 Subject: [PATCH] feat: support adding people with mentions (#36) * feat: support adding people with mentions * Tweak * Improve --- src/utils/parse-comment/index.js | 4 +++- test/utils/parse-comment/index.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/parse-comment/index.js b/src/utils/parse-comment/index.js index c3bfdfbe..ce2a0b5b 100644 --- a/src/utils/parse-comment/index.js +++ b/src/utils/parse-comment/index.js @@ -57,7 +57,7 @@ const plugin = { nlp.plugin(plugin) function parseAddComment(doc, action) { - const who = doc + const whoMatched = doc .match(`${action} [.]`) .normalize({ whitespace: true, // remove hyphens, newlines, and force one space between words @@ -75,6 +75,8 @@ function parseAddComment(doc, action) { }) .data()[0].text + const who = whoMatched.startsWith('@') ? whoMatched.substr(1) : whoMatched + // TODO: handle plurals (e.g. some said docs) let contributions = doc .match('#Contribution') diff --git a/test/utils/parse-comment/index.test.js b/test/utils/parse-comment/index.test.js index 69e06caa..cf150f34 100644 --- a/test/utils/parse-comment/index.test.js +++ b/test/utils/parse-comment/index.test.js @@ -55,6 +55,18 @@ describe('parseComment', () => { }) }) + test('Support adding people with mentions', () => { + expect( + parseComment( + `@${testBotName} please add @sinchang for infrastructure`, + ), + ).toEqual({ + action: 'add', + who: 'sinchang', + contributions: ['infra'], + }) + }) + // TODO: make it so this works // test('Support split words (like user testing)', () => { // expect(