Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,27 @@ func TestExecuteDELETEWithBody(t *testing.T) {
}
}

func TestBuildBodyOptionalStringSendsExplicitEmpty(t *testing.T) {
type args struct {
Owner string `json:"owner"`
Desc *string `json:"description"`
Site *string `json:"website"`
}

empty := ""
body := buildBody(args{Owner: "acme", Desc: &empty, Site: nil}, map[string]bool{"Owner": true})
m, ok := body.(map[string]any)
if !ok {
t.Fatalf("body type = %T, want map[string]any", body)
}
if _, ok := m["description"]; !ok {
t.Error("explicit empty *string should be included in body")
}
if _, ok := m["website"]; ok {
t.Error("nil *string should be excluded from body")
}
}

func TestBuildBodyCSVTag(t *testing.T) {
type args struct {
Owner string `json:"owner"`
Expand Down
14 changes: 14 additions & 0 deletions cmd/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type fieldData struct {
ContextInfer bool
IsOptBool bool
IsOptInt bool
IsOptString bool
}

func groupedTools() map[string][]tools.ToolDef {
Expand Down Expand Up @@ -125,6 +126,7 @@ func generateGroup(name string, defs []tools.ToolDef) error {
ContextInfer: hasRepo && (jsonName == "owner" || jsonName == "repo"),
IsOptBool: isOptBool(f.Type),
IsOptInt: isOptInt(f.Type),
IsOptString: isOptString(f.Type),
})
}

Expand Down Expand Up @@ -194,6 +196,10 @@ func isOptInt(t reflect.Type) bool {
return t.Kind() == reflect.Ptr && (t.Elem().Kind() >= reflect.Int && t.Elem().Kind() <= reflect.Int64)
}

func isOptString(t reflect.Type) bool {
return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.String
}

func toExportedName(s string) string {
parts := strings.FieldsFunc(s, func(r rune) bool {
return r == '_' || r == '-'
Expand Down Expand Up @@ -320,6 +326,8 @@ func {{.FuncName}}Cmd() *cobra.Command {
var _{{.GoName}} bool
{{- end}}{{- if .IsOptInt}}
var _{{.GoName}} int
{{- end}}{{- if .IsOptString}}
var _{{.GoName}} string
{{- end}}{{- end}}
cmd := &cobra.Command{
Use: "{{.CLIName}}",
Expand All @@ -333,6 +341,10 @@ func {{.FuncName}}Cmd() *cobra.Command {
if cmd.Flags().Changed("{{.JSONName}}") {
args.{{.GoName}} = &_{{.GoName}}
}
{{- end}}{{- if .IsOptString}}
if cmd.Flags().Changed("{{.JSONName}}") {
args.{{.GoName}} = &_{{.GoName}}
}
{{- end}}{{- end}}
td := tools.ByName("{{.ToolName}}")
return ExecuteAndPrint(cmd, td, &args)
Expand All @@ -343,6 +355,8 @@ func {{.FuncName}}Cmd() *cobra.Command {
cmd.Flags().BoolVar(&_{{.GoName}}, "{{.JSONName}}", false, ` + "`{{.Desc}}`" + `)
{{- else if .IsOptInt}}
cmd.Flags().IntVar(&_{{.GoName}}, "{{.JSONName}}", 0, ` + "`{{.Desc}}`" + `)
{{- else if .IsOptString}}
cmd.Flags().StringVar(&_{{.GoName}}, "{{.JSONName}}", "", ` + "`{{.Desc}}`" + `)
{{- else}}
cmd.Flags().{{.FlagType}}Var(&args.{{.GoName}}, "{{.JSONName}}", {{defaultVal .FlagType .Default}}, ` + "`{{.Desc}}`" + `)
{{- end}}
Expand Down
18 changes: 15 additions & 3 deletions internal/gen/issue.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions internal/gen/pr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions internal/gen/protection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions internal/gen/release.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions internal/gen/repo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions internal/gen/webhook.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions tools/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ type CreateIssueCommentArgs struct {
}

type UpdateIssueArgs struct {
Owner string `json:"owner" required:"true" desc:"Repository owner"`
Repo string `json:"repo" required:"true" desc:"Repository name"`
Index int `json:"index" required:"true" desc:"Issue index"`
Title string `json:"title" desc:"Title"`
Body string `json:"body" desc:"Content body"`
Assignee string `json:"assignee" desc:"Assignee username (convenience for a single user; equivalent to a one-element 'assignees')"`
Assignees string `json:"assignees" desc:"Assignee usernames (comma-separated). Overrides 'assignee' if both are set. Pass an empty string to clear all assignees." body:"csv"`
Milestone int `json:"milestone" desc:"Milestone ID"`
Owner string `json:"owner" required:"true" desc:"Repository owner"`
Repo string `json:"repo" required:"true" desc:"Repository name"`
Index int `json:"index" required:"true" desc:"Issue index"`
Title string `json:"title" desc:"Title"`
Body *string `json:"body" desc:"Content body"`
Assignee *string `json:"assignee" desc:"Assignee username (convenience for a single user; equivalent to a one-element 'assignees')"`
Assignees string `json:"assignees" desc:"Assignee usernames (comma-separated). Overrides 'assignee' if both are set. Pass an empty string to clear all assignees." body:"csv"`
Milestone int `json:"milestone" desc:"Milestone ID"`
}

type AddIssueLabelsArgs struct {
Expand Down Expand Up @@ -120,13 +120,13 @@ type CreateLabelArgs struct {
}

type EditLabelArgs struct {
Owner string `json:"owner" required:"true" desc:"Repository owner or organization name"`
ID int `json:"id" required:"true" desc:"Label ID"`
Repo string `json:"repo" desc:"Repository name. Omit to edit an org-level label."`
Name string `json:"name" desc:"New label name"`
Color string `json:"color" desc:"New label color hex code"`
Description string `json:"description" desc:"New label description"`
Exclusive bool `json:"exclusive" desc:"Whether this label is exclusive"`
Owner string `json:"owner" required:"true" desc:"Repository owner or organization name"`
ID int `json:"id" required:"true" desc:"Label ID"`
Repo string `json:"repo" desc:"Repository name. Omit to edit an org-level label."`
Name string `json:"name" desc:"New label name"`
Color string `json:"color" desc:"New label color hex code"`
Description *string `json:"description" desc:"New label description"`
Exclusive bool `json:"exclusive" desc:"Whether this label is exclusive"`
}

type DeleteLabelArgs struct {
Expand Down
16 changes: 8 additions & 8 deletions tools/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type CreatePullRequestArgs struct {
}

type UpdatePullRequestArgs struct {
Owner string `json:"owner" required:"true" desc:"Repository owner"`
Repo string `json:"repo" required:"true" desc:"Repository name"`
Index int `json:"index" required:"true" desc:"PR index"`
Title string `json:"title" desc:"Title"`
Body string `json:"body" desc:"Content body"`
Base string `json:"base" desc:"Base branch"`
Assignee string `json:"assignee" desc:"Assignee username"`
Milestone int `json:"milestone" desc:"Milestone ID"`
Owner string `json:"owner" required:"true" desc:"Repository owner"`
Repo string `json:"repo" required:"true" desc:"Repository name"`
Index int `json:"index" required:"true" desc:"PR index"`
Title string `json:"title" desc:"Title"`
Body *string `json:"body" desc:"Content body"`
Base string `json:"base" desc:"Base branch"`
Assignee *string `json:"assignee" desc:"Assignee username"`
Milestone int `json:"milestone" desc:"Milestone ID"`
}

type ListPullReviewsArgs struct {
Expand Down
Loading
Loading