close pull request

This commit is contained in:
Peng Lyu
2018-05-21 11:32:15 -07:00
parent a857fd580a
commit 2ccad33b9b
7 changed files with 85 additions and 9 deletions
+11
View File
@@ -35,6 +35,17 @@ export function registerCommands(context: vscode.ExtensionContext) {
});
}));
context.subscriptions.push(vscode.commands.registerCommand('pr.close', async (pr: PullRequestModel) => {
vscode.window.showWarningMessage(`Are you sure you want to close PR`, 'Yes', 'No').then(async value => {
if (value === 'Yes') {
let newPR = await pr.close();
return newPR;
}
return null;
});
}));
context.subscriptions.push(vscode.commands.registerCommand('pr.openDescription', async (pr: PullRequestModel) => {
// Create and show a new webview
PullRequestOverviewPanel.createOrShow(context.extensionPath, pr);
@@ -48,6 +48,10 @@ export class PullRequestModel {
public base: GitHubRef;
constructor(public readonly otcokit: any, public readonly remote: Remote, public prItem: any) {
this.update(prItem);
}
update(prItem: any) {
this.prNumber = prItem.number;
this.title = prItem.title;
this.html_url = prItem.html_url;
@@ -185,6 +189,17 @@ export class PullRequestModel {
return this.prItem.user.avatar_url;
}
async close() {
let ret = await this.otcokit.pullRequests.update({
owner: this.remote.owner,
repo: this.remote.repositoryName,
number: this.prItem.number,
state: 'closed'
});
return ret.data;
}
equals(other: PullRequestModel): boolean {
if (!other) {
return false;
@@ -9,8 +9,6 @@ import * as path from 'path';
import { PullRequestModel } from './models/pullRequestModel';
import { ReviewManager } from '../review/reviewManager';
const MarkdownIt = require('markdown-it');
export class PullRequestOverviewPanel {
/**
* Track the currently panel. Only allow a single panel to exist at a time.
@@ -23,7 +21,6 @@ export class PullRequestOverviewPanel {
private readonly _extensionPath: string;
private _disposables: vscode.Disposable[] = [];
private _pullRequest: PullRequestModel;
private _md = MarkdownIt();
public static createOrShow(extensionPath: string, pullRequestModel: PullRequestModel) {
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
@@ -73,7 +70,7 @@ export class PullRequestOverviewPanel {
const isCurrentlyCheckedOut = pullRequestModel.equals(ReviewManager.instance.currentPullRequest);
const timelineEvents = await pullRequestModel.getTimelineEvents();
this._panel.webview.postMessage({
command: 'initialize',
command: 'pr.initialize',
pullrequest: {
number: pullRequestModel.prNumber,
title: pullRequestModel.title,
@@ -102,6 +99,21 @@ export class PullRequestOverviewPanel {
});
});
return;
case 'pr.close':
vscode.commands.executeCommand('pr.close', this._pullRequest).then(pr => {
if (pr) {
this._pullRequest.update(pr);
this._panel.webview.postMessage({
command: 'pr-update',
pullrequest: {
title: this._pullRequest.title,
body: this._pullRequest.prItem.body,
author: this._pullRequest.author,
state: this._pullRequest.state,
}
});
}
});
case 'pr.comment':
const text = message.text;
this._pullRequest.createDiscussionComment(text).then(comment => {
@@ -45,7 +45,7 @@ export class ReviewManager implements vscode.DecorationProvider {
private _prFileChangesProvider: FileChangesProvider;
get prFileChangesProvider() {
if (!this._prFileChangesProvider) {
this._prFileChangesProvider = new FileChangesProvider(this._context, this._pr);
this._prFileChangesProvider = new FileChangesProvider(this._context);
this._disposables.push(this._prFileChangesProvider);
}