-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add branchName autolinks #3644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add branchName autolinks #3644
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
871a584
Add branchName autolinks
nzaytsev a76a6a2
update changelog
nzaytsev f0c137b
Fix review notes
nzaytsev e457785
Fixes comment, fixes commit message autolinks, makes index optional
axosoft-ramint 635bf2e
Fixes spacing
axosoft-ramint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as assert from 'assert'; | ||
import { suite, test } from 'mocha'; | ||
import { map } from '../../system/iterable'; | ||
import type { Autolink, RefSet } from '../autolinks'; | ||
import { Autolinks } from '../autolinks'; | ||
|
||
const mockRefSets = (prefixes: string[] = ['']): RefSet[] => | ||
prefixes.map(prefix => [ | ||
{ domain: 'test', icon: '1', id: '1', name: 'test' }, | ||
[ | ||
{ | ||
alphanumeric: false, | ||
ignoreCase: false, | ||
prefix: prefix, | ||
title: 'test', | ||
url: 'test/<num>', | ||
description: 'test', | ||
}, | ||
], | ||
]); | ||
|
||
function assertAutolinks(actual: Map<string, Autolink>, expected: Array<string>): void { | ||
assert.deepEqual([...map(actual.values(), x => x.url)], expected); | ||
} | ||
|
||
suite('Autolinks Test Suite', () => { | ||
test('Branch name autolinks', () => { | ||
assertAutolinks(Autolinks._getBranchAutolinks('123', mockRefSets()), ['test/123']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/123', mockRefSets()), ['test/123']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123', mockRefSets()), ['test/123']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('123.2', mockRefSets()), ['test/123', 'test/2']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('123', mockRefSets(['PRE-'])), []); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/123', mockRefSets(['PRE-'])), []); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']); | ||
// incorrectly solved case, maybe it worths to compare the blocks length so that the less block size (without possible link) is more likely a link | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/3', mockRefSets([''])), ['test/2', 'test/3']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123', mockRefSets(['PRE-'])), ['test/123']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123.2', mockRefSets(['PRE-'])), ['test/123']); | ||
assertAutolinks(Autolinks._getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['PRE-'])), ['test/123']); | ||
assertAutolinks( | ||
Autolinks._getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['', 'PRE-'])), | ||
|
||
['test/123', 'test/3'], | ||
); | ||
}); | ||
|
||
test('Commit message autolinks', () => { | ||
assertAutolinks(Autolinks._getAutolinks('test message 123 sd', mockRefSets()), ['test/123']); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './autolinks'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my own learning/benefit, can you explain how you formulated this regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an easy regex playground service called https://regex101.com/, I always test the regexes there before I put them to the code.
Speaking about the current regex, here I expect that the link is wrapped between any star/end (split) symbols (expecting one of [
-
,_
,.
,/
]). The both start/end symbols are the same except of regex symbols ^ and $. Then I expect that the issue key is a concatenation of the prefix and some non-zero count (+) of numbers (\d) or alphanumeric (\w)