-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bd69278
Showing
27 changed files
with
2,089 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Go build | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.3' | ||
|
||
- name: Build | ||
run: go build -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.0' | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Install Cosign | ||
uses: sigstore/cosign-installer@v3 | ||
with: | ||
cosign-release: 'v2.2.3' | ||
- name: Store Cosign private key in a file | ||
run: 'echo "$COSIGN_KEY" > cosign.key' | ||
shell: bash | ||
env: | ||
COSIGN_KEY: ${{secrets.COSIGN_KEY}} | ||
- name: Release Binaries | ||
uses: goreleaser/goreleaser-action@v6 | ||
with: | ||
distribution: goreleaser | ||
version: "~> v2" | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{secrets.GH_PAT}} | ||
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dist | ||
cosign.key | ||
cosign.pub | ||
hours | ||
debug.log | ||
.quickrun | ||
justfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
version: 2 | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
- go generate ./... | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
|
||
signs: | ||
- cmd: cosign | ||
stdin: "{{ .Env.COSIGN_PASSWORD }}" | ||
args: | ||
- "sign-blob" | ||
- "--key=cosign.key" | ||
- "--output-signature=${signature}" | ||
- "${artifact}" | ||
- "--yes" # needed on cosign 2.0.0+ | ||
artifacts: all | ||
|
||
|
||
brews: | ||
- name: hours | ||
repository: | ||
owner: dhth | ||
name: homebrew-tap | ||
directory: Formula | ||
license: MIT | ||
homepage: "https://github.com/dhth/hours" | ||
description: "Track time on your tasks" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
- "^ci:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: run-gofmt | ||
name: run-gofmt | ||
entry: gofmt -w . | ||
types: [go] | ||
language: golang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Dhruv Thakur | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# hours | ||
|
||
✨ Overview | ||
--- | ||
|
||
"hours" is a simple CLI app that allows you to track time on tasks you care | ||
about. | ||
|
||
💾 Install | ||
--- | ||
|
||
**go**: | ||
|
||
```sh | ||
go install github.com/dhth/hours@latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmd | ||
|
||
import "database/sql" | ||
|
||
const ( | ||
DB_VERSION = "1" | ||
) | ||
|
||
func setupDB(dbpath string) (*sql.DB, error) { | ||
|
||
db, err := sql.Open("sqlite", dbpath) | ||
db.SetMaxOpenConns(1) | ||
db.SetMaxIdleConns(1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if _, err = db.Exec(` | ||
CREATE TABLE IF NOT EXISTS task ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
summary TEXT NOT NULL, | ||
secsSpent INTEGER NOT NULL DEFAULT 0, | ||
done BOOLEAN NOT NULL, | ||
created_at TIMESTAMP NOT NULL, | ||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
CREATE TABLE IF NOT EXISTS task_log ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
task_id INTEGER, | ||
begin_ts TIMESTAMP NOT NULL, | ||
end_ts TIMESTAMP, | ||
comment VARCHAR(255), | ||
active BOOLEAN NOT NULL, | ||
FOREIGN KEY(task_id) REFERENCES task(id) | ||
); | ||
CREATE TRIGGER IF NOT EXISTS prevent_duplicate_active_insert | ||
BEFORE INSERT ON task_log | ||
BEGIN | ||
SELECT CASE | ||
WHEN EXISTS (SELECT 1 FROM task_log WHERE active = 1) | ||
THEN RAISE(ABORT, 'Only one row with active=1 is allowed') | ||
END; | ||
END; | ||
`); err != nil { | ||
return nil, err | ||
} | ||
|
||
return db, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"os/user" | ||
|
||
"github.com/dhth/hours/internal/ui" | ||
) | ||
|
||
func die(msg string, args ...any) { | ||
fmt.Fprintf(os.Stderr, msg+"\n", args...) | ||
os.Exit(1) | ||
} | ||
|
||
func Execute() { | ||
currentUser, err := user.Current() | ||
|
||
if err != nil { | ||
die("Error getting your home directory, This is a fatal error; let @dhth know about this.\n%s\n", err) | ||
} | ||
|
||
defaultDBPath := fmt.Sprintf("%s/hours.v%s.db", currentUser.HomeDir, DB_VERSION) | ||
dbPath := flag.String("db-path", defaultDBPath, "location where hours should create its DB file") | ||
|
||
flag.Usage = func() { | ||
fmt.Fprintf(os.Stdout, "Track time on your tasks.\n\nFlags:\n") | ||
flag.CommandLine.SetOutput(os.Stdout) | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
|
||
if *dbPath == "" { | ||
die("db-path cannot be empty") | ||
} | ||
|
||
dbPathFull := expandTilde(*dbPath) | ||
|
||
db, err := setupDB(dbPathFull) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Couldn't set up hours' local database. This is a fatal error; let @dhth know about this.\n%s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
ui.RenderUI(db) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/user" | ||
"strings" | ||
) | ||
|
||
func expandTilde(path string) string { | ||
if strings.HasPrefix(path, "~") { | ||
usr, err := user.Current() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
return strings.Replace(path, "~", usr.HomeDir, 1) | ||
} | ||
return path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module github.com/dhth/hours | ||
|
||
go 1.22.4 | ||
|
||
require ( | ||
github.com/charmbracelet/bubbles v0.18.0 | ||
github.com/charmbracelet/bubbletea v0.26.4 | ||
github.com/charmbracelet/lipgloss v0.11.0 | ||
github.com/dustin/go-humanize v1.0.1 | ||
modernc.org/sqlite v1.30.0 | ||
) | ||
|
||
require ( | ||
github.com/atotto/clipboard v0.1.4 // indirect | ||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
github.com/charmbracelet/x/ansi v0.1.2 // indirect | ||
github.com/charmbracelet/x/input v0.1.0 // indirect | ||
github.com/charmbracelet/x/term v0.1.1 // indirect | ||
github.com/charmbracelet/x/windows v0.1.0 // indirect | ||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-localereader v0.0.1 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | ||
github.com/muesli/cancelreader v0.2.2 // indirect | ||
github.com/muesli/reflow v0.3.0 // indirect | ||
github.com/muesli/termenv v0.15.2 // indirect | ||
github.com/ncruces/go-strftime v0.1.9 // indirect | ||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect | ||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.20.0 // indirect | ||
golang.org/x/text v0.3.8 // indirect | ||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect | ||
modernc.org/libc v1.50.9 // indirect | ||
modernc.org/mathutil v1.6.0 // indirect | ||
modernc.org/memory v1.8.0 // indirect | ||
modernc.org/strutil v1.2.0 // indirect | ||
modernc.org/token v1.1.0 // indirect | ||
) |
Oops, something went wrong.