Merge branch 'trunk' of https://github.com/cli/cli into feature/repo-with-gitignore-license
This commit is contained in:
commit
7c8b6867f4
54 changed files with 2543 additions and 923 deletions
|
|
@ -80,10 +80,20 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
|
|||
case "reviewRequests":
|
||||
requests := make([]interface{}, 0, len(pr.ReviewRequests.Nodes))
|
||||
for _, req := range pr.ReviewRequests.Nodes {
|
||||
if req.RequestedReviewer.TypeName == "" {
|
||||
continue
|
||||
r := req.RequestedReviewer
|
||||
switch r.TypeName {
|
||||
case "User":
|
||||
requests = append(requests, map[string]string{
|
||||
"__typename": r.TypeName,
|
||||
"login": r.Login,
|
||||
})
|
||||
case "Team":
|
||||
requests = append(requests, map[string]string{
|
||||
"__typename": r.TypeName,
|
||||
"name": r.Name,
|
||||
"slug": r.LoginOrSlug(),
|
||||
})
|
||||
}
|
||||
requests = append(requests, req.RequestedReviewer)
|
||||
}
|
||||
data[f] = &requests
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -150,28 +150,33 @@ type PullRequestFile struct {
|
|||
|
||||
type ReviewRequests struct {
|
||||
Nodes []struct {
|
||||
RequestedReviewer struct {
|
||||
TypeName string `json:"__typename"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Organization struct {
|
||||
Login string `json:"login"`
|
||||
}
|
||||
}
|
||||
RequestedReviewer RequestedReviewer
|
||||
}
|
||||
}
|
||||
|
||||
type RequestedReviewer struct {
|
||||
TypeName string `json:"__typename"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Organization struct {
|
||||
Login string `json:"login"`
|
||||
} `json:"organization"`
|
||||
}
|
||||
|
||||
func (r RequestedReviewer) LoginOrSlug() string {
|
||||
if r.TypeName == teamTypeName {
|
||||
return fmt.Sprintf("%s/%s", r.Organization.Login, r.Slug)
|
||||
}
|
||||
return r.Login
|
||||
}
|
||||
|
||||
const teamTypeName = "Team"
|
||||
|
||||
func (r ReviewRequests) Logins() []string {
|
||||
logins := make([]string, len(r.Nodes))
|
||||
for i, a := range r.Nodes {
|
||||
if a.RequestedReviewer.TypeName == teamTypeName {
|
||||
logins[i] = fmt.Sprintf("%s/%s", a.RequestedReviewer.Organization.Login, a.RequestedReviewer.Slug)
|
||||
} else {
|
||||
logins[i] = a.RequestedReviewer.Login
|
||||
}
|
||||
for i, r := range r.Nodes {
|
||||
logins[i] = r.RequestedReviewer.LoginOrSlug()
|
||||
}
|
||||
return logins
|
||||
}
|
||||
|
|
@ -391,7 +396,7 @@ func PullRequestStatus(client *Client, repo ghrepo.Interface, options StatusOpti
|
|||
// these are always necessary to find the PR for the current branch
|
||||
fields.AddValues([]string{"isCrossRepository", "headRepositoryOwner", "headRefName"})
|
||||
gr := PullRequestGraphQL(fields.ToSlice())
|
||||
fragments = fmt.Sprintf("fragment pr on PullRequest{%[1]s}fragment prWithReviews on PullRequest{%[1]s}", gr)
|
||||
fragments = fmt.Sprintf("fragment pr on PullRequest{%s}fragment prWithReviews on PullRequest{...pr}", gr)
|
||||
} else {
|
||||
var err error
|
||||
fragments, err = pullRequestFragment(client.http, repo.RepoHost())
|
||||
|
|
@ -526,67 +531,23 @@ func pullRequestFragment(httpClient *http.Client, hostname string) (string, erro
|
|||
return "", err
|
||||
}
|
||||
|
||||
var reviewsFragment string
|
||||
if prFeatures.HasReviewDecision {
|
||||
reviewsFragment = "reviewDecision"
|
||||
fields := []string{
|
||||
"number", "title", "state", "url", "isDraft", "isCrossRepository",
|
||||
"requiresStrictStatusChecks", "headRefName", "headRepositoryOwner", "mergeStateStatus",
|
||||
}
|
||||
|
||||
var statusesFragment string
|
||||
if prFeatures.HasStatusCheckRollup {
|
||||
statusesFragment = `
|
||||
commits(last: 1) {
|
||||
nodes {
|
||||
commit {
|
||||
statusCheckRollup {
|
||||
contexts(last: 100) {
|
||||
nodes {
|
||||
...on StatusContext {
|
||||
state
|
||||
}
|
||||
...on CheckRun {
|
||||
conclusion
|
||||
status
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
fields = append(fields, "statusCheckRollup")
|
||||
}
|
||||
|
||||
var requiresStrictStatusChecks string
|
||||
if prFeatures.HasBranchProtectionRule {
|
||||
requiresStrictStatusChecks = `
|
||||
baseRef {
|
||||
branchProtectionRule {
|
||||
requiresStrictStatusChecks
|
||||
}
|
||||
}`
|
||||
var reviewFields []string
|
||||
if prFeatures.HasReviewDecision {
|
||||
reviewFields = append(reviewFields, "reviewDecision")
|
||||
}
|
||||
|
||||
fragments := fmt.Sprintf(`
|
||||
fragment pr on PullRequest {
|
||||
number
|
||||
title
|
||||
state
|
||||
url
|
||||
headRefName
|
||||
mergeStateStatus
|
||||
headRepositoryOwner {
|
||||
login
|
||||
}
|
||||
%s
|
||||
isCrossRepository
|
||||
isDraft
|
||||
%s
|
||||
}
|
||||
fragment prWithReviews on PullRequest {
|
||||
...pr
|
||||
%s
|
||||
}
|
||||
`, requiresStrictStatusChecks, statusesFragment, reviewsFragment)
|
||||
fragment pr on PullRequest {%s}
|
||||
fragment prWithReviews on PullRequest {...pr,%s}
|
||||
`, PullRequestGraphQL(fields), PullRequestGraphQL(reviewFields))
|
||||
return fragments, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -216,6 +216,8 @@ func PullRequestGraphQL(fields []string) string {
|
|||
q = append(q, `commits(last:1){nodes{commit{oid}}}`)
|
||||
case "commitsCount": // pseudo-field
|
||||
q = append(q, `commits{totalCount}`)
|
||||
case "requiresStrictStatusChecks": // pseudo-field
|
||||
q = append(q, `baseRef{branchProtectionRule{requiresStrictStatusChecks}}`)
|
||||
case "statusCheckRollup":
|
||||
q = append(q, StatusCheckRollupGraphQL(""))
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue