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)
|
cfg := gcal.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = gcal.NewWidget(app, cfg)
|
widget = gcal.NewWidget(app, cfg)
|
||||||
case "gerrit":
|
case "gerrit":
|
||||||
widget = gerrit.NewWidget(app, pages)
|
cfg := gerrit.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = gerrit.NewWidget(app, pages, cfg)
|
||||||
case "git":
|
case "git":
|
||||||
widget = git.NewWidget(app, pages)
|
widget = git.NewWidget(app, pages)
|
||||||
case "github":
|
case "github":
|
||||||
|
@ -21,10 +21,10 @@ func (widget *Widget) display() {
|
|||||||
str = str + widget.displayStats(project)
|
str = str + widget.displayStats(project)
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
str = str + " [red]Open Incoming Reviews[white]\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 + "\n"
|
||||||
str = str + " [red]My Outgoing Reviews[white]\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)
|
widget.View.SetText(str)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package gerrit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
glb "github.com/andygrunwald/go-gerrit"
|
glb "github.com/andygrunwald/go-gerrit"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GerritProject struct {
|
type GerritProject struct {
|
||||||
@ -25,8 +24,7 @@ func NewGerritProject(path string, gerrit *glb.Client) *GerritProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refresh reloads the gerrit data via the Gerrit API
|
// Refresh reloads the gerrit data via the Gerrit API
|
||||||
func (project *GerritProject) Refresh() {
|
func (project *GerritProject) Refresh(username string) {
|
||||||
username := wtf.Config.UString("wtf.mods.gerrit.username")
|
|
||||||
project.Changes, _ = project.loadChanges()
|
project.Changes, _ = project.loadChanges()
|
||||||
|
|
||||||
project.ReviewCount = project.countReviews(project.Changes)
|
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"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
// "os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
glb "github.com/andygrunwald/go-gerrit"
|
glb "github.com/andygrunwald/go-gerrit"
|
||||||
@ -40,18 +40,20 @@ type Widget struct {
|
|||||||
GerritProjects []*GerritProject
|
GerritProjects []*GerritProject
|
||||||
Idx int
|
Idx int
|
||||||
selected int
|
selected int
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GerritURLPattern = regexp.MustCompile(`^(http|https)://(.*)$`)
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Gerrit", "gerrit", true),
|
TextWidget: wtf.NewTextWidget(app, "Gerrit", "gerrit", true),
|
||||||
|
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
@ -65,31 +67,27 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
baseURL := wtf.Config.UString("wtf.mods.gerrit.domain")
|
httpClient := &http.Client{
|
||||||
username := wtf.Config.UString("wtf.mods.gerrit.username")
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
password := wtf.Config.UString(
|
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
|
||||||
"wtf.mods.gerrit.password",
|
},
|
||||||
os.Getenv("WTF_GERRIT_PASSWORD"),
|
Proxy: http.ProxyFromEnvironment,
|
||||||
)
|
|
||||||
|
|
||||||
verifyServerCertificate := wtf.Config.UBool("wtf.mods.gerrit.verifyServerCertificate", true)
|
|
||||||
|
|
||||||
httpClient := &http.Client{Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
InsecureSkipVerify: !verifyServerCertificate,
|
|
||||||
},
|
},
|
||||||
Proxy: http.ProxyFromEnvironment,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gerritUrl := baseURL
|
gerritUrl := widget.settings.domain
|
||||||
submatches := GerritURLPattern.FindAllStringSubmatch(baseURL, -1)
|
submatches := GerritURLPattern.FindAllStringSubmatch(widget.settings.domain, -1)
|
||||||
|
|
||||||
if len(submatches) > 0 && len(submatches[0]) > 2 {
|
if len(submatches) > 0 && len(submatches[0]) > 2 {
|
||||||
submatch := submatches[0]
|
submatch := submatches[0]
|
||||||
gerritUrl = fmt.Sprintf(
|
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)
|
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -99,10 +97,10 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
widget.gerrit = gerrit
|
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 {
|
for _, project := range widget.GerritProjects {
|
||||||
project.Refresh()
|
project.Refresh(widget.settings.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.display()
|
widget.display()
|
||||||
@ -159,7 +157,7 @@ func (widget *Widget) openReview() {
|
|||||||
} else {
|
} else {
|
||||||
change = project.OutgoingReviews[sel-len(project.IncomingReviews)]
|
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