Skip to content

Commit 9e2d2e6

Browse files
authored
feat: add alternative annotation pattern GUS-W- (#168)
This commit adds an alternative annotation pattern, `GUS-W-`, to be used to identify a work item. The reason for this is that GitHub autolinks (https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/configuring-autolinks-to-reference-external-resources#configuring-autolinks-to-reference-external-resources) do not support patterns that begin with symbols (such as `@`). In order to keep auto linking _and_ enable git2gus, we add support for this additional pattern. The pattern is case sensitive to help avoid issues with words ending with "gus" e.g. `argus`, `bogus`, `asparagus`.
1 parent 2e8f9d9 commit 9e2d2e6

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

api/services/Issues/__test__/getAnnotation.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ describe('getAnnotation issues service', () => {
1313
'@W-12345678@',
1414
'some text @W-12345678@',
1515
'text@W-12345678@',
16-
'some @W-12345678@ text'
16+
'some @W-12345678@ text',
17+
'GUS-W-12345678',
18+
'some text GUS-W-12345678',
19+
'some GUS-W-12345678 text'
1720
];
1821
descriptions.forEach(description => {
1922
expect(getAnnotation(description)).toBe('W-12345678');
@@ -27,6 +30,8 @@ describe('getAnnotation issues service', () => {
2730
'@W12345678@',
2831
'some text W-12345678@',
2932
'text@W-12345678',
33+
'GAS-W-12345678',
34+
'textGUS-W-12345678',
3035
'',
3136
null,
3237
undefined,

api/services/Issues/__test__/isSameAnnotation.spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@
88
const isSameAnnotation = require('../isSameAnnotation');
99

1010
describe('isSameAnnotation issues service', () => {
11+
const annotations = ['@W-12345@', 'GUS-W-12345'];
12+
1113
it('should return true when is same annotation', () => {
1214
const descriptions = [
1315
'@W-12345@',
1416
'some text @W-12345@',
1517
'text@W-12345@',
1618
'some @W-12345@ text',
17-
'some@W-12345@text'
19+
'some@W-12345@text',
20+
'GUS-W-12345',
21+
'some text GUS-W-12345',
22+
'some GUS-W-12345 text'
1823
];
1924
descriptions.forEach(description => {
20-
expect(isSameAnnotation(description, '@W-12345@')).toBe(true);
25+
annotations.forEach(annotation => {
26+
expect(isSameAnnotation(description, annotation)).toBe(true);
27+
});
2128
});
2229
});
2330
it('should return false when is not the same annotation', () => {
@@ -30,6 +37,9 @@ describe('isSameAnnotation issues service', () => {
3037
'@W12345@',
3138
'some text W-12345@',
3239
'text@W-12345',
40+
'GUS-W-12345678',
41+
'some text GUS-W-12345678',
42+
'some GUS-W-12345678 text',
3343
'',
3444
null,
3545
undefined,
@@ -38,7 +48,9 @@ describe('isSameAnnotation issues service', () => {
3848
12345
3949
];
4050
descriptions.forEach(description => {
41-
expect(isSameAnnotation(description, '@W-12345@')).toBe(false);
51+
annotations.forEach(annotation => {
52+
expect(isSameAnnotation(description, annotation)).toBe(false);
53+
});
4254
});
4355
});
4456
it('should return false when both descriptions passed are null', () => {

api/services/Issues/getAnnotation.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66
*/
77

88
module.exports = function getAnnotation(description) {
9+
const annotationMatchers = [
10+
{
11+
rex: /@w-\d+@/gi,
12+
replace: /@/g
13+
},
14+
{
15+
rex: /\bGUS-W-\d+\b/g,
16+
replace: /GUS-/g
17+
}
18+
];
19+
920
if (typeof description === 'string') {
10-
const matches = description.match(/@w-\d+@/gi);
11-
if (Array.isArray(matches) && matches.length > 0) {
12-
return matches[0].replace(/@/g, '');
21+
const matches = [];
22+
annotationMatchers.forEach(matcher => {
23+
let candidates = description.match(matcher.rex);
24+
if (Array.isArray(candidates) && candidates.length > 0) {
25+
matches.push(candidates[0].replace(matcher.replace, ''));
26+
}
27+
});
28+
29+
if (matches.length > 0) {
30+
return matches[0];
1331
}
1432
return null;
1533
}

0 commit comments

Comments
 (0)