mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Git extracted to new config format
This commit is contained in:
parent
0790493c53
commit
095041be61
3
main.go
3
main.go
@ -214,7 +214,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
cfg := gerrit.NewSettingsFromYAML(wtf.Config)
|
cfg := gerrit.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = gerrit.NewWidget(app, pages, cfg)
|
widget = gerrit.NewWidget(app, pages, cfg)
|
||||||
case "git":
|
case "git":
|
||||||
widget = git.NewWidget(app, pages)
|
cfg := git.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = git.NewWidget(app, pages, cfg)
|
||||||
case "github":
|
case "github":
|
||||||
widget = github.NewWidget(app, pages)
|
widget = github.NewWidget(app, pages)
|
||||||
case "gitlab":
|
case "gitlab":
|
||||||
|
@ -16,12 +16,12 @@ type GitRepo struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitRepo(repoPath string) *GitRepo {
|
func NewGitRepo(repoPath string, commitCount int, commitFormat, dateFormat string) *GitRepo {
|
||||||
repo := GitRepo{Path: repoPath}
|
repo := GitRepo{Path: repoPath}
|
||||||
|
|
||||||
repo.Branch = repo.branch()
|
repo.Branch = repo.branch()
|
||||||
repo.ChangedFiles = repo.changedFiles()
|
repo.ChangedFiles = repo.changedFiles()
|
||||||
repo.Commits = repo.commits()
|
repo.Commits = repo.commits(commitCount, commitFormat, dateFormat)
|
||||||
repo.Repository = strings.TrimSpace(repo.repository())
|
repo.Repository = strings.TrimSpace(repo.repository())
|
||||||
|
|
||||||
return &repo
|
return &repo
|
||||||
@ -49,13 +49,9 @@ func (repo *GitRepo) changedFiles() []string {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *GitRepo) commits() []string {
|
func (repo *GitRepo) commits(commitCount int, commitFormat, dateFormat string) []string {
|
||||||
numStr := fmt.Sprintf("-n %d", wtf.Config.UInt("wtf.mods.git.commitCount", 10))
|
|
||||||
|
|
||||||
dateFormat := wtf.Config.UString("wtf.mods.git.dateFormat", "%b %d, %Y")
|
|
||||||
dateStr := fmt.Sprintf("--date=format:\"%s\"", dateFormat)
|
dateStr := fmt.Sprintf("--date=format:\"%s\"", dateFormat)
|
||||||
|
numStr := fmt.Sprintf("-n %d", commitCount)
|
||||||
commitFormat := wtf.Config.UString("wtf.mods.git.commitFormat", "[forestgreen]%h [white]%s [grey]%an on %cd[white]")
|
|
||||||
commitStr := fmt.Sprintf("--pretty=format:\"%s\"", commitFormat)
|
commitStr := fmt.Sprintf("--pretty=format:\"%s\"", commitFormat)
|
||||||
|
|
||||||
arg := []string{repo.gitDir(), repo.workTree(), "log", dateStr, numStr, commitStr}
|
arg := []string{repo.gitDir(), repo.workTree(), "log", dateStr, numStr, commitStr}
|
||||||
|
30
modules/git/settings.go
Normal file
30
modules/git/settings.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
common *cfg.Common
|
||||||
|
|
||||||
|
commitCount int
|
||||||
|
commitFormat string
|
||||||
|
dateFormat string
|
||||||
|
repositories []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
|
localConfig, _ := ymlConfig.Get("wtf.mods.git")
|
||||||
|
|
||||||
|
settings := Settings{
|
||||||
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
|
commitCount: localConfig.UInt("commitCount", 10),
|
||||||
|
commitFormat: localConfig.UString("commitFormat", "[forestgreen]%h [white]%s [grey]%an on %cd[white]"),
|
||||||
|
dateFormat: localConfig.UString("dateFormat", "%b %d, %Y"),
|
||||||
|
repositories: localConfig.UList("repositories"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &settings
|
||||||
|
}
|
@ -32,19 +32,22 @@ type Widget struct {
|
|||||||
wtf.MultiSourceWidget
|
wtf.MultiSourceWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
app *tview.Application
|
|
||||||
GitRepos []*GitRepo
|
GitRepos []*GitRepo
|
||||||
|
|
||||||
|
app *tview.Application
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget("git", "repository", "repositories"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget("git", "repository", "repositories"),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Git", "git", true),
|
TextWidget: wtf.NewTextWidget(app, "Git", "git", true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
pages: pages,
|
pages: pages,
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.LoadSources()
|
widget.LoadSources()
|
||||||
@ -83,7 +86,7 @@ func (widget *Widget) Pull() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
repoPaths := wtf.ToStrs(wtf.Config.UList("wtf.mods.git.repositories"))
|
repoPaths := wtf.ToStrs(widget.settings.repositories)
|
||||||
|
|
||||||
widget.GitRepos = widget.gitRepos(repoPaths)
|
widget.GitRepos = widget.gitRepos(repoPaths)
|
||||||
sort.Slice(widget.GitRepos, func(i, j int) bool {
|
sort.Slice(widget.GitRepos, func(i, j int) bool {
|
||||||
@ -164,10 +167,16 @@ func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
|
|||||||
|
|
||||||
for _, repoPath := range repoPaths {
|
for _, repoPath := range repoPaths {
|
||||||
if strings.HasSuffix(repoPath, "/") {
|
if strings.HasSuffix(repoPath, "/") {
|
||||||
repos = append(repos, findGitRepositories(make([]*GitRepo, 0), repoPath)...)
|
repos = append(repos, widget.findGitRepositories(make([]*GitRepo, 0), repoPath)...)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
repo := NewGitRepo(repoPath)
|
repo := NewGitRepo(
|
||||||
|
repoPath,
|
||||||
|
widget.settings.commitCount,
|
||||||
|
widget.settings.commitFormat,
|
||||||
|
widget.settings.dateFormat,
|
||||||
|
)
|
||||||
|
|
||||||
repos = append(repos, repo)
|
repos = append(repos, repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,7 +184,7 @@ func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
|
|||||||
return repos
|
return repos
|
||||||
}
|
}
|
||||||
|
|
||||||
func findGitRepositories(repositories []*GitRepo, directory string) []*GitRepo {
|
func (widget *Widget) findGitRepositories(repositories []*GitRepo, directory string) []*GitRepo {
|
||||||
directory = strings.TrimSuffix(directory, "/")
|
directory = strings.TrimSuffix(directory, "/")
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(directory)
|
files, err := ioutil.ReadDir(directory)
|
||||||
@ -188,16 +197,24 @@ func findGitRepositories(repositories []*GitRepo, directory string) []*GitRepo {
|
|||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
path = directory + "/" + file.Name()
|
path = directory + "/" + file.Name()
|
||||||
|
|
||||||
if file.Name() == ".git" {
|
if file.Name() == ".git" {
|
||||||
path = strings.TrimSuffix(path, "/.git")
|
path = strings.TrimSuffix(path, "/.git")
|
||||||
repo := NewGitRepo(path)
|
|
||||||
|
repo := NewGitRepo(
|
||||||
|
path,
|
||||||
|
widget.settings.commitCount,
|
||||||
|
widget.settings.commitFormat,
|
||||||
|
widget.settings.dateFormat,
|
||||||
|
)
|
||||||
|
|
||||||
repositories = append(repositories, repo)
|
repositories = append(repositories, repo)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if file.Name() == "vendor" || file.Name() == "node_modules" {
|
if file.Name() == "vendor" || file.Name() == "node_modules" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
repositories = findGitRepositories(repositories, path)
|
repositories = widget.findGitRepositories(repositories, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user