github

package
v1.54.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package github implements scm.Host backed by the gh CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostPrefixedSlug

func HostPrefixedSlug(remoteURL string) string

HostPrefixedSlug returns "host/owner/name" for GitHub Enterprise Server instances and plain "owner/name" for github.com. This is the format that the gh CLI's --repo flag requires for GHE.

func HostPrefixedSlugForHost

func HostPrefixedSlugForHost(remoteURL, host string) string

HostPrefixedSlugForHost is HostPrefixedSlug using an already-resolved host. This lets callers honor SSH HostName aliases without rewriting the remote.

func RepoSlug

func RepoSlug(remoteURL string) string

RepoSlug extracts the "owner/name" identifier from a GitHub remote or PR URL. It supports https URLs, scp-style ssh URLs (git@github.com:owner/name.git), ssh:// URLs, and longer paths such as PR links (the leading two path segments are used). It returns "" when the input has no owner/name pair.

Types

type CmdFactory

type CmdFactory func(ctx context.Context, name string, args ...string) *exec.Cmd

CmdFactory builds an exec.Cmd in the caller's workdir with the caller's env.

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host talks to GitHub through the gh CLI.

func New

func New(cmd CmdFactory, cliAvailable func() bool, host, repo string) *Host

New builds a Host. cliAvailable reports whether the gh binary is resolvable on the caller's PATH (possibly overridden by env). host is the repo's GitHub hostname; when set the availability check is scoped to it via --hostname so a stale credential for an unrelated configured gh host cannot make this repo look unauthenticated. repo is the "owner/name" slug; when set it is passed via --repo to every PR/run command so they resolve the right repository regardless of the process working directory. The daemon runs from a fixed, non-repo working dir, so without this gh cannot infer the repo (or branch) and fails on every poll. host is optional; empty reproduces the legacy unscoped auth-check behavior.

func NewWithFork

func NewWithFork(cmd CmdFactory, cliAvailable func() bool, host, repo, forkRepo string) *Host

NewWithFork builds a Host that opens PRs on repo using forkRepo as the head repository owner. forkRepo is an "owner/name" slug; only the owner is needed because gh pr create expects --head <owner>:<branch>. host is optional; see New for its role in scoping the auth check.

func (*Host) Available

func (h *Host) Available(ctx context.Context) error

func (*Host) Capabilities

func (h *Host) Capabilities() scm.Capabilities

func (*Host) CreatePR

func (h *Host) CreatePR(ctx context.Context, branch, base string, content scm.PRContent) (*scm.PR, error)

func (*Host) FetchFailedCheckLogs

func (h *Host) FetchFailedCheckLogs(ctx context.Context, _ *scm.PR, branch, headSHA string, failingNames []string) (string, error)

func (*Host) FindAttestationPublicationIdentity

func (h *Host) FindAttestationPublicationIdentity(ctx context.Context, headSHA, publicationNonce string) (scm.CheckAttemptIdentity, bool, error)

func (*Host) FindPR

func (h *Host) FindPR(ctx context.Context, branch, base string) (*scm.PR, error)

func (*Host) GetCheckAttemptIdentity

func (h *Host) GetCheckAttemptIdentity(ctx context.Context, check scm.Check) (scm.CheckAttemptIdentity, error)

func (*Host) GetChecks

func (h *Host) GetChecks(ctx context.Context, pr *scm.PR) ([]scm.Check, error)

func (*Host) GetMergeableState

func (h *Host) GetMergeableState(ctx context.Context, pr *scm.PR) (scm.MergeableState, error)

func (*Host) GetPRState

func (h *Host) GetPRState(ctx context.Context, pr *scm.PR) (scm.PRState, error)

func (*Host) Provider

func (h *Host) Provider() scm.Provider

func (*Host) RerunCheck

func (h *Host) RerunCheck(ctx context.Context, _ *scm.PR, check scm.Check) error

RerunCheck re-runs the Actions job behind check for the same commit, so a check the provider cancelled rather than failed can be retried without a new push. The job is identified from the check's details link, which is the only run/job identity `gh pr checks` reports: a link naming a job re-runs just that job (and its dependencies), and a link naming only a run re-runs that run's failed jobs. Anything else - a third-party status pointing at an external dashboard, or a run path this backend cannot read - names no re-runnable job, and the error says so rather than falling back to a wider rerun.

func (*Host) UpdatePR

func (h *Host) UpdatePR(ctx context.Context, pr *scm.PR, content scm.PRContent) (*scm.PR, error)

Jump to

Keyboard shortcuts

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