Skip to content

Commit

Permalink
fix: fix support for usernames with multiple dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored and gr2m committed May 9, 2023
1 parent 205ccee commit 8a84507
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/parse-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ nlp.plugin(plugin);

function findWho(message, action) {
function findWhoSafe(match) {
message = message.replace("-", "#/#"); // workaround (https://github.com/spencermountain/compromise/issues/726)
message = message.replace(/\-/g, "#/#"); // workaround (https://github.com/spencermountain/compromise/issues/726)
const whoNormalizeSettings = {
whitespace: true, // remove hyphens, newlines, and force one space between words
case: false, // keep only first-word, and 'entity' titlecasing
Expand All @@ -155,7 +155,7 @@ function findWho(message, action) {

if (matchedSet.length > 0) {
matchedText = matchedSet[0].text;
matchedText = matchedText.replace("#/#", "-");
matchedText = matchedText.replace(/#\/#/g, "-");

return matchedText;
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/parse-comment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ describe('parseComment', () => {
})
})

test('Basic intent to add - username with multiple dashes', () => {
expect(
parseComment(`@${testBotName} please add rishi-raj-jain for doc`),
).toEqual({
action: 'add',
contributors: {
"rishi-raj-jain": ['doc'],
},
})
})

test('Basic intent to add - with plurals', () => {
expect(
parseComment(`@${testBotName} please add dat2 for docs`),
Expand Down

0 comments on commit 8a84507

Please sign in to comment.