Skip to content

Commit

Permalink
feat: add support for stateReason in gh pr view (cli#9080)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 authored May 21, 2024
1 parent 7dc7b98 commit 140edf7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions api/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ var IssueFields = []string{
"title",
"updatedAt",
"url",
"stateReason",
}

var PullRequestFields = append(IssueFields,
Expand Down Expand Up @@ -298,6 +299,12 @@ var PullRequestFields = append(IssueFields,
"statusCheckRollup",
)

// Some fields are only valid in the context of issues.
var issueOnlyFields = []string{
"isPinned",
"stateReason",
}

// IssueGraphQL constructs a GraphQL query fragment for a set of issue fields.
func IssueGraphQL(fields []string) string {
var q []string
Expand Down Expand Up @@ -363,10 +370,9 @@ func IssueGraphQL(fields []string) string {
// PullRequestGraphQL constructs a GraphQL query fragment for a set of pull request fields.
// It will try to sanitize the fields to just those available on pull request.
func PullRequestGraphQL(fields []string) string {
invalidFields := []string{"isPinned", "stateReason"}
s := set.NewStringSet()
s.AddValues(fields)
s.RemoveValues(invalidFields)
s.RemoveValues(issueOnlyFields)
return IssueGraphQL(s.ToSlice())
}

Expand Down

0 comments on commit 140edf7

Please sign in to comment.