Skip to content

Commit

Permalink
feat/add-short-flag (#4)
Browse files Browse the repository at this point in the history
* add short flag for displaying only first line of commit

* update README

* update short flag comment

* add comment for Cut usage on commit messages
  • Loading branch information
jdockerty authored Jul 10, 2022
1 parent 5e3fb7e commit 6365b0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ This leverages your `git log`, so works best when paired with clear and concise
The easiest way to install is through the `go` command.

```bash
go install github.com/jdockerty/[email protected].0
go install github.com/jdockerty/today@latest # or tag, e.g. @v0.1.1
```

Or by downloading a pre-compiled binary on the [releases](https://github.com/jdockerty/today/releases) page.

## Usage

Simply pass a local directory that you wish to view the work for, this also works over multiple directories, as work is not always confined to a single project.
Simply pass a local directory that you wish to view the work for. This also supports multiple directories, as work is not always confined to a single project.

```bash
today work/very-important-business-app

today work/api work/frontend work/new-important-serivce # You've been very busy

today --since 48h work/api # You missed standup yesterday

today --short work/fun-poc # Only display first line of the commit message
```

Modifying the time range is done using the `--since` flag, valid time units for this conform to [`time.ParseDuration`](https://pkg.go.dev/time#ParseDuration). The main use case for this is to extend or reduce the number of hours you wish to search across, but you may get incredibly precise if you so desire.

Using the `--short` flag is useful when commit messages are incredibly descriptive, spanning below the fold to explain the intention of a change.
15 changes: 14 additions & 1 deletion today.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"strings"
"time"

"github.com/go-git/go-git/v5"
Expand All @@ -14,6 +15,10 @@ import (
// The provided time units must be parseable via time.ParseDuration and it defaults to 12 hours.
var since time.Duration

// Short is a flag for condensing larger messages, this will only display the first line of a commit message.
// This is ideal for repositories where commits may contain longer explanations or reasoning behind the change, but you are familiar with it already and only need a high-level overview.
var short bool

// validatePaths is used to ensure that only directories that are tracked by git are passed into the application,
// as these directories are used to track the work which was been done, via commit messages.
func validatePaths(paths []string) error {
Expand Down Expand Up @@ -98,7 +103,14 @@ func getCommitMessages(dirToRepo map[string]*git.Repository, since time.Duration

// If time of commit is 12 hours (or given value) after current time, add it to the map.
if commitTime.After(timeSince) {
msgs[dir] = append(msgs[dir], c.Message)
if short {
// Multi-line commit messages span over newlines, taking the text before this is the main message and the rest can be discarded.
firstLine, _, _ := strings.Cut(c.Message, "\n")
msgs[dir] = append(msgs[dir], firstLine)
} else {
msgs[dir] = append(msgs[dir], c.Message)
}

return nil
}

Expand All @@ -115,6 +127,7 @@ func getCommitMessages(dirToRepo map[string]*git.Repository, since time.Duration

func main() {

flag.BoolVar(&short, "short", false, "display the first line of commit messages only")
flag.DurationVar(&since, "since", 12*time.Hour, "how far back to check for commits from now")
flag.Parse()

Expand Down

0 comments on commit 6365b0f

Please sign in to comment.