Skip to content

Commit 79da0a8

Browse files
authored
Revive issue editor and fix related issues (#6767)
1 parent fc0a05a commit 79da0a8

27 files changed

+949
-662
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,11 @@
13161316
"title": "%command.pr.createPrMenuRebase.title%",
13171317
"category": "%command.pull.request.category%"
13181318
},
1319+
{
1320+
"command": "issue.openDescription",
1321+
"title": "%command.issue.openDescription.title%",
1322+
"category": "%command.issues.category%"
1323+
},
13191324
{
13201325
"command": "issue.createIssueFromSelection",
13211326
"title": "%command.issue.createIssueFromSelection.title%",
@@ -2070,6 +2075,10 @@
20702075
"command": "pr.acceptMerge",
20712076
"when": "isMergeResultEditor && mergeEditorBaseUri =~ /^(githubpr|gitpr):/"
20722077
},
2078+
{
2079+
"command": "issue.openDescription",
2080+
"when": "false"
2081+
},
20732082
{
20742083
"command": "issue.copyGithubPermalink",
20752084
"when": "github:hasGitHubRemotes"

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
"command.pr.closeRelatedEditors.title": "Close All Pull Request Editors",
261261
"command.pr.toggleEditorCommentingOn.title": "Toggle Editor Commenting On",
262262
"command.pr.toggleEditorCommentingOff.title": "Toggle Editor Commenting Off",
263+
"command.issue.openDescription.title": "View Issue Description",
263264
"command.issue.copyGithubDevLink.title": "Copy github.dev Link",
264265
"command.issue.copyGithubPermalink.title": "Copy GitHub Permalink",
265266
"command.issue.copyGithubHeadLink.title": "Copy GitHub Head Link",

resources/icons/issue.svg

Lines changed: 1 addition & 0 deletions
Loading

resources/icons/issue_closed.svg

Lines changed: 1 addition & 0 deletions
Loading

src/commands.ts

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,37 @@ function ensurePR<TIssue extends Issue, TIssueModel extends IssueModel<TIssue>>(
6767

6868
export async function openDescription(
6969
telemetry: ITelemetry,
70-
pullRequestModel: IssueModel,
70+
issueModel: IssueModel,
7171
descriptionNode: DescriptionNode | undefined,
7272
folderManager: FolderRepositoryManager,
7373
revealNode: boolean,
7474
preserveFocus: boolean = true,
7575
notificationProvider?: NotificationProvider
7676
) {
77-
const pullRequest = ensurePR(folderManager, pullRequestModel);
77+
const issue = ensurePR(folderManager, issueModel);
7878
if (revealNode) {
7979
descriptionNode?.reveal(descriptionNode, { select: true, focus: true });
8080
}
8181
// Create and show a new webview
82-
if (pullRequest instanceof PullRequestModel) {
83-
await PullRequestOverviewPanel.createOrShow(telemetry, folderManager.context.extensionUri, folderManager, pullRequest, undefined, preserveFocus);
82+
if (issue instanceof PullRequestModel) {
83+
await PullRequestOverviewPanel.createOrShow(telemetry, folderManager.context.extensionUri, folderManager, issue, undefined, preserveFocus);
84+
/* __GDPR__
85+
"pr.openDescription" : {}
86+
*/
87+
telemetry.sendTelemetryEvent('pr.openDescription');
8488
} else {
85-
await IssueOverviewPanel.createOrShow(telemetry, folderManager.context.extensionUri, folderManager, pullRequest);
89+
await IssueOverviewPanel.createOrShow(telemetry, folderManager.context.extensionUri, folderManager, issue);
90+
/* __GDPR__
91+
"issue.openDescription" : {}
92+
*/
93+
telemetry.sendTelemetryEvent('issue.openDescription');
8694
}
8795

88-
if (notificationProvider?.hasNotification(pullRequest)) {
89-
notificationProvider.markPrNotificationsAsRead(pullRequest);
96+
if (notificationProvider?.hasNotification(issue)) {
97+
notificationProvider.markPrNotificationsAsRead(issue);
9098
}
9199

92-
/* __GDPR__
93-
"pr.openDescription" : {}
94-
*/
95-
telemetry.sendTelemetryEvent('pr.openDescription');
100+
96101
}
97102

98103
async function chooseItem<T>(
@@ -115,7 +120,7 @@ async function chooseItem<T>(
115120
return (await vscode.window.showQuickPick(items, options))?.itemValue;
116121
}
117122

118-
export async function openPullRequestOnGitHub(e: PRNode | DescriptionNode | PullRequestModel | NotificationTreeItem, telemetry: ITelemetry) {
123+
export async function openPullRequestOnGitHub(e: PRNode | DescriptionNode | IssueModel | NotificationTreeItem, telemetry: ITelemetry) {
119124
if (e instanceof PRNode || e instanceof DescriptionNode) {
120125
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(e.pullRequestModel.html_url));
121126
} else if (isNotificationTreeItem(e)) {
@@ -805,50 +810,61 @@ export function registerCommands(
805810
}),
806811
);
807812

808-
context.subscriptions.push(
809-
vscode.commands.registerCommand(
810-
'pr.openDescription',
811-
async (argument: DescriptionNode | IssueModel | undefined) => {
812-
let pullRequestModel: IssueModel | undefined;
813-
if (!argument) {
814-
const activePullRequests: PullRequestModel[] = reposManager.folderManagers
815-
.map(manager => manager.activePullRequest!)
816-
.filter(activePR => !!activePR);
817-
if (activePullRequests.length >= 1) {
818-
pullRequestModel = await chooseItem<PullRequestModel>(
819-
activePullRequests,
820-
itemValue => itemValue.title,
821-
);
822-
}
823-
} else {
824-
pullRequestModel = argument instanceof DescriptionNode ? argument.pullRequestModel : argument;
825-
}
813+
async function openDescriptionCommand(argument: DescriptionNode | IssueModel | undefined) {
814+
let issueModel: IssueModel | undefined;
815+
if (!argument) {
816+
const activePullRequests: PullRequestModel[] = reposManager.folderManagers
817+
.map(manager => manager.activePullRequest!)
818+
.filter(activePR => !!activePR);
819+
if (activePullRequests.length >= 1) {
820+
issueModel = await chooseItem<PullRequestModel>(
821+
activePullRequests,
822+
itemValue => itemValue.title,
823+
);
824+
}
825+
} else {
826+
issueModel = argument instanceof DescriptionNode ? argument.pullRequestModel : argument;
827+
}
826828

827-
if (!pullRequestModel) {
828-
Logger.appendLine('No pull request found.', logId);
829-
return;
830-
}
829+
if (!issueModel) {
830+
Logger.appendLine('No pull request found.', logId);
831+
return;
832+
}
831833

832-
const folderManager = reposManager.getManagerForIssueModel(pullRequestModel);
833-
if (!folderManager) {
834-
return;
835-
}
834+
const folderManager = reposManager.getManagerForIssueModel(issueModel);
835+
if (!folderManager) {
836+
return;
837+
}
836838

837-
let descriptionNode: DescriptionNode | undefined;
838-
if (argument instanceof DescriptionNode) {
839-
descriptionNode = argument;
840-
} else {
841-
const reviewManager = ReviewManager.getReviewManagerForFolderManager(reviewsManager.reviewManagers, folderManager);
842-
if (!reviewManager) {
843-
return;
844-
}
839+
let descriptionNode: DescriptionNode | undefined;
840+
if (argument instanceof DescriptionNode) {
841+
descriptionNode = argument;
842+
} else {
843+
const reviewManager = ReviewManager.getReviewManagerForFolderManager(reviewsManager.reviewManagers, folderManager);
844+
if (!reviewManager) {
845+
return;
846+
}
845847

846-
descriptionNode = reviewManager.changesInPrDataProvider.getDescriptionNode(folderManager);
847-
}
848+
descriptionNode = reviewManager.changesInPrDataProvider.getDescriptionNode(folderManager);
849+
}
848850

849-
await openDescription(telemetry, pullRequestModel, descriptionNode, folderManager, !(argument instanceof DescriptionNode), !(argument instanceof RepositoryChangesNode), tree.notificationProvider);
850-
},
851-
),
851+
const revealDescription = !(argument instanceof DescriptionNode) && (!(argument instanceof IssueModel) || (argument instanceof PullRequestModel));
852+
853+
await openDescription(telemetry, issueModel, descriptionNode, folderManager, revealDescription, !(argument instanceof RepositoryChangesNode), tree.notificationProvider);
854+
}
855+
856+
context.subscriptions.push(
857+
vscode.commands.registerCommand(
858+
'pr.openDescription',
859+
openDescriptionCommand
860+
)
861+
);
862+
863+
context.subscriptions.push(
864+
vscode.commands.registerCommand(
865+
'issue.openDescription',
866+
openDescriptionCommand
867+
)
852868
);
853869

854870
context.subscriptions.push(
@@ -1460,6 +1476,7 @@ ${contents}
14601476
vscode.env.openExternal(getPullsUrl(githubRepo));
14611477
}
14621478
}));
1479+
14631480
context.subscriptions.push(
14641481
vscode.commands.registerCommand('issues.openIssuesWebsite', async () => {
14651482
const githubRepo = await chooseRepoToOpen();

src/common/timelineEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface CommentEvent {
3333
htmlUrl: string;
3434
body: string;
3535
bodyHTML?: string;
36-
user: IAccount;
36+
user?: IAccount;
3737
event: EventType.Commented;
3838
canEdit?: boolean;
3939
canDelete?: boolean;

src/github/folderRepositoryManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,9 +2087,9 @@ export class FolderRepositoryManager extends Disposable {
20872087
}
20882088

20892089
async getPullRequestRepositoryAccessAndMergeMethods(
2090-
pullRequest: PullRequestModel,
2090+
issue: IssueModel,
20912091
): Promise<RepoAccessAndMergeMethods> {
2092-
const mergeOptions = await pullRequest.githubRepository.getRepoAccessAndMergeMethods();
2092+
const mergeOptions = await issue.githubRepository.getRepoAccessAndMergeMethods();
20932093
return mergeOptions;
20942094
}
20952095

src/github/githubRepository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
GetBranchResponse,
2323
GetChecksResponse,
2424
isCheckRun,
25+
IssueResponse,
2526
IssuesSearchResponse,
2627
ListBranchesResponse,
2728
MaxIssueResponse,
@@ -1003,7 +1004,7 @@ export class GitHubRepository extends Disposable {
10031004
Logger.debug(`Fetch issue ${id} - enter`, this.id);
10041005
const { query, remote, schema } = await this.ensure();
10051006

1006-
const { data } = await query<PullRequestResponse>({
1007+
const { data } = await query<IssueResponse>({
10071008
query: withComments ? schema.IssueWithComments : schema.Issue,
10081009
variables: {
10091010
owner: remote.owner,
@@ -1018,7 +1019,7 @@ export class GitHubRepository extends Disposable {
10181019
}
10191020
Logger.debug(`Fetch issue ${id} - done`, this.id);
10201021

1021-
return new IssueModel(this, remote, parseGraphQLIssue(data.repository.pullRequest, this));
1022+
return new IssueModel(this, remote, parseGraphQLIssue(data.repository.issue, this));
10221023
} catch (e) {
10231024
Logger.error(`Unable to fetch issue: ${e}`, this.id);
10241025
return;

src/github/graphql.ts

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ export interface DeleteReactionResponse {
450450
};
451451
}
452452

453-
export interface UpdatePullRequestResponse {
454-
updatePullRequest: {
455-
pullRequest: {
453+
export interface UpdateIssueResponse {
454+
updateIssue: {
455+
issue: {
456456
body: string;
457457
bodyHTML: string;
458458
title: string;
@@ -522,12 +522,12 @@ export interface SuggestedReviewerResponse {
522522
export type MergeMethod = 'MERGE' | 'REBASE' | 'SQUASH';
523523
export type MergeQueueState = 'AWAITING_CHECKS' | 'LOCKED' | 'MERGEABLE' | 'QUEUED' | 'UNMERGEABLE';
524524

525-
export interface PullRequest {
525+
export interface Issue {
526526
id: string;
527527
databaseId: number;
528528
number: number;
529529
url: string;
530-
state: 'OPEN' | 'CLOSED' | 'MERGED';
530+
state: 'OPEN' | 'CLOSED' | 'MERGED'; // TODO: don't allow merged in an issue
531531
body: string;
532532
bodyHTML: string;
533533
title: string;
@@ -536,48 +536,19 @@ export interface PullRequest {
536536
nodes: Account[];
537537
};
538538
author: Account;
539-
commits: {
540-
nodes: {
541-
commit: {
542-
message: string;
543-
};
544-
}[];
545-
};
546539
comments: {
547540
nodes?: AbbreviatedIssueComment[];
548541
totalCount: number;
549542
};
550543
createdAt: string;
551544
updatedAt: string;
552-
headRef?: Ref;
553-
headRefName: string;
554-
headRefOid: string;
555-
headRepository?: RefRepository;
556-
baseRef?: Ref;
557-
baseRefName: string;
558-
baseRefOid: string;
559-
baseRepository: BaseRefRepository;
560545
labels: {
561546
nodes: {
562547
name: string;
563548
color: string;
564549
}[];
565550
};
566-
merged: boolean;
567-
mergeable: 'MERGEABLE' | 'CONFLICTING' | 'UNKNOWN';
568-
mergeQueueEntry?: MergeQueueEntry | null;
569-
mergeStateStatus: 'BEHIND' | 'BLOCKED' | 'CLEAN' | 'DIRTY' | 'HAS_HOOKS' | 'UNKNOWN' | 'UNSTABLE';
570-
reviewThreads: {
571-
totalCount: number;
572-
}
573-
autoMergeRequest?: {
574-
mergeMethod: MergeMethod;
575-
};
576-
viewerCanEnableAutoMerge: boolean;
577-
viewerCanDisableAutoMerge: boolean;
578551
viewerCanUpdate: boolean;
579-
isDraft?: boolean;
580-
suggestedReviewers: SuggestedReviewerResponse[];
581552
projectItems?: {
582553
nodes: {
583554
project: {
@@ -606,6 +577,39 @@ export interface PullRequest {
606577
}
607578
}
608579

580+
581+
export interface PullRequest extends Issue {
582+
commits: {
583+
nodes: {
584+
commit: {
585+
message: string;
586+
};
587+
}[];
588+
};
589+
headRef?: Ref;
590+
headRefName: string;
591+
headRefOid: string;
592+
headRepository?: RefRepository;
593+
baseRef?: Ref;
594+
baseRefName: string;
595+
baseRefOid: string;
596+
baseRepository: BaseRefRepository;
597+
merged: boolean;
598+
mergeable: 'MERGEABLE' | 'CONFLICTING' | 'UNKNOWN';
599+
mergeQueueEntry?: MergeQueueEntry | null;
600+
mergeStateStatus: 'BEHIND' | 'BLOCKED' | 'CLEAN' | 'DIRTY' | 'HAS_HOOKS' | 'UNKNOWN' | 'UNSTABLE';
601+
reviewThreads: {
602+
totalCount: number;
603+
}
604+
autoMergeRequest?: {
605+
mergeMethod: MergeMethod;
606+
};
607+
viewerCanEnableAutoMerge: boolean;
608+
viewerCanDisableAutoMerge: boolean;
609+
isDraft?: boolean;
610+
suggestedReviewers: SuggestedReviewerResponse[];
611+
}
612+
609613
export enum DefaultCommitTitle {
610614
prTitle = 'PR_TITLE',
611615
commitOrPrTitle = 'COMMIT_OR_PR_TITLE',
@@ -626,6 +630,13 @@ export interface PullRequestResponse {
626630
rateLimit: RateLimit;
627631
}
628632

633+
export interface IssueResponse {
634+
repository: {
635+
issue: PullRequest;
636+
} | null;
637+
rateLimit: RateLimit;
638+
}
639+
629640
export interface PullRequestMergabilityResponse {
630641
repository: {
631642
pullRequest: {

src/github/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export interface IPullRequestsPagingOptions {
287287
fetchOnePagePerRepo?: boolean;
288288
}
289289

290-
export interface IPullRequestEditData {
290+
export interface IIssueEditData {
291291
body?: string;
292292
title?: string;
293293
}

0 commit comments

Comments
 (0)