From 140edf7327beb9af5a51ee6975fed08648dca9e1 Mon Sep 17 00:00:00 2001 From: nobe4 Date: Tue, 21 May 2024 19:54:56 +0200 Subject: [PATCH] feat: add support for stateReason in `gh pr view` (#9080) --- api/query_builder.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/query_builder.go b/api/query_builder.go index 3ccc1ff2e6d..0f131232c9a 100644 --- a/api/query_builder.go +++ b/api/query_builder.go @@ -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()) }