Skip to content

Commit

Permalink
chore: initial cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xederro committed Dec 29, 2024
1 parent b9bbf1b commit e27b642
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ punchout \
jira-url='https://jira.company.com' \
jira-token='XXX' \
jql='assignee = currentUser() AND updatedDate >= -14d ORDER BY updatedDate DESC' \
jira-time-delta-mins='300' \
jira-time-delta-mins='300'
```

Both the config file and the command line flags can be used in conjunction, but
Expand Down Expand Up @@ -114,8 +114,8 @@ General
General List Controls
h/<Up> Move cursor up
k/<Down> Move cursor down
k/<Up> Move cursor up
j/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type JiraConfig struct {
JiraURL *string `toml:"jira_url"`
JiraToken *string `toml:"jira_token"`
Jql *string
JiraTimeDeltaMins *int `toml:"jira_time_delta_mins"`
JiraTimeDeltaMins int `toml:"jira_time_delta_mins"`
}

type POConfig struct {
Expand Down
21 changes: 10 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ func Execute() {
if *jiraTimeDeltaMinsStr != "" {
jiraTimeDeltaMins, err = strconv.Atoi(*jiraTimeDeltaMinsStr)
if err != nil {
die("could't convert jira-time-delta-mins to a number")
die("couldn't convert jira-time-delta-mins to a number")
}
}

poCfg, err := readConfig(*configFilePath)
if err != nil {
die("error reading config at %s: %s", *configFilePath, err.Error())
fmt.Fprintf(os.Stderr, "error reading config at %s: %s.\n"+
"continue with command line args only\n", *configFilePath, err.Error())
}

if *jiraURL != "" {
Expand All @@ -79,7 +80,7 @@ func Execute() {
poCfg.Jira.Jql = jql
}
if *jiraTimeDeltaMinsStr != "" {
poCfg.Jira.JiraTimeDeltaMins = &jiraTimeDeltaMins
poCfg.Jira.JiraTimeDeltaMins = jiraTimeDeltaMins
}

configKeyMaxLen := 40
Expand All @@ -90,28 +91,26 @@ func Execute() {
fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JIRA URL", configKeyMaxLen), *poCfg.Jira.JiraURL)
fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JIRA Token", configKeyMaxLen), *poCfg.Jira.JiraToken)
fmt.Fprintf(os.Stdout, "%s%s\n", ui.RightPadTrim("JQL", configKeyMaxLen), *poCfg.Jira.Jql)
fmt.Fprintf(os.Stdout, "%s%d\n", ui.RightPadTrim("JIRA Time Delta Mins", configKeyMaxLen), *poCfg.Jira.JiraTimeDeltaMins)
fmt.Fprintf(os.Stdout, "%s%d\n", ui.RightPadTrim("JIRA Time Delta Mins", configKeyMaxLen), poCfg.Jira.JiraTimeDeltaMins)
os.Exit(0)
}

// validations

if *poCfg.Jira.JiraURL == "" {
if poCfg.Jira.JiraURL == nil || *poCfg.Jira.JiraURL == "" {
die("jira-url cannot be empty")
}

if *poCfg.Jira.JiraToken == "" {
if poCfg.Jira.JiraToken == nil || *poCfg.Jira.JiraToken == "" {
die("jira-token cannot be empty")
}

if *poCfg.Jira.Jql == "" {
if poCfg.Jira.Jql == nil || *poCfg.Jira.Jql == "" {
die("jql cannot be empty")
}

db, err := setupDB(dbPathFull)
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't set up punchout database. This is a fatal error\n")
os.Exit(1)
die("couldn't set up punchout database. This is a fatal error\n")
}

tp := jira.BearerAuthTransport{
Expand All @@ -122,6 +121,6 @@ func Execute() {
panic(err)
}

ui.RenderUI(db, cl, *poCfg.Jira.Jql, *poCfg.Jira.JiraTimeDeltaMins)
ui.RenderUI(db, cl, *poCfg.Jira.Jql, poCfg.Jira.JiraTimeDeltaMins)

}
4 changes: 2 additions & 2 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func insertManualEntry(db *sql.DB, issueKey string, beginTS time.Time, endTS tim
stmt, err := db.Prepare(`
INSERT INTO issue_log (issue_key, begin_ts, end_ts, comment, active, synced)
VALUES (?, ?, ?, ?, ?, ?);
`)
`)
if err != nil {
return manualEntryInserted{issueKey, err}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ SET begin_ts = ?,
end_ts = ?,
comment = ?
WHERE ID = ?;
`)
`)
if err != nil {
return manualEntryUpdated{rowID, issueKey, err}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ var (
`),
helpHeaderStyle.Render("General List Controls"),
helpSectionStyle.Render(`
h/<Up> Move cursor up
k/<Down> Move cursor down
k/<Up> Move cursor up
j/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func insertNewEntry(db *sql.DB, issueKey string, beginTs time.Time) error {
stmt, err := db.Prepare(`
INSERT INTO issue_log (issue_key, begin_ts, active, synced)
VALUES (?, ?, ?, ?);
`)
`)

if err != nil {
return err
Expand Down Expand Up @@ -81,7 +81,7 @@ SELECT ID, issue_key, begin_ts, end_ts, comment, active, synced
FROM issue_log
WHERE active=false AND synced=false
ORDER by end_ts DESC;
`)
`)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -115,7 +115,7 @@ SELECT ID, issue_key, begin_ts, end_ts, comment
FROM issue_log
WHERE active=false AND synced=true
ORDER by end_ts DESC LIMIT 30;
`)
`)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e27b642

Please sign in to comment.