From a462b7c42058a3133c32ddbbac6f5439ede592a9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 25 Mar 2026 12:28:54 +0100 Subject: [PATCH] Add commands for opening a Github PR in the browser For the branches panel we might consider unifying it with the existing `o` command for creating a PR: it could check if there is a PR already, and open it if so, or create a new one if not. However, I also want the command in the local commits panel for the checked out branch, and there's no existing "Create PR" command there; and the `o` command opens the selected commit in the browser, so it's unrelated. --- docs-master/Config.md | 2 + docs-master/keybindings/Keybindings_en.md | 2 + docs-master/keybindings/Keybindings_ja.md | 2 + docs-master/keybindings/Keybindings_ko.md | 2 + docs-master/keybindings/Keybindings_nl.md | 2 + docs-master/keybindings/Keybindings_pl.md | 2 + docs-master/keybindings/Keybindings_pt.md | 2 + docs-master/keybindings/Keybindings_ru.md | 2 + docs-master/keybindings/Keybindings_zh-CN.md | 2 + docs-master/keybindings/Keybindings_zh-TW.md | 2 + pkg/config/user_config.go | 76 ++++++++++--------- pkg/gui/controllers/branches_controller.go | 27 +++++++ .../controllers/local_commits_controller.go | 27 +++++++ pkg/i18n/english.go | 4 + schema-master/config.json | 8 ++ 15 files changed, 126 insertions(+), 36 deletions(-) diff --git a/docs-master/Config.md b/docs-master/Config.md index 5a26c2d7b..9931fda61 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -707,6 +707,7 @@ keybinding: branches: createPullRequest: o viewPullRequestOptions: O + openPullRequestInBrowser: G copyPullRequestURL: checkoutBranchByName: c forceCheckoutBranch: F @@ -749,6 +750,7 @@ keybinding: copyCommitAttributeToClipboard: "y" openLogMenu: openInBrowser: o + openPullRequestInBrowser: G viewBisectOptions: b startInteractiveRebase: i selectCommitsOfCurrentBranch: '*' diff --git a/docs-master/keybindings/Keybindings_en.md b/docs-master/keybindings/Keybindings_en.md index 827f6eb34..ca1541dd2 100644 --- a/docs-master/keybindings/Keybindings_en.md +++ b/docs-master/keybindings/Keybindings_en.md @@ -107,6 +107,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` t `` | Revert | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | Tag commit | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | View log options | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | Checkout | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | @@ -180,6 +181,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | Create pull request | | | `` O `` | View create pull request options | | +| `` G `` | Open pull request in browser | | | `` `` | Copy pull request URL to clipboard | | | `` c `` | Checkout by name | Checkout by name. In the input box you can enter '-' to switch to the previous branch. | | `` - `` | Checkout previous branch | | diff --git a/docs-master/keybindings/Keybindings_ja.md b/docs-master/keybindings/Keybindings_ja.md index 759edee95..69479db13 100644 --- a/docs-master/keybindings/Keybindings_ja.md +++ b/docs-master/keybindings/Keybindings_ja.md @@ -87,6 +87,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味 | `` t `` | リバート | 選択したコミットの変更を逆に適用する、リバートコミットを作成します。 | | `` T `` | コミットにタグを付ける | 選択したコミットを指すタグを新規作成します。タグ名とオプションの説明を入力するよう促されます。 | | `` `` | ログオプションを表示 | コミットログのオプションを表示します(例:並び順の変更、Gitグラフの非表示、Gitグラフ全体の表示)。 | +| `` G `` | Open pull request in browser | | | `` `` | チェックアウト(ブランチの切り替え) | 選択したコミットをデタッチドヘッド(特定のブランチに属さない状態)としてチェックアウトします。 | | `` y `` | コミット属性をクリップボードにコピー | コミット属性をクリップボードにコピーします(例:ハッシュ、URL、差分、メッセージ、作者)。 | | `` o `` | ブラウザでコミットを開く | | @@ -379,6 +380,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味 | `` N `` | コミットを新しいブランチに移動 | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | プルリクエストを作成 | | | `` O `` | プルリクエスト作成オプションを表示 | | +| `` G `` | Open pull request in browser | | | `` `` | プルリクエストURLをクリップボードにコピー | | | `` c `` | 名前でチェックアウト | 名前でチェックアウトします。入力ボックスに「-」を入力すると、最後のブランチをチェックアウトすることができます。 | | `` - `` | 直前のブランチにチェックアウト | | diff --git a/docs-master/keybindings/Keybindings_ko.md b/docs-master/keybindings/Keybindings_ko.md index 608a67963..eeb5ed885 100644 --- a/docs-master/keybindings/Keybindings_ko.md +++ b/docs-master/keybindings/Keybindings_ko.md @@ -215,6 +215,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | 풀 리퀘스트 생성 | | | `` O `` | 풀 리퀘스트 생성 옵션 | | +| `` G `` | Open pull request in browser | | | `` `` | 풀 리퀘스트 URL을 클립보드에 복사 | | | `` c `` | 이름으로 체크아웃 | Checkout by name. In the input box you can enter '-' to switch to the previous branch. | | `` - `` | Checkout previous branch | | @@ -318,6 +319,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` t `` | Revert | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | Tag commit | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | 로그 메뉴 열기 | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | 체크아웃 | Checkout the selected commit as a detached HEAD. | | `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 브라우저에서 커밋 열기 | | diff --git a/docs-master/keybindings/Keybindings_nl.md b/docs-master/keybindings/Keybindings_nl.md index 8f59d5c21..21b8c5b4c 100644 --- a/docs-master/keybindings/Keybindings_nl.md +++ b/docs-master/keybindings/Keybindings_nl.md @@ -105,6 +105,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | Maak een pull-request | | | `` O `` | Bekijk opties voor pull-aanvraag | | +| `` G `` | Open pull request in browser | | | `` `` | Kopieer de URL van het pull-verzoek naar het klembord | | | `` c `` | Uitchecken bij naam | Checkout by name. In the input box you can enter '-' to switch to the previous branch. | | `` - `` | Checkout previous branch | | @@ -178,6 +179,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` t `` | Revert | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | Tag commit | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | View log options | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | Uitchecken | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | diff --git a/docs-master/keybindings/Keybindings_pl.md b/docs-master/keybindings/Keybindings_pl.md index 63392c52e..622a134fd 100644 --- a/docs-master/keybindings/Keybindings_pl.md +++ b/docs-master/keybindings/Keybindings_pl.md @@ -80,6 +80,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | `` t `` | Cofnij | Utwórz commit cofający dla wybranego commita, który stosuje zmiany wybranego commita w odwrotnej kolejności. | | `` T `` | Otaguj commit | Utwórz nowy tag wskazujący na wybrany commit. Zostaniesz poproszony o wprowadzenie nazwy tagu i opcjonalnego opisu. | | `` `` | Zobacz opcje logów | Zobacz opcje dla logów commitów, np. zmiana kolejności sortowania, ukrywanie grafu gita, pokazywanie całego grafu gita. | +| `` G `` | Open pull request in browser | | | `` `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. | | `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). | | `` o `` | Otwórz commit w przeglądarce | | @@ -146,6 +147,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | Utwórz żądanie ściągnięcia | | | `` O `` | Zobacz opcje tworzenia pull requesta | | +| `` G `` | Open pull request in browser | | | `` `` | Kopiuj adres URL żądania ściągnięcia do schowka | | | `` c `` | Przełącz według nazwy | Przełącz według nazwy. W polu wprowadzania możesz wpisać '-' aby przełączyć się na ostatnią gałąź. | | `` - `` | Checkout previous branch | | diff --git a/docs-master/keybindings/Keybindings_pt.md b/docs-master/keybindings/Keybindings_pt.md index 56b805065..dae031477 100644 --- a/docs-master/keybindings/Keybindings_pt.md +++ b/docs-master/keybindings/Keybindings_pt.md @@ -97,6 +97,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` N `` | Mover commits para uma nova branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | Create pull request | | | `` O `` | View create pull request options | | +| `` G `` | Open pull request in browser | | | `` `` | Copiar URL do pull request para área de transferência | | | `` c `` | Checar por nome | Checar por nome. Na caixa de entrada você pode inserir '-' para trocar para a última branch | | `` - `` | Checkout da branch anterior | | @@ -182,6 +183,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` t `` | Reverter | Crie um commit reverter para o commit selecionado, que aplica as alterações do commit selecionado em reverso. | | `` T `` | Tag commit | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | View log options | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | Verificar | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | diff --git a/docs-master/keybindings/Keybindings_ru.md b/docs-master/keybindings/Keybindings_ru.md index 895e49e63..b4531eb73 100644 --- a/docs-master/keybindings/Keybindings_ru.md +++ b/docs-master/keybindings/Keybindings_ru.md @@ -189,6 +189,7 @@ _Связки клавиш_ | `` t `` | Revert | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | Пометить коммит тегом | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | Открыть меню журнала | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | Переключить | Checkout the selected commit as a detached HEAD. | | `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Открыть коммит в браузере | | @@ -214,6 +215,7 @@ _Связки клавиш_ | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | Создать запрос на принятие изменений | | | `` O `` | Создать параметры запроса принятие изменений | | +| `` G `` | Open pull request in browser | | | `` `` | Скопировать URL запроса на принятие изменений в буфер обмена | | | `` c `` | Переключить по названию | Checkout by name. In the input box you can enter '-' to switch to the previous branch. | | `` - `` | Checkout previous branch | | diff --git a/docs-master/keybindings/Keybindings_zh-CN.md b/docs-master/keybindings/Keybindings_zh-CN.md index 8e7ef420c..0385e486b 100644 --- a/docs-master/keybindings/Keybindings_zh-CN.md +++ b/docs-master/keybindings/Keybindings_zh-CN.md @@ -144,6 +144,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ | `` t `` | 撤销(Revert) | 为所选提交创建还原提交,这会反向应用所选提交的更改。 | | `` T `` | 标签提交 | 创建一个新标签指向所选提交。您可以在弹窗中输入标签名称和描述(可选)。 | | `` `` | 打开日志菜单 | 查看提交日志的选项,例如更改排序顺序、隐藏 git graph、显示整个 git graph。 | +| `` G `` | Open pull request in browser | | | `` `` | 检出 | 检出所选择的提交作为分离HEAD。 | | `` y `` | 复制提交属性到剪贴板 | 复制提交属性到剪贴板(如hash、URL、diff、消息、作者)。 | | `` o `` | 在浏览器中打开提交 | | @@ -229,6 +230,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ | `` N `` | 移动提交至新分支 | 创建一个新分支,并将当前分支未推送的提交移动到该分支。如果您打算开始新工作但忘记先创建新分支,这会很有用。

请注意,此操作忽略选择,新分支总是从主分支创建或堆叠在当前分支之上(您可以选择哪种方式)。 | | `` o `` | 创建拉取请求 | | | `` O `` | 创建拉取请求选项 | | +| `` G `` | Open pull request in browser | | | `` `` | 复制拉取请求 URL 到剪贴板 | | | `` c `` | 按名称检出 | 按名称检出。在输入框中,您可以输入'-' 来切换到最后一个分支。 | | `` - `` | 签出上一个分支 | | diff --git a/docs-master/keybindings/Keybindings_zh-TW.md b/docs-master/keybindings/Keybindings_zh-TW.md index bbd2f291d..c0579e0ce 100644 --- a/docs-master/keybindings/Keybindings_zh-TW.md +++ b/docs-master/keybindings/Keybindings_zh-TW.md @@ -203,6 +203,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | `` t `` | 還原 | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | 打標籤到提交 | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | 開啟記錄選單 | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` G `` | Open pull request in browser | | | `` `` | 檢出 | Checkout the selected commit as a detached HEAD. | | `` y `` | 複製提交屬性 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 在瀏覽器中開啟提交 | | @@ -289,6 +290,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.

Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). | | `` o `` | 建立拉取請求 | | | `` O `` | 建立拉取請求選項 | | +| `` G `` | Open pull request in browser | | | `` `` | 複製拉取請求的 URL 到剪貼板 | | | `` c `` | 根據名稱檢出 | Checkout by name. In the input box you can enter '-' to switch to the previous branch. | | `` - `` | Checkout previous branch | | diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index dac5f6b8b..fde680d12 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -531,24 +531,25 @@ type KeybindingFilesConfig struct { } type KeybindingBranchesConfig struct { - CreatePullRequest string `yaml:"createPullRequest"` - ViewPullRequestOptions string `yaml:"viewPullRequestOptions"` - CopyPullRequestURL string `yaml:"copyPullRequestURL"` - CheckoutBranchByName string `yaml:"checkoutBranchByName"` - ForceCheckoutBranch string `yaml:"forceCheckoutBranch"` - CheckoutPreviousBranch string `yaml:"checkoutPreviousBranch"` - RebaseBranch string `yaml:"rebaseBranch"` - RenameBranch string `yaml:"renameBranch"` - MergeIntoCurrentBranch string `yaml:"mergeIntoCurrentBranch"` - MoveCommitsToNewBranch string `yaml:"moveCommitsToNewBranch"` - ViewGitFlowOptions string `yaml:"viewGitFlowOptions"` - FastForward string `yaml:"fastForward"` - CreateTag string `yaml:"createTag"` - PushTag string `yaml:"pushTag"` - SetUpstream string `yaml:"setUpstream"` - FetchRemote string `yaml:"fetchRemote"` - AddForkRemote string `yaml:"addForkRemote"` - SortOrder string `yaml:"sortOrder"` + CreatePullRequest string `yaml:"createPullRequest"` + ViewPullRequestOptions string `yaml:"viewPullRequestOptions"` + OpenPullRequestInBrowser string `yaml:"openPullRequestInBrowser"` + CopyPullRequestURL string `yaml:"copyPullRequestURL"` + CheckoutBranchByName string `yaml:"checkoutBranchByName"` + ForceCheckoutBranch string `yaml:"forceCheckoutBranch"` + CheckoutPreviousBranch string `yaml:"checkoutPreviousBranch"` + RebaseBranch string `yaml:"rebaseBranch"` + RenameBranch string `yaml:"renameBranch"` + MergeIntoCurrentBranch string `yaml:"mergeIntoCurrentBranch"` + MoveCommitsToNewBranch string `yaml:"moveCommitsToNewBranch"` + ViewGitFlowOptions string `yaml:"viewGitFlowOptions"` + FastForward string `yaml:"fastForward"` + CreateTag string `yaml:"createTag"` + PushTag string `yaml:"pushTag"` + SetUpstream string `yaml:"setUpstream"` + FetchRemote string `yaml:"fetchRemote"` + AddForkRemote string `yaml:"addForkRemote"` + SortOrder string `yaml:"sortOrder"` } type KeybindingWorktreesConfig struct { @@ -579,6 +580,7 @@ type KeybindingCommitsConfig struct { CopyCommitAttributeToClipboard string `yaml:"copyCommitAttributeToClipboard"` OpenLogMenu string `yaml:"openLogMenu"` OpenInBrowser string `yaml:"openInBrowser"` + OpenPullRequestInBrowser string `yaml:"openPullRequestInBrowser"` ViewBisectOptions string `yaml:"viewBisectOptions"` StartInteractiveRebase string `yaml:"startInteractiveRebase"` SelectCommitsOfCurrentBranch string `yaml:"selectCommitsOfCurrentBranch"` @@ -996,24 +998,25 @@ func GetDefaultConfig() *UserConfig { ExpandAll: "=", }, Branches: KeybindingBranchesConfig{ - CopyPullRequestURL: "", - CreatePullRequest: "o", - ViewPullRequestOptions: "O", - CheckoutBranchByName: "c", - ForceCheckoutBranch: "F", - CheckoutPreviousBranch: "-", - RebaseBranch: "r", - RenameBranch: "R", - MergeIntoCurrentBranch: "M", - MoveCommitsToNewBranch: "N", - ViewGitFlowOptions: "i", - FastForward: "f", - CreateTag: "T", - PushTag: "P", - SetUpstream: "u", - FetchRemote: "f", - AddForkRemote: "F", - SortOrder: "s", + CopyPullRequestURL: "", + CreatePullRequest: "o", + ViewPullRequestOptions: "O", + OpenPullRequestInBrowser: "G", + CheckoutBranchByName: "c", + ForceCheckoutBranch: "F", + CheckoutPreviousBranch: "-", + RebaseBranch: "r", + RenameBranch: "R", + MergeIntoCurrentBranch: "M", + MoveCommitsToNewBranch: "N", + ViewGitFlowOptions: "i", + FastForward: "f", + CreateTag: "T", + PushTag: "P", + SetUpstream: "u", + FetchRemote: "f", + AddForkRemote: "F", + SortOrder: "s", }, Worktrees: KeybindingWorktreesConfig{ ViewWorktreeOptions: "w", @@ -1042,6 +1045,7 @@ func GetDefaultConfig() *UserConfig { CopyCommitAttributeToClipboard: "y", OpenLogMenu: "", OpenInBrowser: "o", + OpenPullRequestInBrowser: "G", ViewBisectOptions: "b", StartInteractiveRebase: "i", SelectCommitsOfCurrentBranch: "*", diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index f8a8d7c90..eedd1542a 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -81,6 +81,12 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty Description: self.c.Tr.CreatePullRequestOptions, OpensMenu: true, }, + { + Key: opts.GetKey(opts.Config.Branches.OpenPullRequestInBrowser), + Handler: self.withItem(self.openPRInBrowser), + GetDisabledReason: self.require(self.singleItemSelected(self.branchHasPR)), + Description: self.c.Tr.OpenPullRequestInBrowser, + }, { Key: opts.GetKey(opts.Config.Branches.CopyPullRequestURL), Handler: self.copyPullRequestURL, @@ -930,6 +936,27 @@ func (self *BranchesController) branchIsReal(branch *models.Branch) *types.Disab return nil } +func (self *BranchesController) branchHasPR(branch *models.Branch) *types.DisabledReason { + if _, ok := self.c.Model().PullRequestsMap[branch.Name]; !ok { + return &types.DisabledReason{Text: self.c.Tr.NoPullRequestForBranch, ShowErrorInPanel: true} + } + + return nil +} + +func (self *BranchesController) openPRInBrowser(branch *models.Branch) error { + pr, ok := self.c.Model().PullRequestsMap[branch.Name] + if !ok { + // Should be guarded against by the DisabledReason check, but be defensive in case + // PullRequestsMap was updated concurrently by a background refresh + return errors.New(self.c.Tr.NoPullRequestForBranch) + } + + self.c.LogAction(self.c.Tr.Actions.OpenPullRequest) + + return self.c.OS().OpenLink(pr.Url) +} + func (self *BranchesController) branchesAreReal(selectedBranches []*models.Branch, startIdx int, endIdx int) *types.DisabledReason { if !lo.EveryBy(selectedBranches, func(branch *models.Branch) bool { return branch.IsRealBranch() diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 51b031376..e4f88b3ca 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -253,11 +253,38 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Tooltip: self.c.Tr.OpenLogMenuTooltip, OpensMenu: true, }, + { + Key: opts.GetKey(opts.Config.Commits.OpenPullRequestInBrowser), + Handler: self.openPRInBrowser, + GetDisabledReason: self.checkedOutBranchHasPR, + Description: self.c.Tr.OpenPullRequestInBrowser, + }, } return bindings } +func (self *LocalCommitsController) checkedOutBranchHasPR() *types.DisabledReason { + branch := self.c.Model().CheckedOutBranch + if _, ok := self.c.Model().PullRequestsMap[branch]; !ok { + return &types.DisabledReason{Text: self.c.Tr.NoPullRequestForBranch, ShowErrorInPanel: true} + } + return nil +} + +func (self *LocalCommitsController) openPRInBrowser() error { + pr, ok := self.c.Model().PullRequestsMap[self.c.Model().CheckedOutBranch] + if !ok { + // Should be guarded against by the DisabledReason check, but be defensive in case + // PullRequestsMap was updated concurrently by a background refresh + return errors.New(self.c.Tr.NoPullRequestForBranch) + } + + self.c.LogAction(self.c.Tr.Actions.OpenPullRequest) + + return self.c.OS().OpenLink(pr.Url) +} + func (self *LocalCommitsController) GetOnRenderToMain() func() { return func() { self.c.Helpers().Diff.WithDiffModeCheck(func() { diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b55214d79..079f6c991 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -282,6 +282,8 @@ type TranslationSet struct { AllBranchesLogGraphReverse string UnsupportedGitService string CopyPullRequestURL string + OpenPullRequestInBrowser string + NoPullRequestForBranch string NoBranchOnRemote string Fetch string FetchTooltip string @@ -1397,6 +1399,8 @@ func EnglishTranslationSet() *TranslationSet { UnsupportedGitService: `Unsupported git service`, CreatePullRequest: `Create pull request`, CopyPullRequestURL: `Copy pull request URL to clipboard`, + OpenPullRequestInBrowser: `Open pull request in browser`, + NoPullRequestForBranch: `No pull request found for this branch`, NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`, Fetch: `Fetch`, FetchTooltip: "Fetch changes from remote.", diff --git a/schema-master/config.json b/schema-master/config.json index d4e450493..4f60000d2 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -861,6 +861,10 @@ "type": "string", "default": "O" }, + "openPullRequestInBrowser": { + "type": "string", + "default": "G" + }, "copyPullRequestURL": { "type": "string", "default": "\u003cc-y\u003e" @@ -1043,6 +1047,10 @@ "type": "string", "default": "o" }, + "openPullRequestInBrowser": { + "type": "string", + "default": "G" + }, "viewBisectOptions": { "type": "string", "default": "b"