Skip to content

Commit

Permalink
fix: allow hypens for username matching in parseComment (#307)
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Bolam <jake.bolam@gmail.com>
  • Loading branch information
baikho and jakebolam committed Apr 28, 2020
1 parent 13b89b3 commit bb1ff3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tasks/processIssueComment/utils/parse-comment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ function parseAddComment(message, action) {
const whoMatched = nlp(message)
.match(`${action} [.]`)
.normalize({
whitespace: true, // remove hyphens, newlines, and force one space between words
// We cannot use whitespace: true, because that gets rid of trailing hyphens.
whitespace: false, // remove hyphens, newlines, and force one space between words
case: false, // keep only first-word, and 'entity' titlecasing
numbers: false, // turn 'seven' to '7'
punctuation: true, // remove commas, semicolons - but keep sentence-ending punctuation
Expand All @@ -129,7 +130,8 @@ function parseAddComment(message, action) {
verbs: false, // turn all verbs into Infinitive form - "I walked" → "I walk"
honorifics: false, //turn 'Vice Admiral John Smith' to 'John Smith'
})
.data()[0].text
.data()[0]
.text.replace(/\s/g, '')

const who = whoMatched.startsWith('@') ? whoMatched.substr(1) : whoMatched

Expand Down
20 changes: 20 additions & 0 deletions test/tasks/processIssueComment/utils/parse-comment/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,24 @@ describe('parseComment', () => {
action: false,
})
})

test('Ensure (trailing) hyphens are not discarded', () => {
expect(
parseComment(`@${testBotName} please add @jakebolam- for testing`),
).toEqual({
action: 'add',
who: 'jakebolam-',
contributions: ['test'],
})

expect(
parseComment(
`@${testBotName} please add @jakebolam-jakebolam for bugs, ideas`,
),
).toEqual({
action: 'add',
who: 'jakebolam-jakebolam',
contributions: ['bug', 'ideas'],
})
})
})

0 comments on commit bb1ff3a

Please sign in to comment.