Skip to content

Commit

Permalink
feat: support adding people with mentions (#36)
Browse files Browse the repository at this point in the history
* feat: support adding people with mentions

* Tweak

* Improve
  • Loading branch information
sinchang authored and jakebolam committed Jan 15, 2019
1 parent f104a0a commit 5f79140
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/parse-comment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions test/utils/parse-comment/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5f79140

Please # to comment.