@@ -25,12 +25,16 @@ describe("findGitHubRepositoryForWorkspace", () => {
2525 name : "main" ,
2626 upstream : {
2727 name : "origin" ,
28- remote : "origin " ,
28+ remote : "fork " ,
2929 } ,
3030 } ,
3131 remotes : [
3232 {
3333 name : "origin" ,
34+ fetchUrl : "https://github.com/codeql/test-incorrect.git" ,
35+ } ,
36+ {
37+ name : "fork" ,
3438 fetchUrl : "https://github.com/codeql/test.git" ,
3539 } ,
3640 ] ,
@@ -60,7 +64,9 @@ describe("findGitHubRepositoryForWorkspace", () => {
6064
6165 getExtensionSpy . mockReturnValue (
6266 mockedObject < Extension < GitExtension > > ( {
67+ isActive : true ,
6368 exports : {
69+ enabled : true ,
6470 getAPI : getAPISpy ,
6571 } ,
6672 } ) ,
@@ -85,11 +91,61 @@ describe("findGitHubRepositoryForWorkspace", () => {
8591
8692 it ( "returns an error" , async ( ) => {
8793 expect ( await findGitHubRepositoryForWorkspace ( ) ) . toEqual (
88- ValueResult . fail ( [ "Git extension is not installed or initialized " ] ) ,
94+ ValueResult . fail ( [ "Git extension not found " ] ) ,
8995 ) ;
9096 } ) ;
9197 } ) ;
9298
99+ describe ( "when the git extension is not activated" , ( ) => {
100+ const activate = jest . fn ( ) ;
101+
102+ beforeEach ( ( ) => {
103+ getExtensionSpy . mockReturnValue (
104+ mockedObject < Extension < GitExtension > > ( {
105+ isActive : false ,
106+ activate,
107+ exports : {
108+ enabled : true ,
109+ getAPI : getAPISpy ,
110+ } ,
111+ } ) ,
112+ ) ;
113+ } ) ;
114+
115+ it ( "returns the GitHub repository name with owner" , async ( ) => {
116+ expect ( await findGitHubRepositoryForWorkspace ( ) ) . toEqual (
117+ ValueResult . ok ( {
118+ owner : "codeql" ,
119+ name : "test" ,
120+ } ) ,
121+ ) ;
122+
123+ expect ( activate ) . toHaveBeenCalledTimes ( 1 ) ;
124+ } ) ;
125+ } ) ;
126+
127+ describe ( "when the git extension is disabled by the setting" , ( ) => {
128+ beforeEach ( ( ) => {
129+ getExtensionSpy . mockReturnValue (
130+ mockedObject < Extension < GitExtension > > ( {
131+ isActive : true ,
132+ exports : {
133+ enabled : false ,
134+ getAPI : getAPISpy ,
135+ } ,
136+ } ) ,
137+ ) ;
138+ } ) ;
139+
140+ it ( "returns an error" , async ( ) => {
141+ expect ( await findGitHubRepositoryForWorkspace ( ) ) . toEqual (
142+ ValueResult . fail ( [ "Git extension is not enabled" ] ) ,
143+ ) ;
144+
145+ expect ( getAPISpy ) . not . toHaveBeenCalled ( ) ;
146+ } ) ;
147+ } ) ;
148+
93149 describe ( "when the git extension is not yet initialized" , ( ) => {
94150 beforeEach ( ( ) => {
95151 const onDidChangeState = jest . fn ( ) ;
@@ -149,7 +205,48 @@ describe("findGitHubRepositoryForWorkspace", () => {
149205 } ) ;
150206 } ) ;
151207
152- describe ( "when the current branch does not have a remote" , ( ) => {
208+ describe ( "when the current branch does not have a remote but origin remote exists" , ( ) => {
209+ beforeEach ( ( ) => {
210+ mockGitExtensionAPI = mockedObject < GitExtensionAPI > ( {
211+ state : "initialized" ,
212+ repositories : [
213+ {
214+ ...repositories [ 0 ] ,
215+ state : {
216+ ...repositories [ 0 ] . state ,
217+ HEAD : {
218+ ...repositories [ 0 ] . state . HEAD ,
219+ upstream : undefined ,
220+ } ,
221+ remotes : [
222+ {
223+ name : "upstream" ,
224+ fetchUrl : "https://github.com/github/codeql-incorrect.git" ,
225+ } ,
226+ {
227+ name : "origin" ,
228+ fetchUrl : "https://github.com/github/codeql.git" ,
229+ } ,
230+ ] ,
231+ } ,
232+ } ,
233+ ] ,
234+ } ) ;
235+
236+ getAPISpy . mockReturnValue ( mockGitExtensionAPI ) ;
237+ } ) ;
238+
239+ it ( "returns the GitHub repository name with owner" , async ( ) => {
240+ expect ( await findGitHubRepositoryForWorkspace ( ) ) . toEqual (
241+ ValueResult . ok ( {
242+ owner : "github" ,
243+ name : "codeql" ,
244+ } ) ,
245+ ) ;
246+ } ) ;
247+ } ) ;
248+
249+ describe ( "when the current branch does not have a remote and no origin remote" , ( ) => {
153250 beforeEach ( ( ) => {
154251 mockGitExtensionAPI = mockedObject < GitExtensionAPI > ( {
155252 state : "initialized" ,
@@ -167,6 +264,10 @@ describe("findGitHubRepositoryForWorkspace", () => {
167264 name : "upstream" ,
168265 fetchUrl : "https://github.com/github/codeql.git" ,
169266 } ,
267+ {
268+ name : "fork" ,
269+ fetchUrl : "https://github.com/github/codeql-incorrect.git" ,
270+ } ,
170271 ] ,
171272 } ,
172273 } ,
0 commit comments