Skip to content

Commit

Permalink
refactor: simplify update file (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth authored Jan 17, 2025
1 parent 043161a commit 2102413
Show file tree
Hide file tree
Showing 12 changed files with 899 additions and 563 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: go build
run: go build -v ./...
- name: go test
run: go test -v ./...
- name: run hours
run: |
go build .
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: test

on:
push:
branches: ["main"]
pull_request:
paths:
- "go.*"
- "**/*.go"
- ".github/workflows/test.yml"

env:
GO_VERSION: '1.23.4'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go test
run: go test -v ./...

live:
needs: [test]
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go install
run: go install .
- name: Run live tests
run: |
cd tests
./test.sh
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.3.0] - Jun 29, 2024

### Added

- Timestamps in the "Task Log Entry" view can be moved forwards/backwards using
j/k/J/K
- The TUI now shows the start time of an active recording
- An active task log recording can now be cancelled (using ctrl+x)

### Changed

- Timestamps in "Task Log" view show up differently based on the end timestamp
- "active" subcommand supports a time placeholder, eg. hours active -t 'working
on {{task}} for {{time}}'

## [v0.2.0] - Jun 21, 2024

### Added

- Adds the ability to view reports/logs/stats interactively (using the
--interactive/-i flag)
- Adds the "gen" subcommand to allow new users of "hours" to generate dummy data

[unreleased]: https://github.com/dhth/hours/compare/v0.3.0...HEAD
[v0.3.0]: https://github.com/dhth/hours/compare/v0.2.0...v0.3.0
[v0.2.0]: https://github.com/dhth/hours/compare/v0.1.0...v0.2.0
4 changes: 2 additions & 2 deletions internal/persistence/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ LIMIT ?;
return tLE, nil
}

func DeleteTaskLogEntry(db *sql.DB, entry *types.TaskLogEntry) error {
func DeleteTL(db *sql.DB, entry *types.TaskLogEntry) error {
return runInTx(db, func(tx *sql.Tx) error {
stmt, err := tx.Prepare(`
DELETE from task_log
Expand Down Expand Up @@ -587,7 +587,7 @@ WHERE id=?;
return task, nil
}

func fetchTaskLogByID(db *sql.DB, id int) (types.TaskLogEntry, error) {
func fetchTLByID(db *sql.DB, id int) (types.TaskLogEntry, error) {
var tl types.TaskLogEntry
row := db.QueryRow(`
SELECT id, task_id, begin_ts, end_ts, secs_spent, comment
Expand Down
8 changes: 4 additions & 4 deletions internal/persistence/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestRepository(t *testing.T) {
// THEN
require.NoError(t, err, "failed to update task log")

taskLog, err := fetchTaskLogByID(testDB, tlID)
taskLog, err := fetchTLByID(testDB, tlID)
require.NoError(t, err, "failed to fetch task log")

taskAfter, err := fetchTaskByID(testDB, taskID)
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestRepository(t *testing.T) {
// THEN
require.NoError(t, err, "failed to insert task log")

taskLog, err := fetchTaskLogByID(testDB, tlID)
taskLog, err := fetchTLByID(testDB, tlID)
require.NoError(t, err, "failed to fetch task log")

taskAfter, err := fetchTaskByID(testDB, taskID)
Expand All @@ -133,11 +133,11 @@ func TestRepository(t *testing.T) {
taskBefore, err := fetchTaskByID(testDB, taskID)
require.NoError(t, err, "failed to fetch task")
numSecondsBefore := taskBefore.SecsSpent
taskLog, err := fetchTaskLogByID(testDB, tlID)
taskLog, err := fetchTLByID(testDB, tlID)
require.NoError(t, err, "failed to fetch task log")

// WHEN
err = DeleteTaskLogEntry(testDB, &taskLog)
err = DeleteTL(testDB, &taskLog)

// THEN
require.NoError(t, err, "failed to insert task log")
Expand Down
22 changes: 11 additions & 11 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func updateTLBeginTS(db *sql.DB, beginTS time.Time) tea.Cmd {
}
}

func insertManualEntry(db *sql.DB, taskID int, beginTS time.Time, endTS time.Time, comment string) tea.Cmd {
func insertManualTL(db *sql.DB, taskID int, beginTS time.Time, endTS time.Time, comment string) tea.Cmd {
return func() tea.Msg {
_, err := pers.InsertManualTL(db, taskID, beginTS, endTS, comment)
return manualTaskLogInserted{taskID, err}
return manualTLInsertedMsg{taskID, err}
}
}

Expand Down Expand Up @@ -101,27 +101,27 @@ func updateTaskRep(db *sql.DB, t *types.Task) tea.Cmd {
}
}

func fetchTaskLogEntries(db *sql.DB) tea.Cmd {
func fetchTLS(db *sql.DB) tea.Cmd {
return func() tea.Msg {
entries, err := pers.FetchTLEntries(db, true, 50)
return taskLogEntriesFetchedMsg{
return tLsFetchedMsg{
entries: entries,
err: err,
}
}
}

func deleteLogEntry(db *sql.DB, entry *types.TaskLogEntry) tea.Cmd {
func deleteTL(db *sql.DB, entry *types.TaskLogEntry) tea.Cmd {
return func() tea.Msg {
err := pers.DeleteTaskLogEntry(db, entry)
return taskLogEntryDeletedMsg{
err := pers.DeleteTL(db, entry)
return tLDeletedMsg{
entry: entry,
err: err,
}
}
}

func deleteActiveTaskLog(db *sql.DB) tea.Cmd {
func deleteActiveTL(db *sql.DB) tea.Cmd {
return func() tea.Msg {
err := pers.DeleteActiveTL(db)
return activeTaskLogDeletedMsg{err}
Expand All @@ -145,20 +145,20 @@ func updateTask(db *sql.DB, task *types.Task, summary string) tea.Cmd {
func updateTaskActiveStatus(db *sql.DB, task *types.Task, active bool) tea.Cmd {
return func() tea.Msg {
err := pers.UpdateTaskActiveStatus(db, task.ID, active)
return taskActiveStatusUpdated{task, active, err}
return taskActiveStatusUpdatedMsg{task, active, err}
}
}

func fetchTasks(db *sql.DB, active bool) tea.Cmd {
return func() tea.Msg {
tasks, err := pers.FetchTasks(db, active, 50)
return tasksFetched{tasks, active, err}
return tasksFetchedMsg{tasks, active, err}
}
}

func hideHelp(interval time.Duration) tea.Cmd {
return tea.Tick(interval, func(time.Time) tea.Msg {
return HideHelpMsg{}
return hideHelpMsg{}
})
}

Expand Down
Loading

0 comments on commit 2102413

Please # to comment.