X Tutup
Skip to content

Commit bfdf89b

Browse files
committed
updated based sorting and fuzzy time display on issue status
1 parent 99c17c3 commit bfdf89b

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

api/queries_issue.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"fmt"
5+
"time"
56
)
67

78
type IssuesPayload struct {
@@ -16,12 +17,13 @@ type IssuesAndTotalCount struct {
1617
}
1718

1819
type Issue struct {
19-
Number int
20-
Title string
21-
URL string
22-
State string
23-
Body string
24-
Comments struct {
20+
Number int
21+
Title string
22+
URL string
23+
State string
24+
Body string
25+
UpdatedAt time.Time
26+
Comments struct {
2527
TotalCount int
2628
}
2729
Author struct {
@@ -44,6 +46,7 @@ const fragments = `
4446
title
4547
url
4648
state
49+
updatedAt
4750
labels(first: 3) {
4851
nodes {
4952
name
@@ -111,19 +114,19 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
111114
query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
112115
repository(owner: $owner, name: $repo) {
113116
hasIssuesEnabled
114-
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
117+
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
115118
totalCount
116119
nodes {
117120
...issue
118121
}
119122
}
120-
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
123+
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
121124
totalCount
122125
nodes {
123126
...issue
124127
}
125128
}
126-
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
129+
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
127130
totalCount
128131
nodes {
129132
...issue

command/issue.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"regexp"
88
"strconv"
99
"strings"
10+
"time"
1011

1112
"github.com/github/gh-cli/api"
1213
"github.com/github/gh-cli/context"
@@ -385,7 +386,14 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue)
385386
if coloredLabels != "" {
386387
coloredLabels = utils.Gray(fmt.Sprintf(" (%s)", coloredLabels))
387388
}
388-
fmt.Fprintf(w, "%s%s %s%s\n", prefix, number, truncate(70, replaceExcessiveWhitespace(issue.Title)), coloredLabels)
389+
390+
now := time.Now()
391+
ago := now.Sub(issue.UpdatedAt)
392+
393+
fmt.Fprintf(w, "%s%s %s%s %s\n", prefix, number,
394+
truncate(70, replaceExcessiveWhitespace(issue.Title)),
395+
coloredLabels,
396+
utils.Gray(utils.FuzzyAgo(ago)))
389397
}
390398
remaining := totalCount - len(issues)
391399
if remaining > 0 {

utils/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"runtime"
10+
"time"
1011

1112
"github.com/kballard/go-shellquote"
1213
md "github.com/vilmibm/go-termd"
@@ -90,3 +91,17 @@ func Pluralize(num int, thing string) string {
9091
return fmt.Sprintf("%d %ss", num, thing)
9192
}
9293
}
94+
95+
func FuzzyAgo(ago time.Duration) string {
96+
if ago < time.Minute {
97+
return "less than a minute ago"
98+
}
99+
if ago < time.Hour {
100+
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Minutes()), "minute"))
101+
}
102+
if ago < 24*time.Hour {
103+
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Hours()), "hour"))
104+
}
105+
106+
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Hours()/24), "day"))
107+
}

0 commit comments

Comments
 (0)
X Tutup