Skip to content

Commit 7ca1a3b

Browse files
committed
Enhance GitHub PR functionality by adding labels and assignees support, and update package.json keywords for better searchability
1 parent 2323cba commit 7ca1a3b

4 files changed

Lines changed: 63 additions & 7 deletions

File tree

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
"git",
1414
"checkout",
1515
"stash",
16-
"auto stash"
16+
"auto stash",
17+
"pull request",
18+
"PR",
19+
"pr clone",
20+
"clone pull request"
1721
],
1822
"license": "MIT",
1923
"version": "0.0.1",

src/common/api/ghClient.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as https from 'https';
22
import { authentication } from 'vscode';
33

44
import { EXTENSION_NAME } from '../../const';
5-
import { GitHubCommit, GitHubCommitFile, GitHubPR } from '../../types/dataTypes';
5+
import { GitHubCommit, GitHubCommitFile, GitHubLabel, GitHubPR, GitHubUser } from '../../types/dataTypes';
66

77
export 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
}

src/services/prCloneInPlaceService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,19 @@ export class PrCloneInPlaceService extends PrCloneServiceBase {
273273
): Promise<GitHubPR> {
274274
const prBody = description;
275275

276+
// Extract labels and assignees from original PR
277+
const labels = originalPr.labels?.map(label => label.name) || [];
278+
const assignees = originalPr.assignees?.map(assignee => assignee.login) || [];
279+
276280
// Create PR using the GitHub API
277281
const newPr = await this.ghClient.createPullRequest(
278282
originalPr.title, // Use original PR title
279283
prBody,
280284
featureBranch,
281285
targetBranch,
282-
isDraft
286+
isDraft,
287+
labels,
288+
assignees
283289
);
284290

285291
this.loggingService.info(`Created PR #${newPr.number}: ${newPr.title}`);

src/types/dataTypes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
export interface GitHubUser {
2+
id: number;
3+
login: string;
4+
avatar_url: string;
5+
}
6+
17
export interface GitHubPR {
28
number: number;
39
title: string;
@@ -10,6 +16,8 @@ export interface GitHubPR {
1016
ref: string;
1117
};
1218
html_url: string;
19+
labels: GitHubLabel[];
20+
assignees: GitHubUser[];
1321
}
1422

1523
export interface GitHubCommitFile {
@@ -29,6 +37,14 @@ export interface GitHubCommit {
2937
files?: GitHubCommitFile[];
3038
}
3139

40+
export interface GitHubLabel {
41+
id: number;
42+
name: string;
43+
description: string | null;
44+
color: string;
45+
default: boolean;
46+
}
47+
3248
export interface AppState {
3349
view: 'input' | 'clone';
3450
prData?: GitHubPR;

0 commit comments

Comments
 (0)