From b0749ca5f777262bd6d58ce881c2c7a45b199f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Zywert?= Date: Tue, 26 Mar 2024 20:44:00 +0100 Subject: [PATCH] More details while batching logs (#6) --- .github/workflows/release.yaml | 4 ++-- CHANGELOG.md | 10 +++++++++- gojira/cli.go | 23 +++++++++-------------- gojira/dayview.go | 14 ++++++++++---- gojira/gojira.go | 2 +- gojira/loaderview.go | 10 ++++++++-- gojira/version.go | 3 +++ 7 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 gojira/version.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a257780..f441922 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,8 +19,8 @@ jobs: - name: Update project version if cmd/version.go exists shell: bash run: | - if [ -f "cmd/version.go" ]; then - printf "package cmd\n\nconst projectVersion = \"$(echo $GITHUB_REF | cut -d / -f 3)\"" > cmd/version.go + if [ -f "gojira/version.go" ]; then + printf "package gojira\n\nconst projectVersion = \"$(echo $GITHUB_REF | cut -d / -f 3)\"" > gojira/version.go fi - name: Build binary (linux/amd64) shell: bash diff --git a/CHANGELOG.md b/CHANGELOG.md index 89934c1..365da84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +## [0.5.2] - 2024-03-26 +### Changed +- More detailed loader while adding worklogs in a batch + +### Fixed +- Version number is now properly synced with the latest release + ## [0.5.1] - 2024-03-25 ### Fixed - Summary not updating with worklog changes @@ -71,7 +78,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added - Initial release of gojira -[Unreleased]: https://github.com/jzyinq/gojira/compare/0.5.1...master +[Unreleased]: https://github.com/jzyinq/gojira/compare/0.5.2...master +[0.5.2]: https://github.com/jzyinq/gojira/compare/0.5.1...0.5.2 [0.5.1]: https://github.com/jzyinq/gojira/compare/0.5.0...0.5.1 [0.5.0]: https://github.com/jzyinq/gojira/compare/0.4.0...0.5.0 [0.4.0]: https://github.com/jzyinq/gojira/compare/0.3.1...0.4.0 diff --git a/gojira/cli.go b/gojira/cli.go index 994ac5d..e4208a5 100644 --- a/gojira/cli.go +++ b/gojira/cli.go @@ -11,15 +11,15 @@ import ( "time" ) -const GojiraAscii = "" + - " _____ _ _ \n" + - " / ____| (_|_) \n" + - " | | __ ___ _ _ _ __ __ _ \n" + - " | | |_ |/ _ \\| | | '__/ _` |\n" + - " | |__| | (_) | | | | | (_| |\n" + - " \\_____|\\___/| |_|_| \\__,_|\n" + - " _/ | v0.4.0 \n" + - " |__/ \n\n" +var AppAsciiArt = fmt.Sprintf(""+ + " _____ _ _ \n"+ + " / ____| (_|_) \n"+ + " | | __ ___ _ _ _ __ __ _ \n"+ + " | | |_ |/ _ \\| | | '__/ _` |\n"+ + " | |__| | (_) | | | | | (_| |\n"+ + " \\_____|\\___/| |_|_| \\__,_|\n"+ + " _/ | v%s \n"+ + " |__/ \n\n", projectVersion) var WorkLogsCommand = &cli.Command{ Name: "worklogs", @@ -264,10 +264,5 @@ func (issue Issue) LogWork(logTime *time.Time, timeSpent string) error { // add this workload to global object app.workLogs.logs = append(app.workLogs.logs, &worklog) app.workLogsIssues.issues = append(app.workLogsIssues.issues, WorkLogIssue{Issue: issue, WorkLog: &worklog}) - _, err = app.workLogs.LogsOnDate(logTime) - if err != nil { - return err - } - //fmt.Printf("Currently logged time: %s\n", FormatTimeSpent(CalculateTimeSpent(todayWorklog))) return nil } diff --git a/gojira/dayview.go b/gojira/dayview.go index 084c094..e1303f4 100644 --- a/gojira/dayview.go +++ b/gojira/dayview.go @@ -176,8 +176,9 @@ func (d *DayView) loadLatest() { // DateRange is a struct for holding the start and end dates type DateRange struct { - StartDate time.Time - EndDate time.Time + StartDate time.Time + EndDate time.Time + NumberOfDays int } func ParseDateRange(dateStr string) (DateRange, error) { @@ -212,9 +213,13 @@ func ParseDateRange(dateStr string) (DateRange, error) { endDate = startDate } + // count number of dayhs between StartDate and EndDate + numberOfDays := int(endDate.Sub(startDate).Hours() / 24) + return DateRange{ - StartDate: startDate, - EndDate: endDate, + StartDate: startDate, + EndDate: endDate, + NumberOfDays: numberOfDays, }, nil } @@ -240,6 +245,7 @@ func NewAddWorklogForm(d *DayView, issues []Issue, row int) *tview.Form { } for day := dateRange.StartDate; day.Before(dateRange.EndDate.AddDate(0, 0, 1)); day = day.AddDate(0, 0, 1) { err := issue.LogWork(&day, timeSpent) + app.ui.loaderView.UpdateText(fmt.Sprintf("Adding worklog for %s ...", day.Format(dateLayout))) if err != nil { app.ui.errorView.ShowError(err.Error()) return diff --git a/gojira/gojira.go b/gojira/gojira.go index 88fa060..30ece7b 100644 --- a/gojira/gojira.go +++ b/gojira/gojira.go @@ -37,7 +37,7 @@ func Run() { Calling without arguments will try to detect issue from git branch, otherwise it will display list of last updated issues you're are assigned to.`, - Version: "0.4.0", + Version: projectVersion, Before: func(context *cli.Context) error { if context.Args().First() != "config" { // dont' check envs on ConfigCommand diff --git a/gojira/loaderview.go b/gojira/loaderview.go index 406d188..21951b3 100644 --- a/gojira/loaderview.go +++ b/gojira/loaderview.go @@ -11,10 +11,11 @@ type LoaderView struct { *LoaderModal ctx context.Context cancel context.CancelFunc + text string } func NewLoaderView() *LoaderView { - loaderView := &LoaderView{NewModal(), nil, nil} + loaderView := &LoaderView{NewModal(), nil, nil, ""} loaderView.SetBorder(false) loaderView.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) app.ui.pages.AddPage("loader", loaderView, true, false) @@ -32,6 +33,7 @@ func (e *LoaderView) Wrap(msg string, callable func()) { func (e *LoaderView) Show(msg string) { e.ctx, e.cancel = context.WithCancel(context.Background()) + e.UpdateText(msg) app.ui.pages.SendToFront("loader") go func() { for { @@ -40,7 +42,7 @@ func (e *LoaderView) Show(msg string) { return default: for _, r := range `-\|/` { - e.SetText(fmt.Sprintf("%s%s\n%s", GojiraAscii, msg, string(r))) + e.SetText(fmt.Sprintf("%s%s\n%s", AppAsciiArt, e.text, string(r))) app.ui.app.Draw() time.Sleep(100 * time.Millisecond) } @@ -51,6 +53,10 @@ func (e *LoaderView) Show(msg string) { app.ui.app.Draw() } +func (e *LoaderView) UpdateText(msg string) { + e.text = msg +} + func (e *LoaderView) Hide() { if e.cancel != nil { e.cancel() diff --git a/gojira/version.go b/gojira/version.go new file mode 100644 index 0000000..86452e5 --- /dev/null +++ b/gojira/version.go @@ -0,0 +1,3 @@ +package gojira + +const projectVersion = "dev"