Skip to content
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

Improves branch autolinks experiments #3898

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-prefix = ''
30 changes: 29 additions & 1 deletion ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ This project incorporates components from the projects listed below.
27. react version 16.8.4 (https://github.com/facebook/react)
28. signal-utils version 0.20.0 (https://github.com/proposal-signals/signal-utils)
29. slug version 10.0.0 (https://github.com/Trott/slug)
30. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)
30. slugify version 1.6.6 (https://github.com/simov/slugify)
31. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)

%% @gk-nzaytsev/fast-string-truncated-width NOTICES AND INFORMATION BEGIN HERE
=========================================
Expand Down Expand Up @@ -2219,6 +2220,33 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
=========================================
END OF slug NOTICES AND INFORMATION

%% slugify NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)

Copyright (c) Simeon Velichkov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=========================================
END OF slugify NOTICES AND INFORMATION

%% sortablejs NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20030,6 +20030,7 @@
"react-dom": "16.8.4",
"signal-utils": "0.20.0",
"slug": "10.0.0",
"slugify": "1.6.6",
"sortablejs": "1.15.0"
},
"devDependencies": {
Expand All @@ -20047,7 +20048,7 @@
"@types/sortablejs": "1.15.8",
"@types/vscode": "1.82.0",
"@typescript-eslint/parser": "8.18.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-cli": "0.0.10",
"@vscode/test-electron": "2.4.1",
"@vscode/test-web": "0.0.65",
"@vscode/vsce": "3.2.1",
Expand Down
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 102 additions & 21 deletions src/autolinks/__tests__/autolinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,131 @@ import * as assert from 'assert';
import { suite, test } from 'mocha';
import { map } from '../../system/iterable';
import type { Autolink, RefSet } from '../autolinks.utils';
import { getAutolinks, getBranchAutolinks } from '../autolinks.utils';
import { calculatePriority, getAutolinks, getBranchAutolinks } from '../autolinks.utils';

const mockRefSets = (prefixes: string[] = ['']): RefSet[] =>
const mockRefSets = (prefixes: string[] = [''], title = 'test'): RefSet[] =>
prefixes.map(prefix => [
{ domain: 'test', icon: '1', id: '1', name: 'test' },
[
{
alphanumeric: false,
ignoreCase: false,
prefix: prefix,
title: 'test',
url: 'test/<num>',
title: title,
url: '<num>',
description: 'test',
},
],
]);

function assertAutolinks(actual: Map<string, Autolink>, expected: Array<string>): void {
assert.deepEqual([...map(actual.values(), x => x.url)], expected);
function assertAutolinks(actual: Map<string, Autolink>, expected: Array<string>, message: string): void {
assert.deepEqual([...map(actual.values(), x => x.url)], expected, message);
}

suite('Autolinks Test Suite', () => {
test('Branch name autolinks', () => {
assertAutolinks(getBranchAutolinks('123', mockRefSets()), ['test/123']);
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets()), ['test/123']);
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets()), ['test/123']);
assertAutolinks(getBranchAutolinks('123.2', mockRefSets()), ['test/123', 'test/2']);
assertAutolinks(getBranchAutolinks('123', mockRefSets(['PRE-'])), []);
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets(['PRE-'])), []);
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
// incorrectly solved cat worths to compare the blocks length so that the less block size (without possible link) is more likely a link
assertAutolinks(getBranchAutolinks('feature/2-fa/3', mockRefSets([''])), ['test/2', 'test/3']);
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets(['PRE-'])), ['test/123']);
assertAutolinks(getBranchAutolinks('feature/PRE-123.2', mockRefSets(['PRE-'])), ['test/123']);
assertAutolinks(getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['PRE-'])), ['test/123']);
assertAutolinks(getBranchAutolinks('123', mockRefSets()), ['123'], 'test-1');
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets()), ['123'], 'test-2');
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets()), ['123'], 'test-3');
assertAutolinks(getBranchAutolinks('123.2', mockRefSets()), ['123'], 'test-4');
assertAutolinks(getBranchAutolinks('123', mockRefSets(['PRE-'])), [], 'test-5');
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets(['PRE-'])), [], 'test-6');
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['123', '2'], 'test-7');
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['123', '2'], 'test-8');
assertAutolinks(getBranchAutolinks('feature/2-fa/3', mockRefSets([''])), ['3', '2'], 'test-9');
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets(['PRE-'])), ['123'], 'test-10');
assertAutolinks(getBranchAutolinks('feature/PRE-123.2', mockRefSets(['PRE-'])), ['123'], 'test-11');
assertAutolinks(getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['PRE-'])), ['123'], 'test-12');
assertAutolinks(
getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['', 'PRE-'])),

['test/123', 'test/3'],
['123', '3'],
'test-13',
);
});

test('Commit message autolinks', () => {
assertAutolinks(getAutolinks('test message 123 sd', mockRefSets()), ['test/123']);
assertAutolinks(getAutolinks('test message 123 sd', mockRefSets()), ['123'], 'test-14');
});

test('Test autolink priority comparation', () => {
assert.equal(calculatePriority('1', 0, '1', 1) > calculatePriority('1', 0, '1', 0), true, 'test-15');
assert.equal(calculatePriority('1', 0, '1', 2) > calculatePriority('1', 1, '1', 0), true, 'test-16');
assert.equal(calculatePriority('1', 0, '1', 2) > calculatePriority('1', 0, '1.1', 2), true, 'test-17');
assert.equal(calculatePriority('2', 0, '2', 2) > calculatePriority('1', 0, '1', 2), true, 'test-19');
});
/**
* 16.1.1^ - improved branch name autolinks matching
*/
test('Improved branch name autolinks matching', () => {
// skip branch names chunks matching '^release(?=(-(?<number-chunk>))$` or other release-like values
// skip pair in case of double chunk
assertAutolinks(getBranchAutolinks('folder/release/16/issue-1', mockRefSets([''])), ['1'], 'test-20');
assertAutolinks(getBranchAutolinks('folder/release/16.1/issue-1', mockRefSets([''])), ['1'], 'test-21');
assertAutolinks(getBranchAutolinks('folder/release/16.1.1/1', mockRefSets([''])), ['1'], 'test-22');
assertAutolinks(getBranchAutolinks('release-2024', mockRefSets([''])), [], 'test-23');
assertAutolinks(getBranchAutolinks('v-2024', mockRefSets([''])), [], 'test-24');
assertAutolinks(getBranchAutolinks('v2024', mockRefSets([''])), [], 'test-25');
// cannot be definitely handled
assertAutolinks(getBranchAutolinks('some-issue-in-release-2024', mockRefSets([''])), ['2024'], 'test-26');
assertAutolinks(getBranchAutolinks('folder/release-notes-16-1', mockRefSets([''])), ['16'], 'test-27');
assertAutolinks(getBranchAutolinks('folder/16-1-release-notes', mockRefSets([''])), ['16'], 'test-28');
// skip next in case of single chunk
assertAutolinks(getBranchAutolinks('folder/release-16/1', mockRefSets([''])), ['1'], 'test-29');
assertAutolinks(getBranchAutolinks('folder/release-16.1/1', mockRefSets([''])), ['1'], 'test-30');
assertAutolinks(getBranchAutolinks('folder/release-16.1.2/1', mockRefSets([''])), ['1'], 'test-31');

/**
* Added chunk matching logic for non-prefixed numbers:
* - XX - is more likely issue number
* - XX.XX - is less likely issue number, but still possible
* - XX.XX.XX - is more likely not issue number: seems like a date or version number
*/
assertAutolinks(getBranchAutolinks('issue-2024', mockRefSets([''])), ['2024'], 'test-32');
assertAutolinks(getBranchAutolinks('issue-2024.1', mockRefSets([''])), ['2024'], 'test-33');
assertAutolinks(getBranchAutolinks('issue-2024.1.1', mockRefSets([''])), [], 'test-34');

// the chunk that is more close to the end is more likely actual issue number
assertAutolinks(
getBranchAutolinks('1-epic-folder/10-issue/100-subissue', mockRefSets([''])),
['100', '10', '1'],
'test-35',
);

// ignore numbers from title
assertAutolinks(
getBranchAutolinks('folder/100-content-content-16', mockRefSets([''], '100-content-content')),
['16'],
'test-36',
);
assertAutolinks(
getBranchAutolinks('folder/100-content-content-16', mockRefSets([''], 'content-content-16')),
['100'],
'test-37',
);

// consider edge distance and issue key length to sort
assertAutolinks(
getBranchAutolinks('2-some-issue-in-release-2024', mockRefSets([''])),
['2024', '2'],
'test-38',
);
assertAutolinks(
getBranchAutolinks('2024-some-issue-in-release-2', mockRefSets([''])),
['2024', '2'],
'test-39',
);
assertAutolinks(
getBranchAutolinks('some-2-issue-in-release-2024', mockRefSets([''])),
['2024', '2'],
'test-40',
);
assertAutolinks(
getBranchAutolinks('4048-issue-in-release-2024.1', mockRefSets([''])),
['4048', '2024'],
'test-41',
);
// less numbers - more likely issue key
assertAutolinks(getBranchAutolinks('1-issue-in-release-2024.1', mockRefSets([''])), ['1', '2024'], 'test-42');
});
});
Loading
Loading