From 72f1d8784d044336a0f12c7715f948d828544758 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 24 Jan 2021 17:39:12 -0500 Subject: [PATCH] Adds create pull request notification --- CHANGELOG.md | 3 ++- package.json | 5 +++++ src/config.ts | 1 + src/git/models/repository.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ src/messages.ts | 13 +++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8942c6f..47c83de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Adds a new _Browse Repository from Before Here_ (`gitlens.browseRepoBeforeRevision`) and _Browse Repository from Before Here in New Window_ (`gitlens.browseRepoBeforeRevisionInNewWindow`) commands - Adds _Repository from Before Here_ and _Repository from Before Here in New Window_ to the _Browse_ submenu of commits in the views - Adds a new _Copy Current Branch Name_ (`gitlens.copyCurrentBranch`) command to copy the current branch name to the clipboard — closes [#1306](https://github.com/eamodio/vscode-gitlens/issues/1306) — thanks to [PR #1307](https://github.com/eamodio/vscode-gitlens/pull/1307) by Ken Hom ([@kh0m](https://github.com/kh0m)) -- Adds a `gitlens.advanced.abbreviateShaOnCopy` setting to specify to whether to copy full or abbreviated commit SHAs to the clipboard. Abbreviates to the length of `gitlens.advanced.abbreviatedShaLength` — closes [#1062](https://github.com/eamodio/vscode-gitlens/issues/1062) — thanks to [PR #1316](https://github.com/eamodio/vscode-gitlens/pull/1316) by Brendon Smith ([@br3ndonland](https://github.com/br3ndonland)) - Adds a _Switch to Text_ button on the _Interactive Rebase Editor_ to open the text rebase todo file — note that closing either document will start the rebase +- Adds a notification which asks if you want to create a pull request after publishing a new branch +- Adds a `gitlens.advanced.abbreviateShaOnCopy` setting to specify to whether to copy full or abbreviated commit SHAs to the clipboard. Abbreviates to the length of `gitlens.advanced.abbreviatedShaLength` — closes [#1062](https://github.com/eamodio/vscode-gitlens/issues/1062) — thanks to [PR #1316](https://github.com/eamodio/vscode-gitlens/pull/1316) by Brendon Smith ([@br3ndonland](https://github.com/br3ndonland)) - Adds a `gitlens.advanced.externalDiffTool` setting to specify an optional external diff tool to use when comparing files. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool). - Adds a `gitlens.advanced.externalDirectoryDiffTool` setting to specify an optional external diff tool to use when comparing directories. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool). diff --git a/package.json b/package.json index 7807159..c851685 100644 --- a/package.json +++ b/package.json @@ -2428,6 +2428,7 @@ "default": { "suppressCommitHasNoPreviousCommitWarning": false, "suppressCommitNotFoundWarning": false, + "suppressCreatePullRequestPrompt": false, "suppressFileNotUnderSourceControlWarning": false, "suppressGitDisabledWarning": false, "suppressGitVersionWarning": false, @@ -2444,6 +2445,10 @@ "type": "boolean", "default": false }, + "suppressCreatePullRequestPrompt": { + "type": "boolean", + "default": false + }, "suppressFileNotUnderSourceControlWarning": { "type": "boolean", "default": false diff --git a/src/config.ts b/src/config.ts index 7e9b8ed..57f5658 100644 --- a/src/config.ts +++ b/src/config.ts @@ -296,6 +296,7 @@ export interface AdvancedConfig { messages: { suppressCommitHasNoPreviousCommitWarning: boolean; suppressCommitNotFoundWarning: boolean; + suppressCreatePullRequestPrompt: boolean; suppressFileNotUnderSourceControlWarning: boolean; suppressGitDisabledWarning: boolean; suppressGitVersionWarning: boolean; diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index fc196c9..5d166ec 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -13,6 +13,8 @@ import { workspace, WorkspaceFolder, } from 'vscode'; +import { CreatePullRequestActionContext } from '../../api/gitlens'; +import { executeActionCommand } from '../../commands'; import { BranchSorting, configuration, TagSorting } from '../../configuration'; import { Starred, WorkspaceState } from '../../constants'; import { Container } from '../../container'; @@ -597,6 +599,10 @@ export class Repository implements Disposable { return Container.git.getRebaseStatus(this.path); } + async getRemote(remote: string): Promise { + return (await this.getRemotes()).find(r => r.name === remote); + } + getRemotes(_options: { sort?: boolean } = {}): Promise { if (this._remotes == null || !this.supportsChangeEvents) { if (this._providers == null) { @@ -722,6 +728,41 @@ export class Repository implements Disposable { )); } + private async showCreatePullRequestPrompt(remoteName: string, branch: GitBranchReference) { + if (!Container.actionRunners.count('createPullRequest')) return; + if (!(await Messages.showCreatePullRequestPrompt(branch.name))) return; + + const remote = await this.getRemote(remoteName); + const remoteInfo = + remote != null + ? { + name: remote.name, + provider: + remote.provider != null + ? { + id: remote.provider.id, + name: remote.provider.name, + domain: remote.provider.domain, + } + : undefined, + url: remote.url, + } + : { name: remoteName }; + + void executeActionCommand('createPullRequest', { + repoPath: this.path, + remote: remoteInfo, + branch: { + name: branch.name, + isRemote: branch.remote, + upstream: branch.tracking, + + remote: remoteInfo, + repoPath: this.path, + }, + }); + } + private async pushCore( options: { force?: boolean; @@ -738,6 +779,7 @@ export class Repository implements Disposable { if (options.publish != null) { await repo?.push(options.publish.remote, options.reference.name, true); + void this.showCreatePullRequestPrompt(options.publish.remote, options.reference); } else { const branch = await this.getBranch(options.reference.name); if (branch == null) return; diff --git a/src/messages.ts b/src/messages.ts index 0aca45c..cf8ca72 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -7,6 +7,7 @@ import { Logger } from './logger'; export enum SuppressedMessages { CommitHasNoPreviousCommitWarning = 'suppressCommitHasNoPreviousCommitWarning', CommitNotFoundWarning = 'suppressCommitNotFoundWarning', + CreatePullRequestPrompt = 'suppressCreatePullRequestPrompt', FileNotUnderSourceControlWarning = 'suppressFileNotUnderSourceControlWarning', GitDisabledWarning = 'suppressGitDisabledWarning', GitVersionWarning = 'suppressGitVersionWarning', @@ -39,6 +40,18 @@ export class Messages { ); } + static async showCreatePullRequestPrompt(branch: string): Promise { + const create = { title: 'Create Pull Request...' }; + const result = await Messages.showMessage( + 'info', + `Would you like to create a Pull Request for branch '${branch}'?`, + SuppressedMessages.CreatePullRequestPrompt, + { title: "Don't Show Again" }, + create, + ); + return result === create; + } + static async showGenericErrorMessage(message: string): Promise { const actions: MessageItem[] = [{ title: 'Open Output Channel' }]; const result = await Messages.showMessage(