Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions api/queries_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
27 changes: 21 additions & 6 deletions api/queries_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import (
)

type PullRequestsPayload struct {
ViewerCreated []PullRequest
ReviewRequested []PullRequest
ViewerCreated PullRequestAndTotalCount
ReviewRequested PullRequestAndTotalCount
CurrentPR *PullRequest
}

type PullRequestAndTotalCount struct {
TotalCount int
PullRequests []PullRequest
}

type PullRequest struct {
Number int
Title string
Expand Down Expand Up @@ -123,7 +128,8 @@ type Repo interface {

func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) {
type edges struct {
Edges []struct {
TotalCount int
Edges []struct {
Node PullRequest
}
}
Expand Down Expand Up @@ -177,6 +183,7 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
repository(owner: $owner, name: $repo) {
pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) {
totalCount
edges {
node {
...prWithReviews
Expand All @@ -198,13 +205,15 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea

query := fragments + queryPrefix + `
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
totalCount: issueCount
edges {
node {
...prWithReviews
}
}
}
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
totalCount: issueCount
edges {
node {
...pr
Expand Down Expand Up @@ -260,9 +269,15 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
}

payload := PullRequestsPayload{
viewerCreated,
reviewRequested,
currentPR,
ViewerCreated: PullRequestAndTotalCount{
PullRequests: viewerCreated,
TotalCount: resp.ViewerCreated.TotalCount,
},
ReviewRequested: PullRequestAndTotalCount{
PullRequests: reviewRequested,
TotalCount: resp.ReviewRequested.TotalCount,
},
CurrentPR: currentPR,
}

return &payload, nil
Expand Down
18 changes: 11 additions & 7 deletions command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,25 @@ 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)
}
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")
}
Expand Down Expand Up @@ -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)
Expand All @@ -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\n"), prefix, remaining)
}
}

func labelList(issue api.Issue) string {
Expand Down
16 changes: 10 additions & 6 deletions command/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,24 @@ func prStatus(cmd *cobra.Command, args []string) error {

printHeader(out, "Current branch")
if prPayload.CurrentPR != nil {
printPrs(out, *prPayload.CurrentPR)
printPrs(out, 0, *prPayload.CurrentPR)
} else {
message := fmt.Sprintf(" There is no pull request associated with %s", utils.Cyan("["+currentPRHeadRef+"]"))
printMessage(out, message)
}
fmt.Fprintln(out)

printHeader(out, "Created by you")
if len(prPayload.ViewerCreated) > 0 {
printPrs(out, prPayload.ViewerCreated...)
if prPayload.ViewerCreated.TotalCount > 0 {
printPrs(out, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
} else {
printMessage(out, " You have no open pull requests")
}
fmt.Fprintln(out)

printHeader(out, "Requesting a code review from you")
if len(prPayload.ReviewRequested) > 0 {
printPrs(out, prPayload.ReviewRequested...)
if prPayload.ReviewRequested.TotalCount > 0 {
printPrs(out, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
} else {
printMessage(out, " You have no pull requests to review")
}
Expand Down Expand Up @@ -435,7 +435,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
return nil
}

func printPrs(w io.Writer, prs ...api.PullRequest) {
func printPrs(w io.Writer, totalCount int, prs ...api.PullRequest) {
for _, pr := range prs {
prNumber := fmt.Sprintf("#%d", pr.Number)
fmt.Fprintf(w, " %s %s %s", utils.Green(prNumber), truncate(50, replaceExcessiveWhitespace(pr.Title)), utils.Cyan("["+pr.HeadLabel()+"]"))
Expand Down Expand Up @@ -472,6 +472,10 @@ func printPrs(w io.Writer, prs ...api.PullRequest) {

fmt.Fprint(w, "\n")
}
remaining := totalCount - len(prs)
if remaining > 0 {
fmt.Fprintf(w, utils.Gray(" And %d more\n"), remaining)
}
}

func printHeader(w io.Writer, s string) {
Expand Down
19 changes: 11 additions & 8 deletions test/fixtures/issueStatus.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
"repository": {
"hasIssuesEnabled": true,
"assigned": {
"totalCount": 2,
"nodes": [
{
"number": 9,
"title": "corey thinks squash tastes bad"
"number": 9,
"title": "corey thinks squash tastes bad"
},
{
"number": 10,
"title": "broccoli is a superfood"
"number": 10,
"title": "broccoli is a superfood"
}
]
},
"mentioned": {
"totalCount": 2,
"nodes": [
{
"number": 8,
"title": "rabbits eat carrots"
"number": 8,
"title": "rabbits eat carrots"
},
{
"number": 11,
"title": "swiss chard is neutral"
"number": 11,
"title": "swiss chard is neutral"
}
]
},
"authored": {
"totalCount": 0,
"nodes": []
}
}
Expand Down
93 changes: 49 additions & 44 deletions test/fixtures/prStatus.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,57 @@
{"data":{
"repository": {
"pullRequests": {
{
"data": {
"repository": {
"pullRequests": {
"totalCount": 1,
"edges": [
{
"node": {
"number": 10,
"title": "Blueberries are a good fruit",
"url": "https://github.com/github/gh-cli/pull/10",
"headRefName": "blueberries",
"headRepositoryOwner": {
"login": "OWNER"
},
"isCrossRepository": false
}
}
]
}
},
"viewerCreated": {
"totalCount": 1,
"edges": [
{
"node": {
"number": 10,
"title": "Blueberries are a good fruit",
"url": "https://github.com/github/gh-cli/pull/10",
"headRefName": "blueberries",
"headRepositoryOwner": {
"login": "OWNER"
},
"isCrossRepository": false
"number": 8,
"title": "Strawberries are not actually berries",
"url": "https://github.com/github/gh-cli/pull/8",
"headRefName": "strawberries"
}
}
]
}
},
"viewerCreated": {
"edges": [
{
"node": {
"number": 8,
"title": "Strawberries are not actually berries",
"url": "https://github.com/github/gh-cli/pull/8",
"headRefName": "strawberries"
}
}
]
},
"reviewRequested": {
"edges": [
{
"node": {
"number": 9,
"title": "Apples are tasty",
"url": "https://github.com/github/gh-cli/pull/9",
"headRefName": "apples"
}
},
{
"node": {
"number": 11,
"title": "Figs are my favorite",
"url": "https://github.com/github/gh-cli/pull/1",
"headRefName": "figs"
},
"reviewRequested": {
"totalCount": 2,
"edges": [
{
"node": {
"number": 9,
"title": "Apples are tasty",
"url": "https://github.com/github/gh-cli/pull/9",
"headRefName": "apples"
}
},
{
"node": {
"number": 11,
"title": "Figs are my favorite",
"url": "https://github.com/github/gh-cli/pull/1",
"headRefName": "figs"
}
}
}
]
]
}
}
}}
}
Loading