@@ -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.
928926func 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