mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 GitLab extracted to new config format
This commit is contained in:
parent
6c22ad6d27
commit
50726b4f07
3
main.go
3
main.go
@ -220,7 +220,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := github.NewSettingsFromYAML(wtf.Config)
|
settings := github.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = github.NewWidget(app, pages, settings)
|
widget = github.NewWidget(app, pages, settings)
|
||||||
case "gitlab":
|
case "gitlab":
|
||||||
widget = gitlab.NewWidget(app, pages)
|
settings := gitlab.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = gitlab.NewWidget(app, pages, settings)
|
||||||
case "gitter":
|
case "gitter":
|
||||||
widget = gitter.NewWidget(app, pages)
|
widget = gitter.NewWidget(app, pages)
|
||||||
case "gspreadsheets":
|
case "gspreadsheets":
|
||||||
|
@ -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 Approval Requests[white]\n"
|
str = str + " [red]Open Approval Requests[white]\n"
|
||||||
str = str + widget.displayMyApprovalRequests(project, wtf.Config.UString("wtf.mods.gitlab.username"))
|
str = str + widget.displayMyApprovalRequests(project, widget.settings.username)
|
||||||
str = str + "\n"
|
str = str + "\n"
|
||||||
str = str + " [red]My Merge Requests[white]\n"
|
str = str + " [red]My Merge Requests[white]\n"
|
||||||
str = str + widget.displayMyMergeRequests(project, wtf.Config.UString("wtf.mods.gitlab.username"))
|
str = str + widget.displayMyMergeRequests(project, widget.settings.username)
|
||||||
|
|
||||||
widget.View.SetText(str)
|
widget.View.SetText(str)
|
||||||
}
|
}
|
||||||
|
32
modules/gitlab/settings.go
Normal file
32
modules/gitlab/settings.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
common *cfg.Common
|
||||||
|
|
||||||
|
apiKey string
|
||||||
|
domain string
|
||||||
|
projects map[string]interface{}
|
||||||
|
username string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
|
localConfig, _ := ymlConfig.Get("wtf.mods.gitlab")
|
||||||
|
|
||||||
|
settings := Settings{
|
||||||
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
|
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_GITLAB_TOKEN")),
|
||||||
|
domain: localConfig.UString("domain"),
|
||||||
|
projects: localConfig.UMap("projects"),
|
||||||
|
username: localConfig.UString("username"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &settings
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package gitlab
|
package gitlab
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
@ -25,15 +23,15 @@ type Widget struct {
|
|||||||
wtf.HelpfulWidget
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
gitlab *glb.Client
|
|
||||||
|
|
||||||
GitlabProjects []*GitlabProject
|
GitlabProjects []*GitlabProject
|
||||||
Idx int
|
Idx int
|
||||||
|
gitlab *glb.Client
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
baseURL := wtf.Config.UString("wtf.mods.gitlab.domain")
|
baseURL := settings.domain
|
||||||
gitlab := glb.NewClient(nil, apiKey())
|
gitlab := glb.NewClient(nil, settings.apiKey)
|
||||||
|
|
||||||
if baseURL != "" {
|
if baseURL != "" {
|
||||||
gitlab.SetBaseURL(baseURL)
|
gitlab.SetBaseURL(baseURL)
|
||||||
@ -43,12 +41,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Gitlab", "gitlab", true),
|
TextWidget: wtf.NewTextWidget(app, "Gitlab", "gitlab", true),
|
||||||
|
|
||||||
gitlab: gitlab,
|
Idx: 0,
|
||||||
|
gitlab: gitlab,
|
||||||
Idx: 0,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.GitlabProjects = widget.buildProjectCollection(wtf.Config.UMap("wtf.mods.gitlab.projects"))
|
widget.GitlabProjects = widget.buildProjectCollection(settings.projects)
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
@ -86,13 +84,6 @@ func (widget *Widget) Prev() {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func apiKey() string {
|
|
||||||
return wtf.Config.UString(
|
|
||||||
"wtf.mods.gitlab.apiKey",
|
|
||||||
os.Getenv("WTF_GITLAB_TOKEN"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) buildProjectCollection(projectData map[string]interface{}) []*GitlabProject {
|
func (widget *Widget) buildProjectCollection(projectData map[string]interface{}) []*GitlabProject {
|
||||||
gitlabProjects := []*GitlabProject{}
|
gitlabProjects := []*GitlabProject{}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user