Skip to content

Commit e0ee291

Browse files
authored
Support closing an issue (#6884)
Fixes #6864
1 parent 1bfccfd commit e0ee291

21 files changed

+213
-129
lines changed

common/views.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IAccount, ILabel, IMilestone, IProject, ITeam, MergeMethod, MergeMethodsAvailability } from '../src/github/interface';
6+
import { ClosedEvent, CommentEvent } from '../src/common/timelineEvent';
7+
import { GithubItemStateEnum, IAccount, ILabel, IMilestone, IProject, ITeam, MergeMethod, MergeMethodsAvailability } from '../src/github/interface';
78
import { PreReviewState } from '../src/github/views';
89

910
export interface RemoteInfo {
@@ -168,4 +169,10 @@ export interface TitleAndDescriptionResult {
168169
description: string | undefined;
169170
}
170171

172+
export interface CloseResult {
173+
state: GithubItemStateEnum;
174+
commentEvent?: CommentEvent;
175+
closeEvent: ClosedEvent;
176+
}
177+
171178
// #endregion

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,6 @@
828828
"title": "%command.pr.readyForReview.title%",
829829
"category": "%command.pull.request.category%"
830830
},
831-
{
832-
"command": "pr.close",
833-
"title": "%command.pr.close.title%",
834-
"category": "%command.pull.request.category%"
835-
},
836831
{
837832
"command": "pr.openPullRequestOnGitHub",
838833
"title": "%command.pr.openPullRequestOnGitHub.title%",
@@ -1776,10 +1771,6 @@
17761771
"command": "review.openLocalFile",
17771772
"when": "false"
17781773
},
1779-
{
1780-
"command": "pr.close",
1781-
"when": "gitHubOpenRepositoryCount != 0 && github:inReviewMode"
1782-
},
17831774
{
17841775
"command": "pr.create",
17851776
"when": "gitHubOpenRepositoryCount != 0 && github:authenticated"

package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
"command.pr.dismissNotification.title": "Dismiss Notification",
174174
"command.pr.merge.title": "Merge Pull Request",
175175
"command.pr.readyForReview.title": "Mark Pull Request Ready For Review",
176-
"command.pr.close.title": "Close Pull Request",
177176
"command.pr.openPullRequestOnGitHub.title": "Open Pull Request on GitHub",
178177
"command.pr.openAllDiffs.title": "Open All Diffs",
179178
"command.pr.refreshPullRequest.title": "Refresh Pull Request",

src/commands.ts

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as vscode from 'vscode';
99
import { Repository } from './api/api';
1010
import { GitErrorCodes } from './api/api1';
1111
import { CommentReply, findActiveHandler, resolveCommentHandler } from './commentHandlerResolver';
12-
import { IComment } from './common/comment';
1312
import { commands } from './common/executeCommands';
1413
import Logger from './common/logger';
1514
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
@@ -20,7 +19,7 @@ import { formatError } from './common/utils';
2019
import { EXTENSION_ID } from './constants';
2120
import { FolderRepositoryManager } from './github/folderRepositoryManager';
2221
import { GitHubRepository } from './github/githubRepository';
23-
import { Issue, PullRequest } from './github/interface';
22+
import { Issue } from './github/interface';
2423
import { IssueModel } from './github/issueModel';
2524
import { IssueOverviewPanel } from './github/issueOverview';
2625
import { NotificationProvider } from './github/notifications';
@@ -46,9 +45,6 @@ import {
4645
import { PRNode } from './view/treeNodes/pullRequestNode';
4746
import { RepositoryChangesNode } from './view/treeNodes/repositoryChangesNode';
4847

49-
const _onDidUpdatePR = new vscode.EventEmitter<PullRequest | void>();
50-
export const onDidUpdatePR: vscode.Event<PullRequest | void> = _onDidUpdatePR.event;
51-
5248
function ensurePR(folderRepoManager: FolderRepositoryManager, pr?: PRNode): PullRequestModel;
5349
function ensurePR<TIssue extends Issue, TIssueModel extends IssueModel<TIssue>>(folderRepoManager: FolderRepositoryManager, pr?: TIssueModel): TIssueModel;
5450
function ensurePR<TIssue extends Issue, TIssueModel extends IssueModel<TIssue>>(folderRepoManager: FolderRepositoryManager, pr?: PRNode | TIssueModel): TIssueModel {
@@ -749,56 +745,6 @@ export function registerCommands(
749745
}),
750746
);
751747

752-
context.subscriptions.push(
753-
vscode.commands.registerCommand('pr.close', async (pr?: PRNode | PullRequestModel, message?: string) => {
754-
let pullRequestModel: PullRequestModel | undefined;
755-
if (pr) {
756-
pullRequestModel = pr instanceof PullRequestModel ? pr : pr.pullRequestModel;
757-
} else {
758-
const activePullRequests: PullRequestModel[] = reposManager.folderManagers
759-
.map(folderManager => folderManager.activePullRequest!)
760-
.filter(activePR => !!activePR);
761-
pullRequestModel = await chooseItem<PullRequestModel>(
762-
activePullRequests,
763-
itemValue => `${itemValue.number}: ${itemValue.title}`,
764-
{ placeHolder: vscode.l10n.t('Pull request to close') },
765-
);
766-
}
767-
if (!pullRequestModel) {
768-
return;
769-
}
770-
const pullRequest: PullRequestModel = pullRequestModel;
771-
const yes = vscode.l10n.t('Yes');
772-
return vscode.window
773-
.showWarningMessage(
774-
vscode.l10n.t('Are you sure you want to close this pull request on GitHub? This will close the pull request without merging.'),
775-
{ modal: true },
776-
yes,
777-
vscode.l10n.t('No'),
778-
)
779-
.then(async value => {
780-
if (value === yes) {
781-
try {
782-
let newComment: IComment | undefined = undefined;
783-
if (message) {
784-
newComment = await pullRequest.createIssueComment(message);
785-
}
786-
787-
const newPR = await pullRequest.close();
788-
vscode.commands.executeCommand('pr.refreshList');
789-
_onDidUpdatePR.fire(newPR);
790-
return newComment;
791-
} catch (e) {
792-
vscode.window.showErrorMessage(`Unable to close pull request. ${formatError(e)}`);
793-
_onDidUpdatePR.fire();
794-
}
795-
}
796-
797-
_onDidUpdatePR.fire();
798-
});
799-
}),
800-
);
801-
802748
context.subscriptions.push(
803749
vscode.commands.registerCommand('pr.dismissNotification', node => {
804750
if (node instanceof PRNode) {

src/common/timelineEvent.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export enum EventType {
1919
HeadRefDeleted,
2020
Merged,
2121
CrossReferenced,
22+
Closed,
23+
Reopened,
2224
Other,
2325
}
2426

@@ -121,4 +123,18 @@ export interface CrossReferencedEvent {
121123
willCloseTarget: boolean;
122124
}
123125

124-
export type TimelineEvent = CommitEvent | ReviewEvent | CommentEvent | NewCommitsSinceReviewEvent | MergedEvent | AssignEvent | HeadRefDeleteEvent | CrossReferencedEvent;
126+
export interface ClosedEvent {
127+
id: string
128+
event: EventType.Closed;
129+
actor: IActor;
130+
createdAt: string;
131+
}
132+
133+
export interface ReopenedEvent {
134+
id: string;
135+
event: EventType.Reopened;
136+
actor: IActor;
137+
createdAt: string;
138+
}
139+
140+
export type TimelineEvent = CommitEvent | ReviewEvent | CommentEvent | NewCommitsSinceReviewEvent | MergedEvent | AssignEvent | HeadRefDeleteEvent | CrossReferencedEvent | ClosedEvent | ReopenedEvent;

src/github/activityBarViewProvider.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { onDidUpdatePR, openPullRequestOnGitHub } from '../commands';
7+
import { openPullRequestOnGitHub } from '../commands';
88
import { IComment } from '../common/comment';
99
import { disposeAll } from '../common/lifecycle';
1010
import { ReviewEvent as CommonReviewEvent } from '../common/timelineEvent';
@@ -31,18 +31,6 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
3131
) {
3232
super(extensionUri);
3333

34-
this._register(onDidUpdatePR(
35-
pr => {
36-
if (pr) {
37-
this._item.update(pr);
38-
}
39-
40-
this._postMessage({
41-
command: 'update-state',
42-
state: this._item.state,
43-
});
44-
}));
45-
4634
this._register(this._folderRepositoryManager.onDidMergePullRequest(_ => {
4735
this._postMessage({
4836
command: 'update-state',

src/github/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export namespace OctokitCommon {
3939
export type PullsCreateReviewResponseData = Endpoints['POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews']['response']['data'];
4040
export type PullsCreateReviewCommentResponseData = Endpoints['POST /repos/{owner}/{repo}/pulls/{pull_number}/comments']['response']['data'];
4141
export type PullsGetResponseData = OctokitRest.RestEndpointMethodTypes['pulls']['get']['response']['data'];
42+
export type IssuesGetResponseData = OctokitRest.RestEndpointMethodTypes['issues']['get']['response']['data'];
4243
export type PullsGetResponseUser = Exclude<PullsGetResponseData['user'], null>;
4344
export type PullsListCommitsResponseData = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/commits']['response']['data'];
4445
export type PullsListRequestedReviewersResponseData = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers']['response']['data'];

src/github/folderRepositoryManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ export class FolderRepositoryManager extends Disposable {
11541154
Logger.debug(`Fetch pull request category ${categoryQuery} - enter`, this.id);
11551155
const { octokit, query, schema } = await githubRepository.ensure();
11561156

1157-
const user = await githubRepository.getAuthenticatedUser();
1157+
const user = (await githubRepository.getAuthenticatedUser()).login;
11581158
// Search api will not try to resolve repo that redirects, so get full name first
11591159
repo = await githubRepository.getMetadata();
11601160
const { data, headers } = await octokit.call(octokit.api.search.issuesAndPullRequests, {

src/github/githubRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ export class GitHubRepository extends Disposable {
886886
}
887887
}
888888

889-
async getAuthenticatedUser(): Promise<string> {
890-
return (await this._credentialStore.getCurrentUser(this.remote.authProviderId)).login;
889+
async getAuthenticatedUser(): Promise<IAccount> {
890+
return await this._credentialStore.getCurrentUser(this.remote.authProviderId);
891891
}
892892

893893
async getAuthenticatedUserEmails(): Promise<string[]> {

src/github/graphql.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ export interface CrossReferencedEvent {
4747
willCloseTarget: boolean;
4848
}
4949

50+
export interface ClosedEvent {
51+
__typename: string;
52+
id: string;
53+
actor: Actor;
54+
createdAt: string;
55+
}
56+
57+
export interface ReopenedEvent {
58+
__typename: string;
59+
id: string;
60+
actor: Actor;
61+
createdAt: string;
62+
}
63+
5064
export interface AbbreviatedIssueComment {
5165
author: Account;
5266
body: string;

0 commit comments

Comments
 (0)