Skip to content

Commit

Permalink
Add isDraft to search prs json options, matching pr view (cli#6704
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mgabeler-lee-6rs authored Dec 9, 2022
1 parent 4fd56ac commit eadc8e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/search/prs/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 20 additions & 13 deletions pkg/search/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
13 changes: 13 additions & 0 deletions pkg/search/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit eadc8e8

Please sign in to comment.