mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-16 00:43:20 +01:00
close pull request
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -72,6 +72,10 @@
|
||||
"command": "pr.pick",
|
||||
"title": "Checkout Pull Request"
|
||||
},
|
||||
{
|
||||
"command": "pr.close",
|
||||
"title": "Close Pull Request"
|
||||
},
|
||||
{
|
||||
"command": "pr.openInGitHub",
|
||||
"title": "Open in GitHub"
|
||||
@@ -106,6 +110,10 @@
|
||||
"command": "pr.openInGitHub",
|
||||
"when": "view == pr && viewItem =~ /pullrequest/"
|
||||
},
|
||||
{
|
||||
"command": "pr.close",
|
||||
"when": "view == pr && viewItem =~ /pullrequest/"
|
||||
},
|
||||
{
|
||||
"command": "pr.openInGitHub",
|
||||
"when": "view =~ /(pr|prStatus)/ && viewItem == filechange"
|
||||
@@ -123,7 +131,7 @@
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -watch -p ./",
|
||||
"watch": "npm run build-preview && npm run compile",
|
||||
"watch-preview": "npm run build-preview",
|
||||
"build-preview": "webpack --watch --mode development"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -11,9 +11,12 @@ const vscode = acquireVsCodeApi();
|
||||
function handleMessage(event: any) {
|
||||
const message = event.data; // The json data that the extension sent
|
||||
switch (message.command) {
|
||||
case 'initialize':
|
||||
case 'pr.initialize':
|
||||
renderPullRequest(message.pullrequest);
|
||||
break;
|
||||
case 'pr.update':
|
||||
updatePullRequest(message.pullrequest);
|
||||
break;
|
||||
case 'checked-out':
|
||||
updateCheckoutButton(true);
|
||||
break;
|
||||
@@ -35,6 +38,12 @@ function renderPullRequest(pullRequest: any) {
|
||||
addEventListeners();
|
||||
}
|
||||
|
||||
function updatePullRequest(pullRequest: any) {
|
||||
if (pullRequest.state || pullRequest.body || pullRequest.author || pullRequest.title) {
|
||||
setTitleHTML(pullRequest);
|
||||
}
|
||||
}
|
||||
|
||||
function setTitleHTML(pr: any) {
|
||||
document.getElementById('title')!.innerHTML = `
|
||||
<div class="prIcon"><svg width="64" height="64" class="octicon octicon-git-compare" viewBox="0 0 14 16" version="1.1" aria-hidden="true"><path fill="#FFFFFF" fill-rule="evenodd" d="M5 12H4c-.27-.02-.48-.11-.69-.31-.21-.2-.3-.42-.31-.69V4.72A1.993 1.993 0 0 0 2 1a1.993 1.993 0 0 0-1 3.72V11c.03.78.34 1.47.94 2.06.6.59 1.28.91 2.06.94h1v2l3-3-3-3v2zM2 1.8c.66 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2C1.35 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2zm11 9.48V5c-.03-.78-.34-1.47-.94-2.06-.6-.59-1.28-.91-2.06-.94H9V0L6 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 12 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg></div>
|
||||
@@ -70,6 +79,13 @@ function addEventListeners() {
|
||||
});
|
||||
(<HTMLTextAreaElement>document.getElementById('commentTextArea')!).value = '';
|
||||
});
|
||||
|
||||
document.getElementById('close-button')!.addEventListener('click', () => {
|
||||
(<HTMLButtonElement>document.getElementById('close-button')).disabled = true;
|
||||
vscode.postMessage({
|
||||
command: 'pr.close'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function appendComment(comment: any) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user