Skip to content

Commit d7961f1

Browse files
Merge pull request cli#13185 from cli/sammorrowdrums/skills-post-merge-review-followups
Address post-merge review feedback for skills commands
2 parents 3265170 + de204f8 commit d7961f1

4 files changed

Lines changed: 126 additions & 133 deletions

File tree

internal/skills/discovery/discovery_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -925,21 +925,21 @@ func TestMatchesSkillPath(t *testing.T) {
925925

926926
func TestMatchSkillPath(t *testing.T) {
927927
tests := []struct {
928-
testName string
928+
name string
929929
path string
930930
wantName string
931931
wantNamespace string
932932
}{
933-
{testName: "skills convention", path: "skills/code-review/SKILL.md", wantName: "code-review", wantNamespace: ""},
934-
{testName: "namespaced convention", path: "skills/monalisa/issue-triage/SKILL.md", wantName: "issue-triage", wantNamespace: "monalisa"},
935-
{testName: "plugins convention", path: "plugins/hubot/skills/pr-summary/SKILL.md", wantName: "pr-summary", wantNamespace: "hubot"},
936-
{testName: "non-skill file", path: "README.md", wantName: "", wantNamespace: ""},
937-
{testName: "same name different namespace 1", path: "skills/kynan/commit/SKILL.md", wantName: "commit", wantNamespace: "kynan"},
938-
{testName: "same name different namespace 2", path: "skills/will/commit/SKILL.md", wantName: "commit", wantNamespace: "will"},
939-
{testName: "root convention", path: "my-skill/SKILL.md", wantName: "my-skill", wantNamespace: ""},
933+
{name: "skills convention", path: "skills/code-review/SKILL.md", wantName: "code-review", wantNamespace: ""},
934+
{name: "namespaced convention", path: "skills/monalisa/issue-triage/SKILL.md", wantName: "issue-triage", wantNamespace: "monalisa"},
935+
{name: "plugins convention", path: "plugins/hubot/skills/pr-summary/SKILL.md", wantName: "pr-summary", wantNamespace: "hubot"},
936+
{name: "non-skill file", path: "README.md", wantName: "", wantNamespace: ""},
937+
{name: "same name different namespace 1", path: "skills/kynan/commit/SKILL.md", wantName: "commit", wantNamespace: "kynan"},
938+
{name: "same name different namespace 2", path: "skills/will/commit/SKILL.md", wantName: "commit", wantNamespace: "will"},
939+
{name: "root convention", path: "my-skill/SKILL.md", wantName: "my-skill", wantNamespace: ""},
940940
}
941941
for _, tt := range tests {
942-
t.Run(tt.testName, func(t *testing.T) {
942+
t.Run(tt.name, func(t *testing.T) {
943943
name, namespace := MatchSkillPath(tt.path)
944944
assert.Equal(t, tt.wantName, name)
945945
assert.Equal(t, tt.wantNamespace, namespace)

pkg/cmd/skills/publish/publish.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ type PublishOptions struct {
4242
DryRun bool
4343
Tag string
4444

45-
client *api.Client // injectable for tests; nil means use factory
46-
host string // resolved from config in production
45+
host string // resolved from config in production
4746
}
4847

4948
// publishDiagnostic is a single validation finding.
@@ -178,11 +177,10 @@ func publishRun(opts *PublishOptions) error {
178177

179178
canPrompt := opts.IO.CanPrompt()
180179

181-
// Use injected client or create one from the factory HttpClient.
182-
// Initialization is deferred until after local validation so that
180+
// Client initialization is deferred until after local validation so that
183181
// simple errors (missing skills/, bad SKILL.md, etc.) are reported
184182
// without requiring an HTTP client.
185-
client := opts.client
183+
var client *api.Client
186184
host := opts.host
187185

188186
var diagnostics []publishDiagnostic
@@ -343,14 +341,11 @@ func publishRun(opts *PublishOptions) error {
343341
hasTopic := false
344342
var existingTags []tagEntry
345343
if owner != "" && repo != "" {
346-
// Create API client from factory if not already injected (tests inject directly).
347-
if client == nil {
348-
httpClient, err := opts.HttpClient()
349-
if err != nil {
350-
return err
351-
}
352-
client = api.NewClientFromHTTP(httpClient)
344+
httpClient, err := opts.HttpClient()
345+
if err != nil {
346+
return err
353347
}
348+
client = api.NewClientFromHTTP(httpClient)
354349

355350
if host == "" && repoInfo != nil {
356351
host = repoInfo.Repo.RepoHost()
@@ -658,10 +653,11 @@ func ensurePushed(opts *PublishOptions, dir, remoteName string) error {
658653
}
659654

660655
ref := fmt.Sprintf("HEAD:refs/heads/%s", currentBranch)
661-
fmt.Fprintf(opts.IO.ErrOut, "%s Pushing %s to %s\n", cs.SuccessIcon(), currentBranch, remoteName)
656+
fmt.Fprintf(opts.IO.ErrOut, "Pushing %s to %s...\n", currentBranch, remoteName)
662657
if err := gitClient.Push(ctx, remoteName, ref); err != nil {
663658
return fmt.Errorf("failed to push branch %s: %w", currentBranch, err)
664659
}
660+
fmt.Fprintf(opts.IO.ErrOut, "%s Pushed %s to %s\n", cs.SuccessIcon(), currentBranch, remoteName)
665661

666662
return nil
667663
}
@@ -924,7 +920,9 @@ type gitHubRemote struct {
924920
}
925921

926922
// detectGitHubRemote attempts to detect the GitHub owner/repo from git remotes
927-
// in the given directory.
923+
// in the given directory. Remotes are tried in the order returned by
924+
// gitClient.Remotes (upstream > github > origin > rest), so the first
925+
// GitHub-pointing remote wins.
928926
func detectGitHubRemote(gitClient *git.Client, dir string) (*gitHubRemote, error) {
929927
if gitClient == nil {
930928
return nil, nil
@@ -933,26 +931,11 @@ func detectGitHubRemote(gitClient *git.Client, dir string) (*gitHubRemote, error
933931
dirClient := gitClient.Copy()
934932
dirClient.RepoDir = dir
935933

936-
// Try origin first
937-
if url, err := dirClient.RemoteURL(context.Background(), "origin"); err == nil {
938-
repo, parseErr := parseGitHubURL(url)
939-
if parseErr != nil {
940-
return nil, parseErr
941-
}
942-
if repo != nil {
943-
return &gitHubRemote{Repo: repo, RemoteName: "origin"}, nil
944-
}
945-
}
946-
947-
// Fall back to any remote that points to GitHub
948934
remotes, err := dirClient.Remotes(context.Background())
949935
if err != nil {
950936
return nil, nil //nolint:nilerr // failing to list remotes is not an error; it just means no repo detected
951937
}
952938
for _, r := range remotes {
953-
if r.Name == "origin" {
954-
continue
955-
}
956939
if url, err := dirClient.RemoteURL(context.Background(), r.Name); err == nil {
957940
repo, parseErr := parseGitHubURL(url)
958941
if parseErr != nil {

0 commit comments

Comments
 (0)