Skip to content

Commit 5274d40

Browse files
committed
Merge branch 'master' of github.com:mergeability/mergeable
2 parents e19395e + c6d0d68 commit 5274d40

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

__tests__/unit/actions/lib/searchAndReplaceSpecialAnnotation.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,22 @@ describe('searchAndReplaceSpecialAnnotations', () => {
3636
}
3737
expect(searchAndReplaceSpecialAnnotations('this is @author', payload)).toBe('this is creator')
3838
})
39+
40+
test('@@author is replaced by @payload.user.login', () => {
41+
const payload = {
42+
user: {
43+
login: 'creator'
44+
}
45+
}
46+
expect(searchAndReplaceSpecialAnnotations('this is @@author', payload)).toBe('this is @creator')
47+
})
48+
49+
test('replaces annotation anywhere in the text', () => {
50+
const payload = {
51+
user: {
52+
login: 'creator'
53+
}
54+
}
55+
expect(searchAndReplaceSpecialAnnotations('this is something@author speaking', payload)).toBe('this is somethingcreator speaking')
56+
})
3957
})

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CHANGELOG
22
=====================================
3+
| Feb 27, 2024: fix: search and replace of special annotations `#735 <https://github.com/mergeability/mergeable/pull/735>`_
34
| May 12, 2023: fix: Loading teams for team option of author filter/validator `#713 <https://github.com/mergeability/mergeable/pull/713>`_
45
| May 11, 2023: fix: Send correct payload for changing labels `#715 <https://github.com/mergeability/mergeable/pull/715>`_
56
| April 25, 2023: feat: Add author validator `#710 <https://github.com/mergeability/mergeable/pull/710>`_

docs/recipes.rst

+6-11
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,17 @@ Checks that the PR's draft state is false before running actions.
212212
mergeable:
213213
- when: pull_request.*, pull_request_review.*
214214
name: 'Draft check'
215-
validate:
215+
filter:
216216
- do: payload
217217
pull_request:
218218
draft:
219219
boolean:
220220
match: false
221-
pass:
222-
- do: comment
223-
payload:
224-
body: This PR is NOT a draft!
225-
fail:
226-
- do: comment
227-
payload:
228-
body: This PR is STILL a draft!
229-
230-
221+
validate:
222+
- do: description
223+
no_empty:
224+
enabled: true
225+
message: Description must be present when PR is not a draft
231226

232227

233228
Allow commits only if they contain a Issue ID (like an Azure DevOps Work Item)

lib/actions/lib/searchAndReplaceSpecialAnnotation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const searchAndReplaceSpecialAnnotations = (template, payload) => {
66
let newTemplate = template
77

88
for (const annotation of Object.keys(SPECIAL_ANNOTATION)) {
9-
const specialAnnotationRegex = new RegExp(`([^\\\\])${annotation}`)
9+
const specialAnnotationRegex = new RegExp(`(?<!\\\\)${annotation}`)
1010
const annotationAtStartRegex = new RegExp(`^${annotation}`)
1111
const escapeAnnotationRegex = new RegExp(`(\\\\){1}${annotation}`)
1212

13-
newTemplate = newTemplate.replace(specialAnnotationRegex, ` ${SPECIAL_ANNOTATION[annotation](payload)}`)
13+
newTemplate = newTemplate.replace(specialAnnotationRegex, `${SPECIAL_ANNOTATION[annotation](payload)}`)
1414
newTemplate = newTemplate.replace(escapeAnnotationRegex, annotation)
1515
newTemplate = newTemplate.replace(annotationAtStartRegex, SPECIAL_ANNOTATION[annotation](payload))
1616
}

0 commit comments

Comments
 (0)