Skip to content

fix: use target directory remotes in skills publish#13169

Merged
SamMorrowDrums merged 2 commits intosm/add-skills-commandfrom
sammorrowdrums/fix-skills-publish-remote-detection
Apr 15, 2026
Merged

fix: use target directory remotes in skills publish#13169
SamMorrowDrums merged 2 commits intosm/add-skills-commandfrom
sammorrowdrums/fix-skills-publish-remote-detection

Conversation

@SamMorrowDrums
Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where gh skill publish /path/to/repo-bar run from inside repo-foo would detect repo-foo's remotes instead of repo-bar's, potentially creating a release on the wrong repository.

Bug

detectGitHubRemote used the factory-provided gitClient directly, which has its RepoDir set to the current working directory. When a dir argument is passed to publish, the function should look at the remotes of the target directory, not the CWD.

Reproduction scenario

  1. User is in repo-foo working directory
  2. User runs gh skill publish /path/to/repo-bar
  3. Both repos have GitHub remotes
  4. Validation passes on repo-bar's local files, but the release gets created on repo-foo

Fix

detectGitHubRemote now accepts a dir parameter, copies the git client, and sets RepoDir = dir — matching the pattern already used by detectMissingRepoDiagnostic and checkInstalledSkillDirs.

Testing (TDD)

  • TestDetectGitHubRemote_UsesDir — unit test for the function directly: creates two git repos with different remotes, verifies the correct one is returned
  • TestPublishRun_DirArgUsesTargetRemote — integration test through publishRun: simulates the full bug scenario with HTTP mocks that would fail if the wrong repo is detected
  • Acceptance test (skills-publish-dir-remote.txtar) — end-to-end test creating two real GitHub repos and verifying the release lands on the correct one

All existing tests updated to initialize git repos in the skill directory (matching production behavior).

Stacked on #13165

Co-authored-by: BagToad 47394200+BagToad@users.noreply.github.com

When a directory argument is provided to `gh skill publish`, the remote
detection now correctly uses the target directory's git remotes instead
of the current working directory's remotes.

Previously, `detectGitHubRemote` used the factory-provided git client
which pointed to the CWD. This meant that running
`gh skill publish /path/to/repo-bar` from inside repo-foo would detect
repo-foo's remotes and potentially create the release on the wrong repo.

The fix copies the git client and sets `RepoDir` to the target directory,
matching the pattern already used by `detectMissingRepoDiagnostic` and
`checkInstalledSkillDirs`.

Co-authored-by: BagToad <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner April 15, 2026 20:56
@SamMorrowDrums SamMorrowDrums changed the base branch from trunk to sm/add-skills-command April 15, 2026 20:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect GitHub remote detection in gh skill publish when a target directory is provided, ensuring releases are created against the target repo rather than the current working directory.

Changes:

  • Update detectGitHubRemote to accept a target dir and run git remote detection against that directory (via a copied git client with RepoDir set).
  • Refactor/extend tests to initialize git repos in the skill directory and add regression coverage for the --dir scenario.
  • Add an acceptance test covering publishing from one repo while targeting another.
Show a summary per file
File Description
pkg/cmd/skills/publish/publish.go Ensures remote detection uses the provided publish directory by copying the git client and setting RepoDir.
pkg/cmd/skills/publish/publish_test.go Updates existing tests to initialize git in the target dir and adds new unit/integration regression tests for dir-based remote detection.
acceptance/testdata/skills/skills-publish-dir-remote.txtar Adds end-to-end acceptance coverage verifying release is created on the target repo when invoked from another repo.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread pkg/cmd/skills/publish/publish_test.go Outdated
Comment on lines +23 to +28
func newTestGitClient(t *testing.T, remoteURLs map[string]string) *git.Client {
t.Helper()
dir := t.TempDir()
runGit := func(args ...string) {
t.Helper()
cmd := exec.Command("git", append([]string{"-C", dir}, args...)...)
cmd.Env = append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1", "HOME="+dir)
out, err := cmd.CombinedOutput()
require.NoError(t, err, "git %v: %s", args, out)
}
runGit("init", "--initial-branch=main")
runGit("config", "user.email", "monalisa@github.com")
runGit("config", "user.name", "Monalisa Octocat")
initGitRepo(t, dir, remoteURLs)
return &git.Client{RepoDir: dir}
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newTestGitClient is no longer referenced anywhere in this test file (only defined). Consider removing it to reduce dead code, or switch call sites to use it instead of open-coding initGitRepo + &git.Client{} where appropriate.

See below for a potential fix:


Copilot uses AI. Check for mistakes.
Remove the now-unused newTestGitClient helper that was left behind
after refactoring tests to use initGitRepo directly. This fixes the
golangci-lint 'unused' error in CI.

Co-authored-by: BagToad <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I thought: maybe there's a way to fold the standalone test into the table test - but I don't think it's worth the effort to rework the table test to accommodate making multiple git dirs and whatever else it needs.

@SamMorrowDrums
Copy link
Copy Markdown
Contributor Author

Good question @BagToad you are likely right it's both possible but maybe not necessarily desirable.

LMK if you want it as a follow up. I will merge for sake of getting ready for release.

@SamMorrowDrums SamMorrowDrums merged commit 980428c into sm/add-skills-command Apr 15, 2026
8 checks passed
@SamMorrowDrums SamMorrowDrums deleted the sammorrowdrums/fix-skills-publish-remote-detection branch April 15, 2026 23:17
@t72053166-eng t72053166-eng mentioned this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants