gitremote

package
v0.111.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitremote answers "where does this repository live on the web, and which pull requests did a session open", from the machine alone.

Owner request (2026-10-04): from a session, one click to the repository it works in and to the pull requests it opened. Rule 4 holds: nothing here makes a network call. The repository comes from `git remote get-url` in the session's directory, turned into a web address by string rules; the pull requests come from what Claude Code already recorded in its own tool output. A remote this package cannot read as a web host yields no link rather than a guessed one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchURL

func BranchURL(repoURL, branch, defaultBranch string) string

BranchURL is the web page of a branch, or "" when the branch is the default (the repository page already shows it), unknown, or the host's scheme for branch pages is not one this package knows. Hosts are recognised by name, so GitHub Enterprise and self-hosted GitLab are covered when their host says so.

func WebURL

func WebURL(remote string) (string, bool)

WebURL turns a git remote into the repository's https address.

Accepted: `git@host:owner/repo.git` (scp-like), `ssh://[user@]host[:port]/owner/repo.git`, `git+ssh://`, `git://`, `http(s)://[user[:pass]@]host[:port]/owner/repo(.git)`. Credentials and an ssh port are dropped (the web is on https's own port); an http(s) port is kept. A local path, `file://`, or anything else that names no host returns false.

Types

type PR

type PR struct {
	URL    string `json:"url"`
	Number int    `json:"number"`
	// Title is the `--title` the command passed, when it passed one plainly.
	Title string `json:"title,omitempty"`
	// Action is what this one command did: created, merged, closed, edited,
	// commented. Only a recorded "merged" ever makes a PR read as merged.
	Action string `json:"action"`
}

PR is one pull request a session opened, or merged, as its own tool output recorded it.

func FromToolPost

func FromToolPost(payload []byte) (PR, bool)

FromToolPost reads a pull request out of a Bash tool's PostToolUse payload.

Claude Code records `tool_response.gitOperation.pr` — {number, url, action} — when a `gh pr` command succeeds; that is the primary source and the only one trusted for anything but "created". Without it, a `gh pr create` whose output carries a pull-request URL counts as created. A failed command records nothing.

type Repo

type Repo struct {
	// Root is the repository's top level on this machine, or the directory
	// itself when git could not say. Shown, with a copy button, when there is
	// no web address to link to.
	Root string `json:"root"`
	// URL is the repository's web address, https, no credentials. Empty when
	// there is no remote or it is not a web host (a path, a file:// URL).
	URL string `json:"url,omitempty"`
	// Branch is the checked-out branch; empty on a detached HEAD.
	Branch string `json:"branch,omitempty"`
	// DefaultBranch is the remote's default branch when git knows it locally
	// (refs/remotes/<remote>/HEAD).
	DefaultBranch string `json:"default_branch,omitempty"`
	// BranchURL is the branch's page, set only when the branch is not the
	// default and the host's URL scheme for branches is known.
	BranchURL string `json:"branch_url,omitempty"`
}

Repo is where a working directory's repository lives.

func Lookup

func Lookup(ctx context.Context, dir string) (Repo, bool)

Lookup reads the repository a directory belongs to. It runs git with a short timeout per call; a directory that is not a repository returns a Repo with only Root set and ok=false.

Jump to

Keyboard shortcuts

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