mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-02 23:27:32 +02:00
Add mapping to copy a pull request URL to the clipboard
This commit is contained in:
parent
4e1d3e45a3
commit
79888d3bde
@ -91,10 +91,29 @@ func NewPullRequest(gitCommand *GitCommand) *PullRequest {
|
|||||||
|
|
||||||
// Create opens link to new pull request in browser
|
// Create opens link to new pull request in browser
|
||||||
func (pr *PullRequest) Create(branch *models.Branch) error {
|
func (pr *PullRequest) Create(branch *models.Branch) error {
|
||||||
|
pullRequestURL, err := pr.getPullRequestURL(branch)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pr.GitCommand.OSCommand.OpenLink(pullRequestURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyURL copies the pull request URL to the clipboard
|
||||||
|
func (pr *PullRequest) CopyURL(branch *models.Branch) error {
|
||||||
|
pullRequestURL, err := pr.getPullRequestURL(branch)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pr.GitCommand.OSCommand.CopyToClipboard(pullRequestURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PullRequest) getPullRequestURL(branch *models.Branch) (string, error) {
|
||||||
branchExistsOnRemote := pr.GitCommand.CheckRemoteBranchExists(branch)
|
branchExistsOnRemote := pr.GitCommand.CheckRemoteBranchExists(branch)
|
||||||
|
|
||||||
if !branchExistsOnRemote {
|
if !branchExistsOnRemote {
|
||||||
return errors.New(pr.GitCommand.Tr.NoBranchOnRemote)
|
return "", errors.New(pr.GitCommand.Tr.NoBranchOnRemote)
|
||||||
}
|
}
|
||||||
|
|
||||||
repoURL := pr.GitCommand.GetRemoteURL()
|
repoURL := pr.GitCommand.GetRemoteURL()
|
||||||
@ -108,14 +127,15 @@ func (pr *PullRequest) Create(branch *models.Branch) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if gitService == nil {
|
if gitService == nil {
|
||||||
return errors.New(pr.GitCommand.Tr.UnsupportedGitService)
|
return "", errors.New(pr.GitCommand.Tr.UnsupportedGitService)
|
||||||
}
|
}
|
||||||
|
|
||||||
repoInfo := getRepoInfoFromURL(repoURL)
|
repoInfo := getRepoInfoFromURL(repoURL)
|
||||||
|
pullRequestURL := fmt.Sprintf(
|
||||||
return pr.GitCommand.OSCommand.OpenLink(fmt.Sprintf(
|
|
||||||
gitService.PullRequestURL, repoInfo.Owner, repoInfo.Repository, branch.Name,
|
gitService.PullRequestURL, repoInfo.Owner, repoInfo.Repository, branch.Name,
|
||||||
))
|
)
|
||||||
|
|
||||||
|
return pullRequestURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRepoInfoFromURL(url string) *RepoInformation {
|
func getRepoInfoFromURL(url string) *RepoInformation {
|
||||||
|
@ -169,6 +169,7 @@ type KeybindingFilesConfig struct {
|
|||||||
|
|
||||||
type KeybindingBranchesConfig struct {
|
type KeybindingBranchesConfig struct {
|
||||||
CreatePullRequest string `yaml:"createPullRequest"`
|
CreatePullRequest string `yaml:"createPullRequest"`
|
||||||
|
CopyPullRequestURL string `yaml:"copyPullRequestURL"`
|
||||||
CheckoutBranchByName string `yaml:"checkoutBranchByName"`
|
CheckoutBranchByName string `yaml:"checkoutBranchByName"`
|
||||||
ForceCheckoutBranch string `yaml:"forceCheckoutBranch"`
|
ForceCheckoutBranch string `yaml:"forceCheckoutBranch"`
|
||||||
RebaseBranch string `yaml:"rebaseBranch"`
|
RebaseBranch string `yaml:"rebaseBranch"`
|
||||||
@ -383,6 +384,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
Fetch: "f",
|
Fetch: "f",
|
||||||
},
|
},
|
||||||
Branches: KeybindingBranchesConfig{
|
Branches: KeybindingBranchesConfig{
|
||||||
|
CopyPullRequestURL: "c",
|
||||||
CreatePullRequest: "o",
|
CreatePullRequest: "o",
|
||||||
CheckoutBranchByName: "c",
|
CheckoutBranchByName: "c",
|
||||||
ForceCheckoutBranch: "F",
|
ForceCheckoutBranch: "F",
|
||||||
|
@ -99,6 +99,19 @@ func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleCopyPullRequestURLPress(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
pullRequest := commands.NewPullRequest(gui.GitCommand)
|
||||||
|
|
||||||
|
branch := gui.getSelectedBranch()
|
||||||
|
if err := pullRequest.CopyURL(branch); err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.createPopupPanel(createPopupPanelOpts{
|
||||||
|
prompt: "Pull request URL copied to clipboard",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleGitFetch(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleGitFetch(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.createLoaderPanel(gui.Tr.FetchWait); err != nil {
|
if err := gui.createLoaderPanel(gui.Tr.FetchWait); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -505,6 +505,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleCreatePullRequestPress,
|
Handler: gui.handleCreatePullRequestPress,
|
||||||
Description: gui.Tr.LcCreatePullRequest,
|
Description: gui.Tr.LcCreatePullRequest,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ViewName: "branches",
|
||||||
|
Contexts: []string{LOCAL_BRANCHES_CONTEXT_KEY},
|
||||||
|
Key: gui.getKey(config.Branches.CopyPullRequestURL),
|
||||||
|
Handler: gui.handleCopyPullRequestURLPress,
|
||||||
|
Description: gui.Tr.LcCopyPullRequestURL,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ViewName: "branches",
|
ViewName: "branches",
|
||||||
Contexts: []string{LOCAL_BRANCHES_CONTEXT_KEY},
|
Contexts: []string{LOCAL_BRANCHES_CONTEXT_KEY},
|
||||||
|
@ -154,6 +154,7 @@ func dutchTranslationSet() TranslationSet {
|
|||||||
SwitchRepo: "wissel naar een recente repo",
|
SwitchRepo: "wissel naar een recente repo",
|
||||||
UnsupportedGitService: `Niet-ondersteunde git-service`,
|
UnsupportedGitService: `Niet-ondersteunde git-service`,
|
||||||
LcCreatePullRequest: `maak een pull-aanvraag`,
|
LcCreatePullRequest: `maak een pull-aanvraag`,
|
||||||
|
LcCopyPullRequestURL: `kopieer de URL van het pull-verzoek naar het klembord`,
|
||||||
NoBranchOnRemote: `Deze branch bestaat niet op de remote. U moet het eerst naar de remote pushen.`,
|
NoBranchOnRemote: `Deze branch bestaat niet op de remote. U moet het eerst naar de remote pushen.`,
|
||||||
LcFetch: `fetch`,
|
LcFetch: `fetch`,
|
||||||
NoAutomaticGitFetchTitle: `Geen automatische git fetch`,
|
NoAutomaticGitFetchTitle: `Geen automatische git fetch`,
|
||||||
@ -380,5 +381,6 @@ func dutchTranslationSet() TranslationSet {
|
|||||||
NoFilesStagedPrompt: "Je hebt geen bestanden gestaged. Commit alle bestanden?",
|
NoFilesStagedPrompt: "Je hebt geen bestanden gestaged. Commit alle bestanden?",
|
||||||
BranchNotFoundTitle: "Branch niet gevonden",
|
BranchNotFoundTitle: "Branch niet gevonden",
|
||||||
BranchNotFoundPrompt: "Branch niet gevonden. Creëer een nieuwe branch genaamd",
|
BranchNotFoundPrompt: "Branch niet gevonden. Creëer een nieuwe branch genaamd",
|
||||||
|
PullRequestURLCopiedToClipboard: "Pull-aanvraag-URL gekopieerd naar klembord",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,7 @@ type TranslationSet struct {
|
|||||||
SwitchRepo string
|
SwitchRepo string
|
||||||
UnsupportedGitService string
|
UnsupportedGitService string
|
||||||
LcCreatePullRequest string
|
LcCreatePullRequest string
|
||||||
|
LcCopyPullRequestURL string
|
||||||
NoBranchOnRemote string
|
NoBranchOnRemote string
|
||||||
LcFetch string
|
LcFetch string
|
||||||
NoAutomaticGitFetchTitle string
|
NoAutomaticGitFetchTitle string
|
||||||
@ -429,6 +430,7 @@ type TranslationSet struct {
|
|||||||
SubmodulesTitle string
|
SubmodulesTitle string
|
||||||
NavigationTitle string
|
NavigationTitle string
|
||||||
PushingTagStatus string
|
PushingTagStatus string
|
||||||
|
PullRequestURLCopiedToClipboard string
|
||||||
}
|
}
|
||||||
|
|
||||||
const englishReleaseNotes = `## lazygit 0.23.2 Release Notes
|
const englishReleaseNotes = `## lazygit 0.23.2 Release Notes
|
||||||
@ -664,6 +666,7 @@ func englishTranslationSet() TranslationSet {
|
|||||||
SwitchRepo: `switch to a recent repo`,
|
SwitchRepo: `switch to a recent repo`,
|
||||||
UnsupportedGitService: `Unsupported git service`,
|
UnsupportedGitService: `Unsupported git service`,
|
||||||
LcCreatePullRequest: `create pull request`,
|
LcCreatePullRequest: `create pull request`,
|
||||||
|
LcCopyPullRequestURL: `copy pull request URL to clipboard`,
|
||||||
NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`,
|
NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`,
|
||||||
LcFetch: `fetch`,
|
LcFetch: `fetch`,
|
||||||
NoAutomaticGitFetchTitle: `No automatic git fetch`,
|
NoAutomaticGitFetchTitle: `No automatic git fetch`,
|
||||||
@ -928,5 +931,6 @@ func englishTranslationSet() TranslationSet {
|
|||||||
SubmodulesTitle: "Submodules",
|
SubmodulesTitle: "Submodules",
|
||||||
NavigationTitle: "List Panel Navigation",
|
NavigationTitle: "List Panel Navigation",
|
||||||
PushingTagStatus: "pushing tag",
|
PushingTagStatus: "pushing tag",
|
||||||
|
PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ func polishTranslationSet() TranslationSet {
|
|||||||
ConfirmQuit: `Na pewno chcesz wyjść z programu?`,
|
ConfirmQuit: `Na pewno chcesz wyjść z programu?`,
|
||||||
UnsupportedGitService: `Nieobsługiwana usługa git`,
|
UnsupportedGitService: `Nieobsługiwana usługa git`,
|
||||||
LcCreatePullRequest: `utwórz żądanie wyciągnięcia`,
|
LcCreatePullRequest: `utwórz żądanie wyciągnięcia`,
|
||||||
|
LcCopyPullRequestURL: `skopiuj adres URL żądania ściągnięcia do schowka`,
|
||||||
NoBranchOnRemote: `Ta gałąź nie istnieje na zdalnym. Najpierw musisz go odepchnąć na odległość.`,
|
NoBranchOnRemote: `Ta gałąź nie istnieje na zdalnym. Najpierw musisz go odepchnąć na odległość.`,
|
||||||
LcFetch: `fetch`,
|
LcFetch: `fetch`,
|
||||||
NoAutomaticGitFetchTitle: `No automatic git fetch`,
|
NoAutomaticGitFetchTitle: `No automatic git fetch`,
|
||||||
@ -250,5 +251,6 @@ func polishTranslationSet() TranslationSet {
|
|||||||
NoFilesStagedPrompt: "You have not staged any files. Commit all files?",
|
NoFilesStagedPrompt: "You have not staged any files. Commit all files?",
|
||||||
BranchNotFoundTitle: "Branch not found",
|
BranchNotFoundTitle: "Branch not found",
|
||||||
BranchNotFoundPrompt: "Branch not found. Create a new branch named",
|
BranchNotFoundPrompt: "Branch not found. Create a new branch named",
|
||||||
|
PullRequestURLCopiedToClipboard: "URL żądania ściągnięcia skopiowany do schowka",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user