Skip to content

Commit

Permalink
fix: support usernames with multiple dashes (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Mar 13, 2024
1 parent 811c487 commit 5c1f338
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 @@ -134,7 +134,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 @@ -156,7 +156,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 5c1f338

Please sign in to comment.