Help us shape the future of Go! Take the 2026 Go Developer Survey

remote

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package remote parses git remote URLs and derives host-specific actions from them.

wtg itself is provider-agnostic: it talks to git rather than to a hosting service. This package is the one place that knows about GitHub, and only to help the user archive retired repos with the `gh` CLI (see docs/adr/0013-repo-archive.md).

Index

Constants

View Source
const GitHubHost = "github.com"

GitHubHost is the host v1 recognizes for archival. GitHub Enterprise and other forges are intentionally excluded for now, so a remote on any other host yields ok == false and no GitHub action is suggested.

Variables

This section is empty.

Functions

func ArchiveCommand

func ArchiveCommand(ownerRepo string) string

ArchiveCommand returns the `gh` invocation that archives ownerRepo on GitHub. `gh repo archive` has existed since gh 2.32. Without --remote, wtg prints this command for the user to run; with --remote, SystemRunner executes the same command (see gh.go).

func ParseGitHubRemote

func ParseGitHubRemote(raw string) (ownerRepo, host string, ok bool)

ParseGitHubRemote extracts the "owner/repo" slug and the hostname from a git remote URL.

It understands the URL forms git produces in practice:

git@github.com:owner/repo.git
github.com:owner/repo.git
ssh://git@github.com/owner/repo.git
ssh://git@github.com:22/owner/repo.git
https://github.com/owner/repo.git
http://github.com/owner/repo

host is the remote's hostname, lowercased and with any port stripped. ok reports whether the remote points at GitHub (GitHubHost) and a valid owner/repo slug was found. A non-GitHub remote (GitLab, GitHub Enterprise, Bitbucket, ...) yields ok == false but still fills in host and, when the path parses, ownerRepo, so the caller can explain why no GitHub action is offered. A URL that cannot be parsed at all yields an empty ownerRepo and host.

func UnarchiveCommand

func UnarchiveCommand(ownerRepo string) string

UnarchiveCommand returns the `gh` invocation that unarchives ownerRepo on GitHub, the inverse of ArchiveCommand. It is printed by `wtg repo unarchive` without --remote, and executed by SystemRunner with --remote.

Types

type Runner

type Runner interface {
	// Available reports whether the gh CLI is installed and on PATH.
	Available() error
	// AuthStatus verifies gh is authenticated for host.
	AuthStatus(ctx context.Context, host string) error
	// IsArchived reports whether ownerRepo is already archived on host. It is
	// the read-only check that makes the archive idempotent.
	IsArchived(ctx context.Context, host, ownerRepo string) (bool, error)
	// Archive archives ownerRepo on host.
	Archive(ctx context.Context, host, ownerRepo string) error
	// Unarchive reverses Archive. It is used only to roll back a failed saga.
	Unarchive(ctx context.Context, host, ownerRepo string) error
}

Runner runs the read-only and mutating `gh` commands that back `wtg repo archive --remote`. It is an interface so command tests can inject a fake; the real implementation is SystemRunner.

type SystemRunner

type SystemRunner struct{}

SystemRunner runs the gh CLI found on PATH.

func (SystemRunner) Archive

func (SystemRunner) Archive(ctx context.Context, host, ownerRepo string) error

Archive archives ownerRepo on host.

func (SystemRunner) AuthStatus

func (SystemRunner) AuthStatus(ctx context.Context, host string) error

AuthStatus verifies gh is authenticated for host.

func (SystemRunner) Available

func (SystemRunner) Available() error

Available reports whether gh is installed.

func (SystemRunner) IsArchived

func (SystemRunner) IsArchived(ctx context.Context, host, ownerRepo string) (bool, error)

IsArchived reports whether ownerRepo is already archived on host.

func (SystemRunner) Unarchive

func (SystemRunner) Unarchive(ctx context.Context, host, ownerRepo string) error

Unarchive reverses Archive.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL