diff --git a/pkg/cmd/search/prs/prs.go b/pkg/cmd/search/prs/prs.go index ea31001ce..2fd4961ff 100644 --- a/pkg/cmd/search/prs/prs.go +++ b/pkg/cmd/search/prs/prs.go @@ -122,7 +122,7 @@ func NewCmdPrs(f *cmdutil.Factory, runF func(*shared.IssuesOptions) error) *cobr } // Output flags - cmdutil.AddJSONFlags(cmd, &opts.Exporter, search.IssueFields) + cmdutil.AddJSONFlags(cmd, &opts.Exporter, search.PullRequestFields) cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the search query in the web browser") // Query parameter flags diff --git a/pkg/search/result.go b/pkg/search/result.go index b9a009695..8c2e3aa39 100644 --- a/pkg/search/result.go +++ b/pkg/search/result.go @@ -57,6 +57,10 @@ var IssueFields = []string{ "url", } +var PullRequestFields = append(IssueFields, + "isDraft", +) + type RepositoriesResult struct { IncompleteResults bool `json:"incomplete_results"` Items []Repository `json:"items"` @@ -124,19 +128,22 @@ func (u *User) IsBot() bool { } type Issue struct { - Assignees []User `json:"assignees"` - Author User `json:"user"` - AuthorAssociation string `json:"author_association"` - Body string `json:"body"` - ClosedAt time.Time `json:"closed_at"` - CommentsCount int `json:"comments"` - CreatedAt time.Time `json:"created_at"` - ID string `json:"node_id"` - Labels []Label `json:"labels"` - IsLocked bool `json:"locked"` - Number int `json:"number"` - PullRequest PullRequest `json:"pull_request"` - RepositoryURL string `json:"repository_url"` + Assignees []User `json:"assignees"` + Author User `json:"user"` + AuthorAssociation string `json:"author_association"` + Body string `json:"body"` + ClosedAt time.Time `json:"closed_at"` + CommentsCount int `json:"comments"` + CreatedAt time.Time `json:"created_at"` + ID string `json:"node_id"` + Labels []Label `json:"labels"` + // This is a PullRequest field which does not appear in issue results, + // but lives outside the PullRequest object. + IsDraft *bool `json:"draft,omitempty"` + IsLocked bool `json:"locked"` + Number int `json:"number"` + PullRequest PullRequest `json:"pull_request"` + RepositoryURL string `json:"repository_url"` // StateInternal should not be used directly. Use State() instead. StateInternal string `json:"state"` StateReason string `json:"state_reason"` diff --git a/pkg/search/result_test.go b/pkg/search/result_test.go index becb839c9..756e3b908 100644 --- a/pkg/search/result_test.go +++ b/pkg/search/result_test.go @@ -47,6 +47,7 @@ func TestRepositoryExportData(t *testing.T) { func TestIssueExportData(t *testing.T) { var updatedAt = time.Date(2021, 2, 28, 12, 30, 0, 0, time.UTC) + trueValue := true tests := []struct { name string fields []string @@ -88,6 +89,18 @@ func TestIssueExportData(t *testing.T) { }, output: `{"isPullRequest":true,"state":"merged"}`, }, + { + name: "isDraft when pull request", + fields: []string{"isDraft", "state"}, + issue: Issue{ + PullRequest: PullRequest{ + URL: "a-url", + }, + StateInternal: "open", + IsDraft: &trueValue, + }, + output: `{"isDraft":true,"state":"open"}`, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {