@@ -7,6 +7,8 @@ import {Protocol} from "../external/protocol";
77import { logDebug , logError } from "../log" ;
88import { API , GitExtension , RefType , RepositoryState } from "../typings/git" ;
99import { canReachGitHubAPI } from "../util" ;
10+ import { getUsername } from "./username" ;
11+ import { RepositoryPermission , getRepositoryPermission } from "./repository-permissions" ;
1012
1113interface GitHubUrls {
1214 workspaceUri : vscode . Uri ;
@@ -127,13 +129,14 @@ export interface GitHubRepoContext {
127129 name : string ;
128130
129131 organizationOwned : boolean ;
130-
131132 defaultBranch : string ;
133+ permissionLevel : RepositoryPermission ;
132134}
133135
134136export interface GitHubContext {
135137 repos : GitHubRepoContext [ ] ;
136138 reposByUri : Map < string , GitHubRepoContext > ;
139+ username : string ;
137140}
138141
139142let gitHubContext : Promise < GitHubContext | undefined > | undefined ;
@@ -159,6 +162,10 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
159162
160163 logDebug ( "Found protocol infos" , protocolInfos . length . toString ( ) ) ;
161164
165+ const username = await handleSamlError ( async ( client : Octokit ) => {
166+ return getUsername ( client ) ;
167+ } ) ;
168+
162169 const repos = await handleSamlError ( async ( client : Octokit ) => {
163170 return await Promise . all (
164171 protocolInfos . map ( async ( protocolInfo ) : Promise < GitHubRepoContext > => {
@@ -179,15 +186,17 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
179186 owner : protocolInfo . protocol . owner ,
180187 id : repoInfo . data . id ,
181188 defaultBranch : `refs/heads/${ repoInfo . data . default_branch } ` ,
182- organizationOwned : repoInfo . data . owner . type === "Organization"
189+ organizationOwned : repoInfo . data . owner . type === "Organization" ,
190+ permissionLevel : getRepositoryPermission ( repoInfo . data . permissions )
183191 } ;
184192 } )
185193 ) ;
186194 } ) ;
187195
188196 gitHubContext = Promise . resolve ( {
189197 repos,
190- reposByUri : new Map ( repos . map ( r => [ r . workspaceUri . toString ( ) , r ] ) )
198+ reposByUri : new Map ( repos . map ( r => [ r . workspaceUri . toString ( ) , r ] ) ) ,
199+ username
191200 } ) ;
192201 } catch ( e ) {
193202 // Reset the context so the next attempt will try this flow again
0 commit comments