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
23 changes: 18 additions & 5 deletions pkg/cmd/skills/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -138,22 +139,25 @@ 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)
}
return publishRun(opts)
},
}

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)")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions pkg/cmd/skills/publish/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
{
Expand Down Expand Up @@ -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"))
Expand Down
Loading