@@ -2,7 +2,7 @@ import * as https from 'https';
22import { authentication } from 'vscode' ;
33
44import { EXTENSION_NAME } from '../../const' ;
5- import { GitHubCommit , GitHubCommitFile , GitHubPR } from '../../types/dataTypes' ;
5+ import { GitHubCommit , GitHubCommitFile , GitHubLabel , GitHubPR , GitHubUser } from '../../types/dataTypes' ;
66
77export class GitHubClient {
88 private static readonly BASE_URL = 'https://api.github.com' ;
@@ -72,9 +72,21 @@ export class GitHubClient {
7272 data += chunk ;
7373 } ) ;
7474
75- res . on ( 'end' , ( ) => {
75+ res . on ( 'end' , async ( ) => {
7676 if ( res . statusCode && res . statusCode === 403 ) {
77- // todo: add reauthenticate method and retry
77+ // Check if this is a SAML enforcement error and we haven't already retried with re-auth
78+ if ( ! reAuthenticate && data . includes ( 'Resource protected by organization SAML enforcement' ) ) {
79+ try {
80+ // Retry with re-authentication
81+ const result = await this . makeRequest < T > ( endpoint , method , body , true ) ;
82+ resolve ( result ) ;
83+ return ;
84+ } catch ( retryError ) {
85+ // If re-authentication fails, throw the retry error instead of the original
86+ reject ( retryError ) ;
87+ return ;
88+ }
89+ }
7890 }
7991
8092 if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 300 ) {
@@ -195,17 +207,35 @@ export class GitHubClient {
195207 body : string ,
196208 head : string ,
197209 base : string ,
198- isDraft : boolean = false
210+ isDraft : boolean = false ,
211+ labels ?: string [ ] ,
212+ assignees ?: string [ ]
199213 ) : Promise < GitHubPR > {
200214 const endpoint = `/repos/${ this . owner } /${ this . repo } /pulls` ;
201- const requestBody = {
215+ const requestBody : any = {
202216 title,
203217 body,
204218 head,
205219 base,
206220 draft : isDraft ,
207221 } ;
208222
223+ // Add labels and assignees if provided
224+ if ( labels && labels . length > 0 ) {
225+ requestBody . labels = labels ;
226+ }
227+ if ( assignees && assignees . length > 0 ) {
228+ requestBody . assignees = assignees ;
229+ }
230+
209231 return this . makeRequest < GitHubPR > ( endpoint , 'POST' , requestBody ) ;
210232 }
233+
234+ /**
235+ * Fetch all labels from the repository
236+ */
237+ public async fetchLabels ( ) : Promise < GitHubLabel [ ] > {
238+ const endpoint = `/repos/${ this . owner } /${ this . repo } /labels` ;
239+ return this . makeRequest < GitHubLabel [ ] > ( endpoint ) ;
240+ }
211241}
0 commit comments