aboutsummaryrefslogtreecommitdiffstats
path: root/termui/bug_table.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-12 21:09:30 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-12 21:09:30 +0200
commite2f4b027c946831c3f4f119d87a80513c7cf8fdc (patch)
treeb2ec57c89c49062ab2e8adeacb2646d2f152db80 /termui/bug_table.go
parent721ed3248e8bf167a89df14d9fc2bf5b0fe45753 (diff)
downloadgit-bug-e2f4b027c946831c3f4f119d87a80513c7cf8fdc.tar.gz
termui: implement push/pull
Diffstat (limited to 'termui/bug_table.go')
-rw-r--r--termui/bug_table.go100
1 files changed, 99 insertions, 1 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 1432d943..cd5ee1f6 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -1,7 +1,9 @@
package termui
import (
+ "bytes"
"fmt"
+
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/util"
@@ -14,6 +16,8 @@ const bugTableHeaderView = "bugTableHeaderView"
const bugTableFooterView = "bugTableFooterView"
const bugTableInstructionView = "bugTableInstructionView"
+const remote = "origin"
+
type bugTable struct {
repo cache.RepoCacher
allIds []string
@@ -105,7 +109,7 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Frame = false
v.BgColor = gocui.ColorBlue
- fmt.Fprintf(v, "[q] Quit [←,h] Previous page [↓,j] Down [↑,k] Up [→,l] Next page [enter] Open bug [n] New bug")
+ fmt.Fprintf(v, "[q] Quit [←↓↑→,hjkl] Navigation [enter] Open bug [n] New bug [i] Pull [o] Push")
}
_, err = g.SetCurrentView(bugTableView)
@@ -176,6 +180,18 @@ func (bt *bugTable) keybindings(g *gocui.Gui) error {
return err
}
+ // Pull
+ if err := g.SetKeybinding(bugTableView, 'i', gocui.ModNone,
+ bt.pull); err != nil {
+ return err
+ }
+
+ // Push
+ if err := g.SetKeybinding(bugTableView, 'o', gocui.ModNone,
+ bt.push); err != nil {
+ return err
+ }
+
return nil
}
@@ -383,3 +399,85 @@ func (bt *bugTable) openBug(g *gocui.Gui, v *gocui.View) error {
ui.showBug.SetBug(bt.bugs[bt.pageCursor+y])
return ui.activateWindow(ui.showBug)
}
+
+func (bt *bugTable) pull(g *gocui.Gui, v *gocui.View) error {
+ // Note: this is very hacky
+
+ ui.msgPopup.Activate("Pull from remote "+remote, "...")
+
+ go func() {
+ stdout, err := bt.repo.Fetch(remote)
+
+ if err != nil {
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
+ return nil
+ })
+ } else {
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.UpdateMessage(stdout)
+ return nil
+ })
+ }
+
+ var buffer bytes.Buffer
+ beginLine := ""
+
+ for merge := range bt.repo.MergeAll(remote) {
+ if merge.Status == bug.MsgMergeNothing {
+ continue
+ }
+
+ if merge.Err != nil {
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
+ return nil
+ })
+ } else {
+ fmt.Fprintf(&buffer, "%s%s: %s",
+ beginLine, util.Cyan(merge.HumanId), merge.Status,
+ )
+
+ beginLine = "\n"
+
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.UpdateMessage(buffer.String())
+ return nil
+ })
+ }
+ }
+
+ fmt.Fprintf(&buffer, "%sdone", beginLine)
+
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.UpdateMessage(buffer.String())
+ return nil
+ })
+
+ }()
+
+ return nil
+}
+
+func (bt *bugTable) push(g *gocui.Gui, v *gocui.View) error {
+ ui.msgPopup.Activate("Push to remote "+remote, "...")
+
+ go func() {
+ // TODO: make the remote configurable
+ stdout, err := bt.repo.Push(remote)
+
+ if err != nil {
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
+ return nil
+ })
+ } else {
+ g.Update(func(gui *gocui.Gui) error {
+ ui.msgPopup.UpdateMessage(stdout)
+ return nil
+ })
+ }
+ }()
+
+ return nil
+}