@@ -2,11 +2,13 @@ import * as vscode from "vscode";
22import { Octokit } from "@octokit/rest" ;
33
44import { handleSamlError } from "../api/handleSamlError" ;
5+ import { getSession } from "../auth/auth" ;
56import { getRemoteName } from "../configuration/configuration" ;
67import { Protocol } from "../external/protocol" ;
78import { logDebug , logError } from "../log" ;
89import { API , GitExtension , RefType , RepositoryState } from "../typings/git" ;
910import { canReachGitHubAPI } from "../util" ;
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,9 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
159162
160163 logDebug ( "Found protocol infos" , protocolInfos . length . toString ( ) ) ;
161164
165+ const session = await getSession ( ) ;
166+ const username = session . account . label ;
167+
162168 const repos = await handleSamlError ( async ( client : Octokit ) => {
163169 return await Promise . all (
164170 protocolInfos . map ( async ( protocolInfo ) : Promise < GitHubRepoContext > => {
@@ -179,15 +185,17 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
179185 owner : protocolInfo . protocol . owner ,
180186 id : repoInfo . data . id ,
181187 defaultBranch : `refs/heads/${ repoInfo . data . default_branch } ` ,
182- organizationOwned : repoInfo . data . owner . type === "Organization"
188+ organizationOwned : repoInfo . data . owner . type === "Organization" ,
189+ permissionLevel : getRepositoryPermission ( repoInfo . data . permissions )
183190 } ;
184191 } )
185192 ) ;
186193 } ) ;
187194
188195 gitHubContext = Promise . resolve ( {
189196 repos,
190- reposByUri : new Map ( repos . map ( r => [ r . workspaceUri . toString ( ) , r ] ) )
197+ reposByUri : new Map ( repos . map ( r => [ r . workspaceUri . toString ( ) , r ] ) ) ,
198+ username
191199 } ) ;
192200 } catch ( e ) {
193201 // Reset the context so the next attempt will try this flow again
0 commit comments