Add "and x more" text"
This commit is contained in:
parent
c6775eae6c
commit
3eb820631d
2 changed files with 40 additions and 16 deletions
|
|
@ -5,9 +5,14 @@ import (
|
|||
)
|
||||
|
||||
type IssuesPayload struct {
|
||||
Assigned []Issue
|
||||
Mentioned []Issue
|
||||
Authored []Issue
|
||||
Assigned IssuesAndTotalCount
|
||||
Mentioned IssuesAndTotalCount
|
||||
Authored IssuesAndTotalCount
|
||||
}
|
||||
|
||||
type IssuesAndTotalCount struct {
|
||||
Issues []Issue
|
||||
TotalCount int
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
|
|
@ -80,13 +85,16 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
|
|||
type response struct {
|
||||
Repository struct {
|
||||
Assigned struct {
|
||||
Nodes []Issue
|
||||
TotalCount int
|
||||
Nodes []Issue
|
||||
}
|
||||
Mentioned struct {
|
||||
Nodes []Issue
|
||||
TotalCount int
|
||||
Nodes []Issue
|
||||
}
|
||||
Authored struct {
|
||||
Nodes []Issue
|
||||
TotalCount int
|
||||
Nodes []Issue
|
||||
}
|
||||
HasIssuesEnabled bool
|
||||
}
|
||||
|
|
@ -97,16 +105,19 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
|
|||
repository(owner: $owner, name: $repo) {
|
||||
hasIssuesEnabled
|
||||
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
}
|
||||
}
|
||||
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
}
|
||||
}
|
||||
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
...issue
|
||||
}
|
||||
|
|
@ -133,9 +144,18 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
|
|||
}
|
||||
|
||||
payload := IssuesPayload{
|
||||
Assigned: resp.Repository.Assigned.Nodes,
|
||||
Mentioned: resp.Repository.Mentioned.Nodes,
|
||||
Authored: resp.Repository.Authored.Nodes,
|
||||
Assigned: IssuesAndTotalCount{
|
||||
Issues: resp.Repository.Assigned.Nodes,
|
||||
TotalCount: resp.Repository.Assigned.TotalCount,
|
||||
},
|
||||
Mentioned: IssuesAndTotalCount{
|
||||
Issues: resp.Repository.Mentioned.Nodes,
|
||||
TotalCount: resp.Repository.Mentioned.TotalCount,
|
||||
},
|
||||
Authored: IssuesAndTotalCount{
|
||||
Issues: resp.Repository.Authored.Nodes,
|
||||
TotalCount: resp.Repository.Authored.TotalCount,
|
||||
},
|
||||
}
|
||||
|
||||
return &payload, nil
|
||||
|
|
|
|||
|
|
@ -172,8 +172,8 @@ func issueStatus(cmd *cobra.Command, args []string) error {
|
|||
out := colorableOut(cmd)
|
||||
|
||||
printHeader(out, "Issues assigned to you")
|
||||
if len(issuePayload.Assigned) > 0 {
|
||||
printIssues(out, " ", issuePayload.Assigned...)
|
||||
if issuePayload.Assigned.TotalCount > 0 {
|
||||
printIssues(out, " ", issuePayload.Assigned.TotalCount, issuePayload.Assigned.Issues)
|
||||
} else {
|
||||
message := fmt.Sprintf(" There are no issues assigned to you")
|
||||
printMessage(out, message)
|
||||
|
|
@ -181,16 +181,16 @@ func issueStatus(cmd *cobra.Command, args []string) error {
|
|||
fmt.Fprintln(out)
|
||||
|
||||
printHeader(out, "Issues mentioning you")
|
||||
if len(issuePayload.Mentioned) > 0 {
|
||||
printIssues(out, " ", issuePayload.Mentioned...)
|
||||
if issuePayload.Mentioned.TotalCount > 0 {
|
||||
printIssues(out, " ", issuePayload.Mentioned.TotalCount, issuePayload.Mentioned.Issues)
|
||||
} else {
|
||||
printMessage(out, " There are no issues mentioning you")
|
||||
}
|
||||
fmt.Fprintln(out)
|
||||
|
||||
printHeader(out, "Issues opened by you")
|
||||
if len(issuePayload.Authored) > 0 {
|
||||
printIssues(out, " ", issuePayload.Authored...)
|
||||
if issuePayload.Authored.TotalCount > 0 {
|
||||
printIssues(out, " ", issuePayload.Authored.TotalCount, issuePayload.Authored.Issues)
|
||||
} else {
|
||||
printMessage(out, " There are no issues opened by you")
|
||||
}
|
||||
|
|
@ -318,7 +318,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func printIssues(w io.Writer, prefix string, issues ...api.Issue) {
|
||||
func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) {
|
||||
for _, issue := range issues {
|
||||
number := utils.Green("#" + strconv.Itoa(issue.Number))
|
||||
coloredLabels := labelList(issue)
|
||||
|
|
@ -327,6 +327,10 @@ func printIssues(w io.Writer, prefix string, issues ...api.Issue) {
|
|||
}
|
||||
fmt.Fprintf(w, "%s%s %s%s\n", prefix, number, truncate(70, replaceExcessiveWhitespace(issue.Title)), coloredLabels)
|
||||
}
|
||||
remaining := totalCount - len(issues)
|
||||
if remaining > 0 {
|
||||
fmt.Fprintf(w, utils.Gray("%sAnd %d more"), prefix, remaining)
|
||||
}
|
||||
}
|
||||
|
||||
func labelList(issue api.Issue) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue