1- import { Octokit } from "@octokit/rest" ;
21import * as vscode from "vscode" ;
2+
3+ import { API , GitExtension , RefType } from "../typings/git" ;
4+ import { logDebug , logError } from "../log" ;
5+
6+ import { Octokit } from "@octokit/rest" ;
7+ import { Protocol } from "../external/protocol" ;
38import { getClient } from "../api/api" ;
49import { getSession } from "../auth/auth" ;
5- import { Protocol } from "../external/protocol" ;
6- import { API , GitExtension , RefType } from "../typings/git" ;
710
811async function getGitExtension ( ) : Promise < API | undefined > {
912 const gitExtension =
@@ -53,8 +56,13 @@ export async function getGitHubUrls(): Promise<
5356> {
5457 const git = await getGitExtension ( ) ;
5558 if ( git && git . repositories . length > 0 ) {
56- return git . repositories
57- . map ( ( r ) => {
59+ logDebug ( "Found git extension" ) ;
60+
61+ const p = await Promise . all (
62+ git . repositories . map ( async ( r ) => {
63+ logDebug ( "Find `origin` remote for repository" , r . rootUri . path ) ;
64+ await r . status ( ) ;
65+
5866 // In the future we might make this configurable, but for now continue to look
5967 // for a remote named "origin".
6068 const originRemote = r . state . remotes . filter (
@@ -73,9 +81,12 @@ export async function getGitHubUrls(): Promise<
7381 } ;
7482 }
7583
84+ logDebug ( "No `origin` remote found, skipping repository" ) ;
85+
7686 return undefined ;
7787 } )
78- . filter ( ( x ) => ! ! x ) as any ;
88+ ) ;
89+ return p . filter ( ( x ) => ! ! x ) as any ;
7990 }
8091
8192 // If we cannot find the git extension, assume for now that we are running a web context,
@@ -140,11 +151,16 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
140151
141152 const protocolInfos = await getGitHubUrls ( ) ;
142153 if ( ! protocolInfos ) {
154+ logDebug ( "Could not get protocol infos" ) ;
143155 return undefined ;
144156 }
145157
158+ logDebug ( "Found protocol infos" , protocolInfos . length . toString ( ) ) ;
159+
146160 const repos = await Promise . all (
147161 protocolInfos . map ( async ( protocolInfo ) : Promise < GitHubRepoContext > => {
162+ logDebug ( "Getting infos for repository" , protocolInfo . url ) ;
163+
148164 const repoInfo = await client . repos . get ( {
149165 repo : protocolInfo . protocol . repositoryName ,
150166 owner : protocolInfo . protocol . owner ,
@@ -169,10 +185,12 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
169185 repos,
170186 reposByUri : new Map ( repos . map ( ( r ) => [ r . workspaceUri . toString ( ) , r ] ) ) ,
171187 } ) ;
172- } catch ( e ) {
188+ } catch ( e : any ) {
173189 // Reset the context so the next attempt will try this flow again
174190 gitHubContext = undefined ;
175191
192+ logError ( e , "Error getting GitHub context" ) ;
193+
176194 // Rethrow original error
177195 throw e ;
178196 }
0 commit comments