~emersion/hut-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Switch from timeDelta to humanize.Time

Details
Message ID
<20230314120637.73012-1-admin@xenrox.net>
DKIM signature
pass
Download raw message
Patch: +21 -32
Closes: https://todo.sr.ht/~emersion/hut/31
---
 builds.go |  2 +-
 git.go    |  7 ++++---
 lists.go  |  5 +++--
 main.go   | 16 ----------------
 meta.go   |  3 ++-
 paste.go  |  9 +++++----
 todo.go   | 11 ++++++-----
 7 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/builds.go b/builds.go
index e7812cc..d4bd534 100644
--- a/builds.go
@@ -493,7 +493,7 @@ func newBuildsSecretsCommand() *cobra.Command {
		defer tw.Flush()
		for _, secret := range secrets.Results {
			// TODO: Display secret type (and path, mode for files)
			created := termfmt.Dim.Sprintf("%s ago", timeDelta(secret.Created.Time))
			created := termfmt.Dim.String(humanize.Time(secret.Created.Time))
			s := fmt.Sprintf("%s\t%s\n", termfmt.DarkYellow.Sprint(secret.Uuid), created)
			if secret.Name != nil {
				s += fmt.Sprintf("%s\n", *secret.Name)
diff --git a/git.go b/git.go
index 04e6513..a03cc67 100644
--- a/git.go
+++ b/git.go
@@ -12,6 +12,7 @@ import (
	"strings"

	"git.sr.ht/~emersion/gqlclient"
	"github.com/dustin/go-humanize"
	"github.com/juju/ansiterm/tabwriter"
	"github.com/spf13/cobra"

@@ -388,7 +389,7 @@ func newGitACLListCommand() *cobra.Command {
				mode = string(*acl.Mode)
			}

			created := termfmt.Dim.Sprintf("%s ago", timeDelta(acl.Created.Time))
			created := termfmt.Dim.String(humanize.Time(acl.Created.Time))
			fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", termfmt.DarkYellow.Sprintf("#%d", acl.Id),
				acl.Entity.CanonicalName, mode, created)
		}
@@ -543,11 +544,11 @@ func newGitShowCommand() *cobra.Command {
			fmt.Printf("  Recent log:\n")

			for _, commit := range repo.Log.Results[:3] {
				fmt.Printf("    %s %s <%s> (%s ago)\n",
				fmt.Printf("    %s %s <%s> (%s)\n",
					termfmt.Yellow.Sprintf("%s", commit.ShortId),
					commit.Author.Name,
					commit.Author.Email,
					timeDelta(commit.Author.Time.Time))
					humanize.Time(commit.Author.Time.Time))

				commitLines := strings.Split(commit.Message, "\n")
				fmt.Printf("      %s\n", commitLines[0])
diff --git a/lists.go b/lists.go
index 666d3a8..a719a1f 100644
--- a/lists.go
+++ b/lists.go
@@ -13,6 +13,7 @@ import (
	"os/exec"
	"strings"

	"github.com/dustin/go-humanize"
	"github.com/juju/ansiterm/tabwriter"

	"github.com/spf13/cobra"
@@ -425,7 +426,7 @@ func newListsPatchsetListCommand() *cobra.Command {
				s += fmt.Sprintf(" v%d", patchset.Version)
			}

			created := termfmt.Dim.Sprintf("%s ago", timeDelta(patchset.Created.Time))
			created := termfmt.Dim.String(humanize.Time(patchset.Created.Time))

			if byUser {
				s += fmt.Sprintf("\t%s/%s\t%s", patchset.List.Owner.CanonicalName,
@@ -615,7 +616,7 @@ func newListsACLListCommand() *cobra.Command {
			s := fmt.Sprintf("%s browse  %s reply  %s post  %s moderate",
				listssrht.PermissionIcon(acl.Browse), listssrht.PermissionIcon(acl.Reply),
				listssrht.PermissionIcon(acl.Post), listssrht.PermissionIcon(acl.Moderate))
			created := termfmt.Dim.Sprintf("%s ago", timeDelta(acl.Created.Time))
			created := termfmt.Dim.String(humanize.Time(acl.Created.Time))
			fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", termfmt.DarkYellow.Sprintf("#%d", acl.Id),
				acl.Entity.CanonicalName, s, created)
		}
diff --git a/main.go b/main.go
index 799d9e4..ee98996 100644
--- a/main.go
+++ b/main.go
@@ -81,22 +81,6 @@ func getConfirmation(msg string) bool {
	}
}

func timeDelta(t time.Time) string {
	d := time.Since(t)
	switch {
	case d > time.Hour*24*30:
		return fmt.Sprintf("%.f months", d.Hours()/(24*30))
	case d > time.Hour*24:
		return fmt.Sprintf("%.f days", d.Hours()/24)
	case d > time.Hour:
		return fmt.Sprintf("%.f hours", d.Hours())
	case d > time.Minute:
		return fmt.Sprintf("%.f minutes", d.Minutes())
	}

	return fmt.Sprintf("%.f seconds", d.Seconds())
}

func parseOwnerName(name string) (owner, instance string) {
	name = stripProtocol(name)
	parsed := strings.Split(name, "/")
diff --git a/meta.go b/meta.go
index c3499f4..284bd63 100644
--- a/meta.go
+++ b/meta.go
@@ -10,6 +10,7 @@ import (
	"path/filepath"
	"strings"

	"github.com/dustin/go-humanize"
	"github.com/spf13/cobra"

	"git.sr.ht/~emersion/hut/srht/metasrht"
@@ -91,7 +92,7 @@ func newMetaAuditLogCommand() *cobra.Command {
			} else {
				entry += fmt.Sprintf(" %s ", log.EventType)
			}
			entry += fmt.Sprintf("%s ago", timeDelta(log.Created.Time))
			entry += humanize.Time(log.Created.Time)
			fmt.Println(entry)
		}
	}
diff --git a/paste.go b/paste.go
index 58e9fa4..44202ff 100644
--- a/paste.go
+++ b/paste.go
@@ -12,6 +12,7 @@ import (
	"strings"

	"git.sr.ht/~emersion/gqlclient"
	"github.com/dustin/go-humanize"
	"github.com/spf13/cobra"

	"git.sr.ht/~emersion/hut/srht/pastesrht"
@@ -138,8 +139,8 @@ func newPasteListCommand() *cobra.Command {
		}

		for _, paste := range pastes.Results {
			fmt.Printf("%s %s %s ago\n", termfmt.DarkYellow.Sprint(paste.Id),
				paste.Visibility.TermString(), timeDelta(paste.Created.Time))
			fmt.Printf("%s %s %s\n", termfmt.DarkYellow.Sprint(paste.Id),
				paste.Visibility.TermString(), humanize.Time(paste.Created.Time))
			for _, file := range paste.Files {
				if file.Filename != nil && *file.Filename != "" {
					fmt.Printf("  %s\n", *file.Filename)
@@ -177,8 +178,8 @@ func newPasteShowCommand() *cobra.Command {
			log.Fatalf("Paste %q does not exist", id)
		}

		fmt.Printf("%s %s %s ago\n", termfmt.DarkYellow.Sprint(paste.Id),
			paste.Visibility.TermString(), timeDelta(paste.Created.Time))
		fmt.Printf("%s %s %s\n", termfmt.DarkYellow.Sprint(paste.Id),
			paste.Visibility.TermString(), humanize.Time(paste.Created.Time))

		for _, file := range paste.Files {
			fmt.Print("\n■ ")
diff --git a/todo.go b/todo.go
index 43124dd..8c6b67a 100644
--- a/todo.go
+++ b/todo.go
@@ -13,6 +13,7 @@ import (

	"git.sr.ht/~emersion/hut/srht/todosrht"
	"git.sr.ht/~emersion/hut/termfmt"
	"github.com/dustin/go-humanize"
	"github.com/juju/ansiterm/tabwriter"
	"github.com/spf13/cobra"
)
@@ -323,8 +324,8 @@ func newTodoTicketListCommand() *cobra.Command {
					}
				}
			}
			s += fmt.Sprintf("%s%s (%s %s ago)", ticket.Subject, labels,
				ticket.Submitter.CanonicalName, timeDelta(ticket.Created.Time))
			s += fmt.Sprintf("%s%s (%s %s)", ticket.Subject, labels,
				ticket.Submitter.CanonicalName, humanize.Time(ticket.Created.Time))
			fmt.Println(s)
		}
	}
@@ -730,8 +731,8 @@ func newTodoTicketShowCommand() *cobra.Command {
		}
		fmt.Println(assigned)

		fmt.Printf("Submitted: %s ago\n", timeDelta(ticket.Created.Time))
		fmt.Printf("Updated: %s ago\n", timeDelta(ticket.Updated.Time))
		fmt.Printf("Submitted: %s\n", humanize.Time(ticket.Created.Time))
		fmt.Printf("Updated: %s\n", humanize.Time(ticket.Updated.Time))

		labels := "Labels: "
		if len(ticket.Labels) == 0 {
@@ -1080,7 +1081,7 @@ func newTodoACLListCommand() *cobra.Command {
				todosrht.PermissionIcon(acl.Browse), todosrht.PermissionIcon(acl.Submit),
				todosrht.PermissionIcon(acl.Comment), todosrht.PermissionIcon(acl.Edit),
				todosrht.PermissionIcon(acl.Triage))
			created := termfmt.Dim.Sprintf("%s ago", timeDelta(acl.Created.Time))
			created := termfmt.Dim.String(humanize.Time(acl.Created.Time))
			fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", termfmt.DarkYellow.Sprintf("#%d", acl.Id),
				acl.Entity.CanonicalName, s, created)
		}

base-commit: 5664e7046d81aa30e7d652cad8f30e87528f6cf8
-- 
2.39.2
Details
Message ID
<JfKrJGQcphbVWjb8exl4xuwQgMBNnWQ3t7RqLnWkR7o6fCGvUJqkhAZy2mWhWF9JC6P_vsNCYVThcipnvSsY51phebG7YWhphdHFSzBlbU0=@emersion.fr>
In-Reply-To
<20230314120637.73012-1-admin@xenrox.net> (view parent)
DKIM signature
pass
Download raw message
Pushed, thanks!
Reply to thread Export thread (mbox)