From 5c1f338d7dc3791861973e8171a0cbd88e1f73b6 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 13 Mar 2024 13:59:33 -0500 Subject: [PATCH] fix: support usernames with multiple dashes (#463) --- lib/parse-comment.js | 4 ++-- test/unit/parse-comment.test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/parse-comment.js b/lib/parse-comment.js index 9be62539..9c24c98c 100644 --- a/lib/parse-comment.js +++ b/lib/parse-comment.js @@ -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 @@ -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; } diff --git a/test/unit/parse-comment.test.js b/test/unit/parse-comment.test.js index 9c6902c2..56397ced 100644 --- a/test/unit/parse-comment.test.js +++ b/test/unit/parse-comment.test.js @@ -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`),