Skip to content

Commit

Permalink
feat: read .gh-dash.yml file in repo root if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Jan 4, 2025
1 parent f3d3dbf commit f169ff1
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
82 changes: 82 additions & 0 deletions .gh-dash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# yaml-language-server: $schema=https://dlvhdr.github.io/gh-dash/configuration/gh-dash/schema.json
prSections:
- title: Mine
filters: is:open author:@me repo:dlvhdr/gh-dash
layout:
author:
hidden: true
- title: Review
filters: repo:dlvhdr/gh-dash -author:@me is:open
- title: All
filters: repo:dlvhdr/gh-dash
issuesSections:
- title: Open
filters: author:@me repo:dlvhdr/gh-dash is:open -author:@me sort:reactions
- title: Creator
filters: author:@me repo:dlvhdr/gh-dash is:open
- title: All
filters: repo:dlvhdr/gh-dash sort:reactions

pager:
diff: diffnav
defaults:
view: prs
refetchIntervalMinutes: 5
layout:
prs:
repoName:
grow: true,
width: 10
hidden: false
base:
hidden: true

preview:
open: true
width: 70
prsLimit: 20
issuesLimit: 20
repoPaths:
dlvhdr/*: ~/code/personal/*

keybindings:
universal:
- key: g
command: >
cd {{.RepoPath}} && lazygit
prs:
- key: O
builtin: checkout
- key: C
command: >
tmux new-window -c {{.RepoPath}} '
nvim -c ":silent Octo pr edit {{.PrNumber}}"
'
- key: b
command: cd {{.RepoPath}} && gh pr view {{.PrNumber}} --json statusCheckRollup | command jq -rcj '.statusCheckRollup.[] | select(.context == "buildkite/mono") | .targetUrl' | xargs open
- key: a
command: >
cd {{.RepoPath}} && git add -A && lazygit
- key: v
command: >
gh pr review --repo {{.RepoName}} --approve --body "$(gum input --prompt='Approval Comment: ')" {{.PrNumber}}
theme:
ui:
sectionsShowCount: true
table:
compact: false
colors:
text:
primary: "#E2E1ED"
secondary: "#666CA6"
inverted: "#242347"
faint: "#B0B3BF"
warning: "#E0AF68"
success: "#3DF294"
background:
selected: "#1B1B33"
border:
primary: "#383B5B"
secondary: "#39386B"
faint: "#2B2B40"
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"

"github.com/dlvhdr/gh-dash/v4/config"
"github.com/dlvhdr/gh-dash/v4/git"
"github.com/dlvhdr/gh-dash/v4/ui"
"github.com/dlvhdr/gh-dash/v4/ui/markdown"
)
Expand Down Expand Up @@ -59,6 +60,9 @@ func createModel(repoPath *string, configPath string, debug bool) (ui.Model, *os
log.SetReportCaller(true)
log.SetLevel(log.DebugLevel)
log.Debug("Logging to debug.log")
if repoPath != nil {
log.Debug("Running in repo", "repo", *repoPath)
}
} else {
loggerFile, _ = tea.LogToFile("debug.log", "debug")
slog.Print("Failed setting up logging", fileErr)
Expand Down Expand Up @@ -124,6 +128,14 @@ func init() {
if repos && len(args) > 0 {
repo = &args[0]
}

if repo == nil {
r, err := git.GetRepoInPwd()
if err == nil && r != nil {
p := r.Path()
repo = &p
}
}
debug, err := rootCmd.Flags().GetBool("debug")
if err != nil {
log.Fatal("Cannot parse debug flag", err)
Expand Down
17 changes: 9 additions & 8 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/go-playground/validator/v10"
"gopkg.in/yaml.v2"

"github.com/dlvhdr/gh-dash/v4/git"
"github.com/dlvhdr/gh-dash/v4/utils"
)

Expand Down Expand Up @@ -366,16 +365,16 @@ func (parser ConfigParser) createConfigFileIfMissing(
return nil
}

func (parser ConfigParser) getDefaultConfigFileOrCreateIfMissing() (string, error) {
func (parser ConfigParser) getDefaultConfigFileOrCreateIfMissing(repoPath *string) (string, error) {
var configFilePath string
ghDashConfig := os.Getenv("GH_DASH_CONFIG")

// First try GH_DASH_CONFIG
if ghDashConfig != "" {
configFilePath = ghDashConfig
// Then try to see if we're currently in a git repo
} else if repo, err := git.GetRepoInPwd(); err == nil {
basename := repo.Path() + "/." + DashDir
} else if repoPath != nil {
basename := *repoPath + "/." + DashDir
repoConfigYml := basename + ".yml"
repoConfigYaml := basename + ".yml"
if _, err := os.Stat(repoConfigYml); err == nil {
Expand All @@ -386,8 +385,10 @@ func (parser ConfigParser) getDefaultConfigFileOrCreateIfMissing() (string, erro
if configFilePath != "" {
return configFilePath, nil
}
// Then fallback to global config
} else {
}

// Then fallback to global config
if configFilePath == "" {
configDir := os.Getenv("XDG_CONFIG_HOME")
if configDir == "" {
homeDir, err := os.UserHomeDir()
Expand Down Expand Up @@ -462,15 +463,15 @@ func initParser() ConfigParser {
return ConfigParser{}
}

func ParseConfig(path string) (Config, error) {
func ParseConfig(path string, repoPath *string) (Config, error) {
parser := initParser()

var config Config
var err error
var configFilePath string

if path == "" {
configFilePath, err = parser.getDefaultConfigFileOrCreateIfMissing()
configFilePath, err = parser.getDefaultConfigFileOrCreateIfMissing(repoPath)
if err != nil {
return config, parsingError{err: err}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *Model) initScreen() tea.Msg {
)
}

cfg, err := config.ParseConfig(m.ctx.ConfigPath)
cfg, err := config.ParseConfig(m.ctx.ConfigPath, m.ctx.RepoPath)
if err != nil {
showError(err)
return initMsg{Config: cfg}
Expand Down

0 comments on commit f169ff1

Please sign in to comment.