@@ -3,10 +3,10 @@ import { describe, expect, it, vi } from "vite-plus/test";
33import {
44 changeRequestRepositoryUrl ,
55 findProjectForChangeRequest ,
6+ gitHubPullRequestBrowserUrl ,
67 matchesLinkedPullRequestUrl ,
78 openPullRequestLink ,
89 parseChangeRequestUrl ,
9- pullRequestBrowserUrl ,
1010 PullRequestLinkOpenError ,
1111 shouldOpenPullRequestExternally ,
1212} from "./openPullRequestLink" ;
@@ -24,15 +24,15 @@ function repositoryIdentity(
2424 } ;
2525}
2626
27- describe ( "pullRequestBrowserUrl " , ( ) => {
27+ describe ( "gitHubPullRequestBrowserUrl " , ( ) => {
2828 it ( "uses the requested GitHub repository instead of the project's default repository" , ( ) => {
2929 const identity = repositoryIdentity (
3030 "github" ,
3131 "github.com/acme/default" ,
3232 "https://github.com/acme/default.git" ,
3333 ) ;
3434
35- expect ( pullRequestBrowserUrl ( identity , "acme/other" , 42 ) ) . toBe (
35+ expect ( gitHubPullRequestBrowserUrl ( identity , "acme/other" , 42 ) ) . toBe (
3636 "https://github.com/acme/other/pull/42" ,
3737 ) ;
3838 } ) ;
@@ -44,94 +44,72 @@ describe("pullRequestBrowserUrl", () => {
4444 "http://[email protected] :8443/team/default.git" , 4545 ) ;
4646
47- expect ( pullRequestBrowserUrl ( identity , "platform/api" , 7 ) ) . toBe (
47+ expect ( gitHubPullRequestBrowserUrl ( identity , "platform/api" , 7 ) ) . toBe (
4848 "http://github.acme.test:8443/platform/api/pull/7" ,
4949 ) ;
5050 } ) ;
5151
52- it ( "preserves a nested GitLab repository path from an SSH remote" , ( ) => {
53- const identity = repositoryIdentity (
54- "gitlab" ,
55- "gitlab.acme.test/group/default" ,
56- "[email protected] :group/default.git" , 57- ) ;
58-
59- expect ( pullRequestBrowserUrl ( identity , "team/platform/api" , 9 ) ) . toBe (
60- "https://gitlab.acme.test/team/platform/api/-/merge_requests/9" ,
61- ) ;
62- } ) ;
63-
64- it ( "builds a Bitbucket pull request URL" , ( ) => {
65- const identity = repositoryIdentity (
66- "bitbucket" ,
67- "bitbucket.org/workspace/default" ,
68- "git://bitbucket.org/workspace/default.git" ,
69- ) ;
70-
71- expect ( pullRequestBrowserUrl ( identity , "workspace/repository" , 5 ) ) . toBe (
72- "https://bitbucket.org/workspace/repository/pull-requests/5" ,
73- ) ;
74- } ) ;
75-
76- it ( "uses Azure DevOps remote context with the requested repository name" , ( ) => {
77- const identity = repositoryIdentity (
78- "azure-devops" ,
79- "dev.azure.com/acme/platform/_git/default" ,
80- "https://user:[email protected] /acme/platform/_git/default.git" , 81- ) ;
82-
83- expect ( pullRequestBrowserUrl ( identity , "checkout" , 17 ) ) . toBe (
84- "https://dev.azure.com/acme/platform/_git/checkout/pullrequest/17" ,
85- ) ;
86- } ) ;
87-
88- it ( "converts an Azure DevOps SSH remote to its browser URL" , ( ) => {
89- const identity = repositoryIdentity (
90- "azure-devops" ,
91- "ssh.dev.azure.com/v3/acme/platform/default" ,
92- "[email protected] :v3/acme/platform/default" , 93- ) ;
94-
95- expect ( pullRequestBrowserUrl ( identity , "checkout" , 17 ) ) . toBe (
96- "https://dev.azure.com/acme/platform/_git/checkout/pullrequest/17" ,
97- ) ;
98- expect ( pullRequestBrowserUrl ( identity , "v3/acme/payments/checkout" , 18 ) ) . toBe (
99- "https://dev.azure.com/acme/payments/_git/checkout/pullrequest/18" ,
100- ) ;
101- expect ( pullRequestBrowserUrl ( identity , "acme/payments/_git/checkout" , 19 ) ) . toBe (
102- "https://dev.azure.com/acme/payments/_git/checkout/pullrequest/19" ,
52+ it . each ( [
53+ {
54+ name : "SSH" ,
55+ remoteUrl :
"[email protected] :team/default.git" , 56+ } ,
57+ {
58+ name : "git protocol" ,
59+ remoteUrl : "git://github.acme.test/team/default.git" ,
60+ } ,
61+ ] ) ( "uses the normalized host for a $name remote" , ( { remoteUrl } ) => {
62+ const identity = repositoryIdentity ( "github" , "github.acme.test/team/default" , remoteUrl ) ;
63+
64+ expect ( gitHubPullRequestBrowserUrl ( identity , "platform/api" , 9 ) ) . toBe (
65+ "https://github.acme.test/platform/api/pull/9" ,
10366 ) ;
10467 } ) ;
10568
106- it ( "keeps a full Azure DevOps repository path from a linked pull request" , ( ) => {
107- const identity = repositoryIdentity (
108- "azure-devops" ,
109- "dev.azure.com/acme/platform/_git/default" ,
110- "https://dev.azure.com/acme/platform/_git/default.git" ,
111- ) ;
112-
113- expect ( pullRequestBrowserUrl ( identity , "acme/payments/_git/checkout" , 17 ) ) . toBe (
114- "https://dev.azure.com/acme/payments/_git/checkout/pullrequest/17" ,
115- ) ;
116- } ) ;
117-
118- it ( "returns null without a supported repository identity" , ( ) => {
119- const unknown = repositoryIdentity (
120- "unknown" ,
121- "code.example.test/acme/repository" ,
122- "https://code.example.test/acme/repository.git" ,
123- ) ;
124-
125- expect ( pullRequestBrowserUrl ( null , "acme/repository" , 1 ) ) . toBeNull ( ) ;
126- expect ( pullRequestBrowserUrl ( unknown , "acme/repository" , 1 ) ) . toBeNull ( ) ;
69+ it ( "returns null for missing or invalid GitHub data" , ( ) => {
70+ expect ( gitHubPullRequestBrowserUrl ( null , "acme/repository" , 1 ) ) . toBeNull ( ) ;
71+ expect (
72+ gitHubPullRequestBrowserUrl (
73+ repositoryIdentity ( "github" , "github.com/acme/repository" , "https://github.com/a/b" ) ,
74+ "acme" ,
75+ 1 ,
76+ ) ,
77+ ) . toBeNull ( ) ;
78+ expect (
79+ gitHubPullRequestBrowserUrl (
80+ repositoryIdentity ( "github" , "github.com/acme/repository" , "https://github.com/a/b" ) ,
81+ "../repository" ,
82+ 1 ,
83+ ) ,
84+ ) . toBeNull ( ) ;
12785 expect (
128- pullRequestBrowserUrl (
86+ gitHubPullRequestBrowserUrl (
87+ repositoryIdentity ( "github" , "github.com/acme/repository" , "https://github.com/a/b" ) ,
88+ "acme/repository" ,
89+ 0 ,
90+ ) ,
91+ ) . toBeNull ( ) ;
92+ expect (
93+ gitHubPullRequestBrowserUrl (
12994 repositoryIdentity ( "github" , "bad host/acme/repository" , "not a remote" ) ,
13095 "acme/repository" ,
13196 1 ,
13297 ) ,
13398 ) . toBeNull ( ) ;
13499 } ) ;
100+
101+ it . each ( [ "gitlab" , "bitbucket" , "azure-devops" , "unknown" ] ) (
102+ "does not build a fallback for %s" ,
103+ ( provider ) => {
104+ expect (
105+ gitHubPullRequestBrowserUrl (
106+ repositoryIdentity ( provider , "github.com/acme/repository" , "https://github.com/a/b" ) ,
107+ "acme/repository" ,
108+ 1 ,
109+ ) ,
110+ ) . toBeNull ( ) ;
111+ } ,
112+ ) ;
135113} ) ;
136114
137115describe ( "changeRequestRepositoryUrl" , ( ) => {
0 commit comments