Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlvhdr/branches-view #416

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/muesli/termenv"
"github.com/spf13/cobra"

"github.com/dlvhdr/gh-dash/v4/config"
"github.com/dlvhdr/gh-dash/v4/ui"
"github.com/dlvhdr/gh-dash/v4/ui/markdown"
)
Expand All @@ -35,6 +36,7 @@ var (
Use: "gh dash",
Short: "A gh extension that shows a configurable dashboard of pull requests and issues.",
Version: "",
Args: cobra.MaximumNArgs(1),
}
)

Expand All @@ -45,7 +47,7 @@ func Execute() {
}
}

func createModel(configPath string, debug bool) (ui.Model, *os.File) {
func createModel(repoPath *string, configPath string, debug bool) (ui.Model, *os.File) {
var loggerFile *os.File

if debug {
Expand All @@ -63,7 +65,7 @@ func createModel(configPath string, debug bool) (ui.Model, *os.File) {
}
}

return ui.NewModel(configPath), loggerFile
return ui.NewModel(repoPath, configPath), loggerFile
}

func buildVersion(version, commit, date, builtBy string) string {
Expand Down Expand Up @@ -113,7 +115,12 @@ func init() {
"help for gh-dash",
)

rootCmd.Run = func(_ *cobra.Command, _ []string) {
rootCmd.Run = func(_ *cobra.Command, args []string) {
var repo *string
repos := config.IsFeatureEnabled(config.FF_REPO_VIEW)
if repos && len(args) > 0 {
repo = &args[0]
}
debug, err := rootCmd.Flags().GetBool("debug")
if err != nil {
log.Fatal("Cannot parse debug flag", err)
Expand All @@ -123,7 +130,7 @@ func init() {
lipgloss.SetHasDarkBackground(termenv.HasDarkBackground())
markdown.InitializeMarkdownStyle(termenv.HasDarkBackground())

model, logger := createModel(cfgFile, debug)
model, logger := createModel(repo, cfgFile, debug)
if logger != nil {
defer logger.Close()
}
Expand Down
10 changes: 10 additions & 0 deletions config/feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

import "os"

const FF_REPO_VIEW = "FF_REPO_VIEW"

func IsFeatureEnabled(name string) bool {
_, ok := os.LookupEnv(name)
return ok
}
9 changes: 8 additions & 1 deletion config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ type ViewType string
const (
PRsView ViewType = "prs"
IssuesView ViewType = "issues"
RepoView ViewType = "repo"
)

type SectionConfig struct {
Title string
Filters string
Limit *int `yaml:"limit,omitempty"`
Type *ViewType
}

type PrsSectionConfig struct {
Title string
Filters string
Limit *int `yaml:"limit,omitempty"`
Layout PrsLayoutConfig `yaml:"layout,omitempty"`
Type *ViewType
}

type IssuesSectionConfig struct {
Expand Down Expand Up @@ -226,7 +229,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
Hidden: utils.BoolPtr(true),
},
Lines: ColumnConfig{
Width: utils.IntPtr(lipgloss.Width("123450 / -123450")),
Width: utils.IntPtr(lipgloss.Width(" +31.4k -31.6k ")),
},
},
Issues: IssuesLayoutConfig{
Expand Down Expand Up @@ -408,6 +411,10 @@ func (parser ConfigParser) readConfigFile(path string) (Config, error) {
if err != nil {
return config, err
}
repoFF := IsFeatureEnabled(FF_REPO_VIEW)
if config.Defaults.View == RepoView && !repoFF {
config.Defaults.View = PRsView
}

err = validate.Struct(config)
return config, err
Expand Down
1 change: 1 addition & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (cfg PrsSectionConfig) ToSectionConfig() SectionConfig {
Title: cfg.Title,
Filters: cfg.Filters,
Limit: cfg.Limit,
Type: cfg.Type,
}
}

Expand Down
60 changes: 60 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package git

import (
"sort"
"time"

gitm "github.com/aymanbagabas/git-module"
)

// Extends git.Repository
type Repo struct {
Origin string
Remotes []string
Branches []Branch
}

type Branch struct {
Name string
LastUpdatedAt *time.Time
}

func GetRepo(dir string) (*Repo, error) {
repo, err := gitm.Open(dir)
if err != nil {
return nil, err
}

bNames, err := repo.Branches()
if err != nil {
return nil, err
}

branches := make([]Branch, len(bNames))
for i, b := range bNames {
var updatedAt *time.Time
commits, err := gitm.Log(dir, b, gitm.LogOptions{MaxCount: 1})
if err == nil && len(commits) > 0 {
updatedAt = &commits[0].Committer.When
}
branches[i] = Branch{Name: b, LastUpdatedAt: updatedAt}
}
sort.Slice(branches, func(i, j int) bool {
if branches[j].LastUpdatedAt == nil || branches[i].LastUpdatedAt == nil {
return false
}
return branches[i].LastUpdatedAt.After(*branches[j].LastUpdatedAt)
})

remotes, err := repo.Remotes()
if err != nil {
return nil, err
}

origin, err := gitm.RemoteGetURL(dir, "origin", gitm.RemoteGetURLOptions{All: true})
if err != nil {
return nil, err
}

return &Repo{Origin: origin[0], Remotes: remotes, Branches: branches}, nil
}
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ require (
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a
github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/kr/text v0.2.0 // indirect
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 // indirect
)

require (
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/aymanbagabas/git-module v1.8.4-0.20231101154130-8d27204ac6d2
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
Expand All @@ -42,7 +48,6 @@ require (
github.com/gorilla/css v1.0.1 // indirect
github.com/henvic/httpretty v0.1.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
15 changes: 14 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/git-module v1.8.4-0.20231101154130-8d27204ac6d2 h1:3w5KT+shE3hzWhORGiu2liVjEoaCEXm9uZP47+Gw4So=
github.com/aymanbagabas/git-module v1.8.4-0.20231101154130-8d27204ac6d2/go.mod h1:d4gQ7/3/S2sPq4NnKdtAgUOVr6XtLpWFtxyVV5/+76U=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
Expand Down Expand Up @@ -38,6 +40,7 @@ github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn
github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
Expand Down Expand Up @@ -89,6 +92,8 @@ github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+Ei
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 h1:Pijfgr7ZuvX7QIQiEwLdRVr3RoMG+i0SbBO1Qu+7yVk=
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
Expand Down Expand Up @@ -116,8 +121,14 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8=
Expand All @@ -135,6 +146,7 @@ golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -159,5 +171,6 @@ gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 3 additions & 1 deletion ui/components/footer/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ func (m *Model) renderViewSwitcher(ctx context.ProgramContext) string {
var view string
if ctx.View == config.PRsView {
view += " PRs"
} else {
} else if ctx.View == config.IssuesView {
view += " Issues"
} else if ctx.View == config.RepoView {
view += " Repo"
}

var user string
Expand Down
2 changes: 1 addition & 1 deletion ui/components/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (issue *Issue) ToTableRow() table.Row {
}

func (issue *Issue) getTextStyle() lipgloss.Style {
return components.GetIssueTextStyle(issue.Ctx, issue.Data.State)
return components.GetIssueTextStyle(issue.Ctx)
}

func (issue *Issue) renderUpdateAt() string {
Expand Down
Loading
Loading