print repo info for status commands
This commit is contained in:
parent
6a6a6cc60f
commit
d64dcdca95
5 changed files with 71 additions and 4 deletions
|
|
@ -8,9 +8,10 @@ import (
|
|||
)
|
||||
|
||||
type IssuesPayload struct {
|
||||
Assigned IssuesAndTotalCount
|
||||
Mentioned IssuesAndTotalCount
|
||||
Authored IssuesAndTotalCount
|
||||
ParentRepo string
|
||||
Assigned IssuesAndTotalCount
|
||||
Mentioned IssuesAndTotalCount
|
||||
Authored IssuesAndTotalCount
|
||||
}
|
||||
|
||||
type IssuesAndTotalCount struct {
|
||||
|
|
@ -108,6 +109,9 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
|
|||
TotalCount int
|
||||
Nodes []Issue
|
||||
}
|
||||
Parent struct {
|
||||
NameWithOwner string
|
||||
}
|
||||
HasIssuesEnabled bool
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +119,9 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
|
|||
query := fragments + `
|
||||
query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
parent {
|
||||
nameWithOwner
|
||||
}
|
||||
hasIssuesEnabled
|
||||
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
|
|
@ -154,6 +161,7 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
|
|||
}
|
||||
|
||||
payload := IssuesPayload{
|
||||
ParentRepo: resp.Repository.Parent.NameWithOwner,
|
||||
Assigned: IssuesAndTotalCount{
|
||||
Issues: resp.Repository.Assigned.Nodes,
|
||||
TotalCount: resp.Repository.Assigned.TotalCount,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type PullRequestsPayload struct {
|
||||
ParentRepo string
|
||||
ViewerCreated PullRequestAndTotalCount
|
||||
ReviewRequested PullRequestAndTotalCount
|
||||
CurrentPR *PullRequest
|
||||
|
|
@ -139,6 +140,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
|
||||
type response struct {
|
||||
Repository struct {
|
||||
Parent struct {
|
||||
NameWithOwner string
|
||||
}
|
||||
PullRequests edges
|
||||
PullRequest *PullRequest
|
||||
}
|
||||
|
|
@ -185,6 +189,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
queryPrefix := `
|
||||
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
parent {
|
||||
nameWithOwner
|
||||
}
|
||||
pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) {
|
||||
totalCount
|
||||
edges {
|
||||
|
|
@ -199,6 +206,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
queryPrefix = `
|
||||
query($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
parent {
|
||||
nameWithOwner
|
||||
}
|
||||
pullRequest(number: $number) {
|
||||
...prWithReviews
|
||||
}
|
||||
|
|
@ -269,6 +279,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
}
|
||||
|
||||
payload := PullRequestsPayload{
|
||||
ParentRepo: resp.Repository.Parent.NameWithOwner,
|
||||
ViewerCreated: PullRequestAndTotalCount{
|
||||
PullRequests: viewerCreated,
|
||||
TotalCount: resp.ViewerCreated.TotalCount,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cli/cli/api"
|
||||
"github.com/cli/cli/context"
|
||||
"github.com/cli/cli/git"
|
||||
"github.com/cli/cli/internal/ghrepo"
|
||||
"github.com/cli/cli/pkg/githubtemplate"
|
||||
|
|
@ -175,6 +176,13 @@ func issueStatus(cmd *cobra.Command, args []string) error {
|
|||
|
||||
out := colorableOut(cmd)
|
||||
|
||||
repoInfo, err := context.FormattedInfo(ctx, issuePayload.ParentRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(out, repoInfo)
|
||||
|
||||
printHeader(out, "Issues assigned to you")
|
||||
if issuePayload.Assigned.TotalCount > 0 {
|
||||
printIssues(out, " ", issuePayload.Assigned.TotalCount, issuePayload.Assigned.Issues)
|
||||
|
|
|
|||
|
|
@ -97,12 +97,19 @@ func prStatus(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
out := colorableOut(cmd)
|
||||
|
||||
prPayload, err := api.PullRequests(apiClient, baseRepo, currentPRNumber, currentPRHeadRef, currentUser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out := colorableOut(cmd)
|
||||
repoInfo, err := context.FormattedInfo(ctx, prPayload.ParentRepo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(out, repoInfo)
|
||||
|
||||
printHeader(out, "Current branch")
|
||||
if prPayload.CurrentPR != nil {
|
||||
|
|
|
|||
33
context/formatted.go
Normal file
33
context/formatted.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cli/cli/internal/ghrepo"
|
||||
"github.com/cli/cli/utils"
|
||||
)
|
||||
|
||||
func FormattedInfo(c Context, parentRepo string) (string, error) {
|
||||
baseRepo, err := c.BaseRepo()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
authLogin, err := c.AuthLogin()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
forkInfo := ""
|
||||
if parentRepo != "" {
|
||||
forkInfo = fmt.Sprintf("(fork of %s) ", parentRepo)
|
||||
}
|
||||
|
||||
out := fmt.Sprintf("%s%s %s%s%s",
|
||||
utils.Gray("in "),
|
||||
utils.Magenta(ghrepo.FullName(baseRepo)),
|
||||
utils.Yellow(forkInfo),
|
||||
utils.Gray("as "),
|
||||
utils.Magenta(authLogin),
|
||||
)
|
||||
|
||||
return out, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue