Merge pull request #13237 from cli/sammorrowdrums/fix-skill-publish-fix-flag

This commit is contained in:
Sam Morrow 2026-04-20 19:23:09 +02:00 committed by GitHub
commit 49d4747a81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 11 deletions

View file

@ -126,7 +126,8 @@ func NewCmdPublish(f *cmdutil.Factory, runF func(*PublishOptions) error) *cobra.
Use %[1]s--dry-run%[1]s to validate without publishing.
Use %[1]s--tag%[1]s to publish non-interactively with a specific tag.
Use %[1]s--fix%[1]s to automatically strip install metadata from committed files.
Use %[1]s--fix%[1]s to automatically strip install metadata from committed files
without publishing. Review and commit the changes, then run publish again.
`, "`"),
Example: heredoc.Doc(`
# Validate and publish interactively
@ -138,14 +139,17 @@ func NewCmdPublish(f *cmdutil.Factory, runF func(*PublishOptions) error) *cobra.
# Validate only (no publish)
$ gh skill publish --dry-run
# Validate and strip install metadata
$ gh skills publish --fix
# Strip install metadata without publishing
$ gh skill publish --fix
`),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
opts.Dir = args[0]
}
if err := cmdutil.MutuallyExclusive("specify only one of `--fix` or `--dry-run`", opts.Fix, opts.DryRun); err != nil {
return err
}
if runF != nil {
return runF(opts)
}
@ -153,7 +157,7 @@ func NewCmdPublish(f *cmdutil.Factory, runF func(*PublishOptions) error) *cobra.
},
}
cmd.Flags().BoolVar(&opts.Fix, "fix", false, "Auto-fix issues where possible (e.g. strip install metadata)")
cmd.Flags().BoolVar(&opts.Fix, "fix", false, "Auto-fix issues where possible without publishing (e.g. strip install metadata)")
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "Validate without publishing")
cmd.Flags().StringVar(&opts.Tag, "tag", "", "Version tag for the release (e.g. v1.0.0)")
@ -410,6 +414,15 @@ func publishRun(opts *PublishOptions) error {
return nil
}
if opts.Fix {
if fixes > 0 {
fmt.Fprintf(opts.IO.ErrOut, "\nFixed %d file(s). Review and commit the changes, then run %s to publish.\n", fixes, "gh skill publish")
} else {
fmt.Fprintf(opts.IO.ErrOut, "\nNo issues to fix.\n")
}
return nil
}
if owner == "" || repo == "" {
fmt.Fprintf(opts.IO.ErrOut, "\nValidation passed. Set up a GitHub remote to publish.\n")
return nil
@ -1059,7 +1072,7 @@ func renderDiagnosticsTTY(opts *PublishOptions, skillCount int, diagnostics []pu
fmt.Fprintf(opts.IO.ErrOut, "\n%s\n", d.message)
}
if errors == 0 {
if errors == 0 && !opts.Fix {
if owner != "" && repo != "" {
fmt.Fprintf(opts.IO.ErrOut, "\n%s Repository: %s/%s\n", cs.Green("Ready to publish!"), owner, repo)
} else {

View file

@ -86,13 +86,15 @@ func TestNewCmdPublish(t *testing.T) {
wantsOpts PublishOptions
}{
{
name: "all flags",
cli: "./monalisa-skills --dry-run --fix --tag v1.0.0",
name: "fix and dry-run are mutually exclusive",
cli: "./monalisa-skills --dry-run --fix --tag v1.0.0",
wantsErr: true,
},
{
name: "fix flag only",
cli: "--fix",
wantsOpts: PublishOptions{
Dir: "./monalisa-skills",
DryRun: true,
Fix: true,
Tag: "v1.0.0",
Fix: true,
},
},
{
@ -457,6 +459,7 @@ func TestPublishRun(t *testing.T) {
return &PublishOptions{IO: ios, Dir: dir, Fix: true}
},
wantStdout: "stripped install metadata",
wantStderr: "Fixed 1 file(s). Review and commit the changes",
verify: func(t *testing.T, dir string) {
t.Helper()
fixed, err := os.ReadFile(filepath.Join(dir, "skills", "test-skill", "SKILL.md"))