updated based sorting and fuzzy time display on issue status
This commit is contained in:
parent
99c17c3a5f
commit
bfdf89b579
3 changed files with 36 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type IssuesPayload struct {
|
||||
|
|
@ -16,12 +17,13 @@ type IssuesAndTotalCount struct {
|
|||
}
|
||||
|
||||
type Issue struct {
|
||||
Number int
|
||||
Title string
|
||||
URL string
|
||||
State string
|
||||
Body string
|
||||
Comments struct {
|
||||
Number int
|
||||
Title string
|
||||
URL string
|
||||
State string
|
||||
Body string
|
||||
UpdatedAt time.Time
|
||||
Comments struct {
|
||||
TotalCount int
|
||||
}
|
||||
Author struct {
|
||||
|
|
@ -44,6 +46,7 @@ const fragments = `
|
|||
title
|
||||
url
|
||||
state
|
||||
updatedAt
|
||||
labels(first: 3) {
|
||||
nodes {
|
||||
name
|
||||
|
|
@ -111,19 +114,19 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
|
|||
query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
hasIssuesEnabled
|
||||
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
}
|
||||
}
|
||||
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
}
|
||||
}
|
||||
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/github/gh-cli/api"
|
||||
"github.com/github/gh-cli/context"
|
||||
|
|
@ -385,7 +386,14 @@ func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue)
|
|||
if coloredLabels != "" {
|
||||
coloredLabels = utils.Gray(fmt.Sprintf(" (%s)", coloredLabels))
|
||||
}
|
||||
fmt.Fprintf(w, "%s%s %s%s\n", prefix, number, truncate(70, replaceExcessiveWhitespace(issue.Title)), coloredLabels)
|
||||
|
||||
now := time.Now()
|
||||
ago := now.Sub(issue.UpdatedAt)
|
||||
|
||||
fmt.Fprintf(w, "%s%s %s%s %s\n", prefix, number,
|
||||
truncate(70, replaceExcessiveWhitespace(issue.Title)),
|
||||
coloredLabels,
|
||||
utils.Gray(utils.FuzzyAgo(ago)))
|
||||
}
|
||||
remaining := totalCount - len(issues)
|
||||
if remaining > 0 {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/kballard/go-shellquote"
|
||||
md "github.com/vilmibm/go-termd"
|
||||
|
|
@ -90,3 +91,17 @@ func Pluralize(num int, thing string) string {
|
|||
return fmt.Sprintf("%d %ss", num, thing)
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzyAgo(ago time.Duration) string {
|
||||
if ago < time.Minute {
|
||||
return "less than a minute ago"
|
||||
}
|
||||
if ago < time.Hour {
|
||||
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Minutes()), "minute"))
|
||||
}
|
||||
if ago < 24*time.Hour {
|
||||
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Hours()), "hour"))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("about %s ago", Pluralize(int(ago.Hours()/24), "day"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue