From 4be0ee35ea629c05dbe1ca77382854e2830e3b1c Mon Sep 17 00:00:00 2001 From: Saugat Acharya Date: Tue, 27 Feb 2024 21:35:44 +0545 Subject: [PATCH 1/3] Do not replace multiple @ when using author annotation --- .../searchAndReplaceSpecialAnnotation.test.js | 18 ++++++++++++++++++ .../lib/searchAndReplaceSpecialAnnotation.js | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/__tests__/unit/actions/lib/searchAndReplaceSpecialAnnotation.test.js b/__tests__/unit/actions/lib/searchAndReplaceSpecialAnnotation.test.js index 227140a8..0824c233 100644 --- a/__tests__/unit/actions/lib/searchAndReplaceSpecialAnnotation.test.js +++ b/__tests__/unit/actions/lib/searchAndReplaceSpecialAnnotation.test.js @@ -36,4 +36,22 @@ describe('searchAndReplaceSpecialAnnotations', () => { } expect(searchAndReplaceSpecialAnnotations('this is @author', payload)).toBe('this is creator') }) + + test('@@author is replaced by @payload.user.login', () => { + const payload = { + user: { + login: 'creator' + } + } + expect(searchAndReplaceSpecialAnnotations('this is @@author', payload)).toBe('this is @creator') + }) + + test('replaces annotation anywhere in the text', () => { + const payload = { + user: { + login: 'creator' + } + } + expect(searchAndReplaceSpecialAnnotations('this is something@author speaking', payload)).toBe('this is somethingcreator speaking') + }) }) diff --git a/lib/actions/lib/searchAndReplaceSpecialAnnotation.js b/lib/actions/lib/searchAndReplaceSpecialAnnotation.js index 45dbce00..b3edb823 100644 --- a/lib/actions/lib/searchAndReplaceSpecialAnnotation.js +++ b/lib/actions/lib/searchAndReplaceSpecialAnnotation.js @@ -6,11 +6,11 @@ const searchAndReplaceSpecialAnnotations = (template, payload) => { let newTemplate = template for (const annotation of Object.keys(SPECIAL_ANNOTATION)) { - const specialAnnotationRegex = new RegExp(`([^\\\\])${annotation}`) + const specialAnnotationRegex = new RegExp(`(? Date: Tue, 27 Feb 2024 22:12:01 +0545 Subject: [PATCH 2/3] Add changeset --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 958641e2..283bc6a6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,5 +1,6 @@ CHANGELOG ===================================== +| Feb 27, 2024: fix: search and replace of special annotations `#735 https://github.com/mergeability/mergeable/pull/735`_ | May 12, 2023: fix: Loading teams for team option of author filter/validator `#713 `_ | May 11, 2023: fix: Send correct payload for changing labels `#715 `_ | April 25, 2023: feat: Add author validator `#710 `_ From 2eb052617c4cb90d909f2c5b41dae1484e7704e7 Mon Sep 17 00:00:00 2001 From: Saugat Acharya Date: Thu, 29 Feb 2024 10:42:53 +0545 Subject: [PATCH 3/3] Format changeset following convention --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 283bc6a6..320234c6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,6 @@ CHANGELOG ===================================== -| Feb 27, 2024: fix: search and replace of special annotations `#735 https://github.com/mergeability/mergeable/pull/735`_ +| Feb 27, 2024: fix: search and replace of special annotations `#735 `_ | May 12, 2023: fix: Loading teams for team option of author filter/validator `#713 `_ | May 11, 2023: fix: Send correct payload for changing labels `#715 `_ | April 25, 2023: feat: Add author validator `#710 `_