mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Gerrit extracted to new config format
This commit is contained in:
parent
12a895b9df
commit
fcbfd8e9a7
3
main.go
3
main.go
@ -211,7 +211,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
cfg := gcal.NewSettingsFromYAML(wtf.Config)
|
||||
widget = gcal.NewWidget(app, cfg)
|
||||
case "gerrit":
|
||||
widget = gerrit.NewWidget(app, pages)
|
||||
cfg := gerrit.NewSettingsFromYAML(wtf.Config)
|
||||
widget = gerrit.NewWidget(app, pages, cfg)
|
||||
case "git":
|
||||
widget = git.NewWidget(app, pages)
|
||||
case "github":
|
||||
|
@ -21,10 +21,10 @@ func (widget *Widget) display() {
|
||||
str = str + widget.displayStats(project)
|
||||
str = str + "\n"
|
||||
str = str + " [red]Open Incoming Reviews[white]\n"
|
||||
str = str + widget.displayMyIncomingReviews(project, wtf.Config.UString("wtf.mods.gerrit.username"))
|
||||
str = str + widget.displayMyIncomingReviews(project, widget.settings.username)
|
||||
str = str + "\n"
|
||||
str = str + " [red]My Outgoing Reviews[white]\n"
|
||||
str = str + widget.displayMyOutgoingReviews(project, wtf.Config.UString("wtf.mods.gerrit.username"))
|
||||
str = str + widget.displayMyOutgoingReviews(project, widget.settings.username)
|
||||
|
||||
widget.View.SetText(str)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package gerrit
|
||||
|
||||
import (
|
||||
glb "github.com/andygrunwald/go-gerrit"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
type GerritProject struct {
|
||||
@ -25,8 +24,7 @@ func NewGerritProject(path string, gerrit *glb.Client) *GerritProject {
|
||||
}
|
||||
|
||||
// Refresh reloads the gerrit data via the Gerrit API
|
||||
func (project *GerritProject) Refresh() {
|
||||
username := wtf.Config.UString("wtf.mods.gerrit.username")
|
||||
func (project *GerritProject) Refresh(username string) {
|
||||
project.Changes, _ = project.loadChanges()
|
||||
|
||||
project.ReviewCount = project.countReviews(project.Changes)
|
||||
|
45
modules/gerrit/settings.go
Normal file
45
modules/gerrit/settings.go
Normal file
@ -0,0 +1,45 @@
|
||||
package gerrit
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
rows struct {
|
||||
even string
|
||||
odd string
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
|
||||
domain string
|
||||
password string
|
||||
projects []interface{}
|
||||
username string
|
||||
verifyServerCertificate bool
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.gerrit")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
domain: localConfig.UString("domain", ""),
|
||||
password: localConfig.UString("password", os.Getenv("WTF_GERRIT_PASSWORD")),
|
||||
projects: localConfig.UList("projects"),
|
||||
username: localConfig.UString("username", ""),
|
||||
verifyServerCertificate: localConfig.UBool("verifyServerCertificate", true),
|
||||
}
|
||||
|
||||
settings.colors.rows.even = localConfig.UString("colors.rows.even", "white")
|
||||
settings.colors.rows.odd = localConfig.UString("colors.rows.odd", "blue")
|
||||
|
||||
return &settings
|
||||
}
|
@ -4,7 +4,7 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
// "os"
|
||||
"regexp"
|
||||
|
||||
glb "github.com/andygrunwald/go-gerrit"
|
||||
@ -40,18 +40,20 @@ type Widget struct {
|
||||
GerritProjects []*GerritProject
|
||||
Idx int
|
||||
selected int
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
var (
|
||||
GerritURLPattern = regexp.MustCompile(`^(http|https)://(.*)$`)
|
||||
)
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, "Gerrit", "gerrit", true),
|
||||
|
||||
Idx: 0,
|
||||
Idx: 0,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
@ -65,31 +67,27 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
baseURL := wtf.Config.UString("wtf.mods.gerrit.domain")
|
||||
username := wtf.Config.UString("wtf.mods.gerrit.username")
|
||||
|
||||
password := wtf.Config.UString(
|
||||
"wtf.mods.gerrit.password",
|
||||
os.Getenv("WTF_GERRIT_PASSWORD"),
|
||||
)
|
||||
|
||||
verifyServerCertificate := wtf.Config.UBool("wtf.mods.gerrit.verifyServerCertificate", true)
|
||||
|
||||
httpClient := &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: !verifyServerCertificate,
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
|
||||
},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
}
|
||||
|
||||
gerritUrl := baseURL
|
||||
submatches := GerritURLPattern.FindAllStringSubmatch(baseURL, -1)
|
||||
gerritUrl := widget.settings.domain
|
||||
submatches := GerritURLPattern.FindAllStringSubmatch(widget.settings.domain, -1)
|
||||
|
||||
if len(submatches) > 0 && len(submatches[0]) > 2 {
|
||||
submatch := submatches[0]
|
||||
gerritUrl = fmt.Sprintf(
|
||||
"%s://%s:%s@%s", submatch[1], username, password, submatch[2])
|
||||
"%s://%s:%s@%s",
|
||||
submatch[1],
|
||||
widget.settings.username,
|
||||
widget.settings.password,
|
||||
submatch[2],
|
||||
)
|
||||
}
|
||||
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||
if err != nil {
|
||||
@ -99,10 +97,10 @@ func (widget *Widget) Refresh() {
|
||||
return
|
||||
}
|
||||
widget.gerrit = gerrit
|
||||
widget.GerritProjects = widget.buildProjectCollection(wtf.Config.UList("wtf.mods.gerrit.projects"))
|
||||
widget.GerritProjects = widget.buildProjectCollection(widget.settings.projects)
|
||||
|
||||
for _, project := range widget.GerritProjects {
|
||||
project.Refresh()
|
||||
project.Refresh(widget.settings.username)
|
||||
}
|
||||
|
||||
widget.display()
|
||||
@ -159,7 +157,7 @@ func (widget *Widget) openReview() {
|
||||
} else {
|
||||
change = project.OutgoingReviews[sel-len(project.IncomingReviews)]
|
||||
}
|
||||
wtf.OpenFile(fmt.Sprintf("%s/%s/%d", wtf.Config.UString("wtf.mods.gerrit.domain"), "#/c", change.Number))
|
||||
wtf.OpenFile(fmt.Sprintf("%s/%s/%d", widget.settings.domain, "#/c", change.Number))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user