feat: add support for stateReason in gh pr view (#9080)

This commit is contained in:
nobe4 2024-05-21 19:54:56 +02:00 committed by GitHub
parent 7dc7b9838d
commit 140edf7327
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -268,6 +268,7 @@ var IssueFields = []string{
"title",
"updatedAt",
"url",
"stateReason",
}
var PullRequestFields = append(IssueFields,
@ -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
@ -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())
}