Skip to content

[plan] Replace gh repo view with repository.Current() #5829

@github-actions

Description

@github-actions

Objective

Replace the shell-out gh.Exec("repo", "view", ...) call with the native repository.Current() function for detecting the current repository.

Context

This is a quick win that eliminates unnecessary process spawning and provides cleaner, more idiomatic Go code. The native function also respects the GH_REPO environment variable automatically.

Files to Modify

  • Update: pkg/workflow/repository_features_validation.go (line ~182)

Current Implementation

stdOut, _, err := gh.Exec("repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner")
if err != nil {
    return "", fmt.Errorf("failed to get repository name: %w", err)
}
repo := strings.TrimSpace(stdOut.String())

Target Implementation

import "github.com/cli/go-gh/v2/pkg/repository"

repo, err := repository.Current()
if err != nil {
    return "", fmt.Errorf("failed to get repository name: %w", err)
}
repoName := fmt.Sprintf("%s/%s", repo.Owner(), repo.Name())

Acceptance Criteria

  • gh.Exec("repo", "view", ...) replaced with repository.Current()
  • Import github.com/cli/go-gh/v2/pkg/repository added
  • Error handling preserved
  • All unit tests pass (make test-unit)
  • Code builds successfully (make build)

Expected Impact

  • Performance: ~5-10x faster (no process spawning)
  • Code Quality: More readable and maintainable
  • Reliability: Better error messages from native function

Estimated Effort

5-10 minutes
Related to #5828

AI generated by Plan Command for discussion #5826

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions