diff --git a/package.json b/package.json index b7413f83..55443063 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,14 @@ "title": "Set Personal Access Token...", "category": "GitHub" }, + { + "command": "extension.createSimplePullRequest", + "title": "Create pull request from current branch (quick)", + "category": "GitHub" + }, { "command": "extension.createPullRequest", - "title": "Create pull request from current branch", + "title": "Create pull request...", "category": "GitHub" }, { diff --git a/src/extension.ts b/src/extension.ts index c43d0f00..96d022b5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -37,6 +37,8 @@ class Extension { context.subscriptions.push( vscode.commands.registerCommand('extension.setGitHubToken', this.createGithubTokenCommand(context)), + vscode.commands.registerCommand('extension.createSimplePullRequest', + this.wrapCommand(this.createSimplePullRequest)), vscode.commands.registerCommand('extension.createPullRequest', this.wrapCommand(this.createPullRequest)), vscode.commands.registerCommand('extension.checkoutPullRequests', this.wrapCommand(this.checkoutPullRequests)), vscode.commands.registerCommand('extension.browserPullRequest', this.wrapCommand(this.browserPullRequest)), @@ -99,7 +101,34 @@ class Extension { }; } + private async createSimplePullRequest(): Promise { + const pullRequest = await this.githubManager.createPullRequest(); + if (pullRequest) { + this.statusBarManager.updateStatus(); + vscode.window.showInformationMessage(`Successfully created #${pullRequest.number}`); + } + } + private async createPullRequest(): Promise { + const repository = await this.githubManager.getRepository(); + if (repository.parent) { + const items = [{ + label: repository.full_name, + description: '' + }, { + label: repository.parent.full_name, + description: '' + }]; + const selectedRepository = await vscode.window.showQuickPick(items); + if (selectedRepository) { + console.log(selectedRepository); + } + } + const [owner, repo] = await git.getGitHubOwnerAndRepository(this.cwd); + console.log('o', owner, 'repo', repo); + if (1 + 1 === 2) { + return; + } const pullRequest = await this.githubManager.createPullRequest(); if (pullRequest) { this.statusBarManager.updateStatus(); diff --git a/src/github-manager.ts b/src/github-manager.ts index e0d66c8e..ff4ea79e 100644 --- a/src/github-manager.ts +++ b/src/github-manager.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; import * as git from './git'; import {getClient, GitHub, GitHubError, PullRequest, ListPullRequestsParameters, CreatePullRequestBody, - PullRequestStatus, Merge, MergeMethod} from './github'; + PullRequestStatus, Merge, MergeMethod, Repository} from './github'; export class GitHubManager { @@ -30,22 +30,25 @@ export class GitHubManager { this.github = getClient(token); } - public async getDefaultBranch(): Promise { + public async getRepository(): Promise { const [owner, repository] = await git.getGitHubOwnerAndRepository(this.cwd); - return (await this.github.getRepository(owner, repository)).body.default_branch; + return (await this.github.getRepository(owner, repository)).body; + } + + public async getDefaultBranch(): Promise { + return (await this.getRepository()).default_branch; } public async getEnabledMergeMethods(): Promise> { - const [owner, repository] = await git.getGitHubOwnerAndRepository(this.cwd); - const repo = await this.github.getRepository(owner, repository); + const repo = await this.getRepository(); const set = new Set(); - if (repo.body.allow_merge_commit) { + if (repo.allow_merge_commit) { set.add('merge'); } - if (repo.body.allow_squash_merge) { + if (repo.allow_squash_merge) { set.add('squash'); } - if (repo.body.allow_rebase_merge) { + if (repo.allow_rebase_merge) { set.add('rebase'); } return set; diff --git a/src/github.ts b/src/github.ts index 736dec30..5ca4c40c 100644 --- a/src/github.ts +++ b/src/github.ts @@ -26,10 +26,15 @@ export interface GitHubResponse { } export interface Repository { + full_name: string; default_branch: string; allow_rebase_merge: boolean; allow_squash_merge: boolean; allow_merge_commit: boolean; + parent?: { + full_name: string; + default_branch: string; + }; } export type MergeMethod = 'merge' | 'squash' | 'rebase';