Skip to content

Commit 174140d

Browse files
committed
fix: expand legacy GitLab route keyword list
Signed-off-by: anilb <epipav@gmail.com>
1 parent 66c653e commit 174140d

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

services/apps/packages_worker/src/utils/__tests__/canonicalizeRepoUrl.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ describe('canonicalizeRepoUrl', () => {
6060
'https://gitlab.com/group/subgroup/project',
6161
'gitlab',
6262
],
63+
[
64+
// The reviewer's exact regression example: `raw` was missing from the legacy
65+
// route list, so this previously resolved as the bogus nested repo
66+
// `group/project/raw`.
67+
'https://gitlab.com/group/project/raw/main/file.php',
68+
'https://gitlab.com/group/project',
69+
'gitlab',
70+
],
71+
[
72+
'https://gitlab.com/group/project/blame/main/file.php',
73+
'https://gitlab.com/group/project',
74+
'gitlab',
75+
],
76+
[
77+
'https://gitlab.com/group/subgroup/project/issues/42',
78+
'https://gitlab.com/group/subgroup/project',
79+
'gitlab',
80+
],
6381
])('canonicalizes %s', (input, expectedUrl, expectedHost) => {
6482
expect(canonicalizeRepoUrl(input)).toEqual({ url: expectedUrl, host: expectedHost })
6583
})

services/apps/packages_worker/src/utils/canonicalizeRepoUrl.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,29 @@ const CASE_INSENSITIVE_HOSTS = new Set(['github.com', 'gitlab.com'])
2727
// Pre-2018 GitLab URLs (and shorthand copies of them still circulating) mark deep-links
2828
// the same way GitHub does — appended directly after the project path, with no `/-/`
2929
// separator. GitLab reserves these route words at the project-slug position precisely so
30-
// they can never collide with a real project name (docs: user/reserved_names), so treating
31-
// the first one as a deep-link boundary is safe even for arbitrarily nested subgroups.
30+
// they can never collide with a real project name (docs: user/reserved_names, the
31+
// PROJECT_WILDCARD_ROUTES list), so treating the first one as a deep-link boundary is
32+
// safe even for arbitrarily nested subgroups.
3233
const GITLAB_LEGACY_ROUTE_SEGMENTS = new Set([
3334
'tree',
3435
'blob',
36+
'blame',
37+
'raw',
3538
'commits',
3639
'commit',
3740
'compare',
3841
'issues',
3942
'merge_requests',
4043
'wikis',
44+
'builds',
45+
'create',
46+
'create_dir',
47+
'edit',
48+
'find_file',
49+
'new',
50+
'preview',
51+
'refs',
52+
'update',
4153
])
4254

4355
/**

0 commit comments

Comments
 (0)