Skip to content

Commit 5f79140

Browse files
sinchangjakebolam
authored andcommitted
feat: support adding people with mentions (#36)
* feat: support adding people with mentions * Tweak * Improve
1 parent f104a0a commit 5f79140

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/utils/parse-comment/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const plugin = {
5757
nlp.plugin(plugin)
5858

5959
function parseAddComment(doc, action) {
60-
const who = doc
60+
const whoMatched = doc
6161
.match(`${action} [.]`)
6262
.normalize({
6363
whitespace: true, // remove hyphens, newlines, and force one space between words
@@ -75,6 +75,8 @@ function parseAddComment(doc, action) {
7575
})
7676
.data()[0].text
7777

78+
const who = whoMatched.startsWith('@') ? whoMatched.substr(1) : whoMatched
79+
7880
// TODO: handle plurals (e.g. some said docs)
7981
let contributions = doc
8082
.match('#Contribution')

test/utils/parse-comment/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ describe('parseComment', () => {
5555
})
5656
})
5757

58+
test('Support adding people with mentions', () => {
59+
expect(
60+
parseComment(
61+
`@${testBotName} please add @sinchang for infrastructure`,
62+
),
63+
).toEqual({
64+
action: 'add',
65+
who: 'sinchang',
66+
contributions: ['infra'],
67+
})
68+
})
69+
5870
// TODO: make it so this works
5971
// test('Support split words (like user testing)', () => {
6072
// expect(

0 commit comments

Comments
 (0)