gitremote

package
v1.0.44630-pre Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gitremote resolves the CircleCI project slug for the current working directory. Resolution prefers the per-checkout .circleci/info.yml recorded by `circleci project link` (so repository renames and standalone projects stay addressable), falling back to parsing the git remote URL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectNamespace

func DetectNamespace() (string, error)

DetectNamespace returns the organization name (namespace) from the git remote. For a slug like "gh/myorg/myrepo" it returns "myorg".

func DetectRepoName

func DetectRepoName() string

DetectRepoName returns the repository name from the git remote, or "" if it cannot be detected.

func SlugFromRemote

func SlugFromRemote(remoteURL string) (string, error)

SlugFromRemote is exported for testing.

Types

type ProjectInfo

type ProjectInfo struct {
	// Slug is the CircleCI project slug, e.g. "gh/myorg/myrepo".
	Slug string
	// Branch is the current git branch name.
	Branch string
	// DefaultBranch is the default branch name.
	DefaultBranch string
	// OrgID is the organization ID recorded by `circleci project link`
	// (.circleci/info.yml). It is empty when the project was resolved from the
	// git remote, because the org ID is not derivable from a remote URL without
	// an API lookup. Its form is whatever link persisted (a UUID, or a compact
	// base62 ID); consumers that need a UUID must parse and fall back on failure.
	OrgID string
}

ProjectInfo holds the information needed to identify a CircleCI project.

func Detect

func Detect() (*ProjectInfo, error)

Detect resolves the CircleCI project for the current working directory.

Resolution priority:

  1. .circleci/info.yml in the working directory (written by `circleci project link`). When this file carries both project_id and organization_id, the canonical "circleci/<orgID>/<projectID>" slug is returned so lookups survive VCS-side renames; otherwise the file's stored slug is returned verbatim.
  2. The git remote "origin" URL.

The branch is always read from git (best-effort when info.yml supplied the slug, since the branch is per-checkout and never persisted in info.yml).

func DetectFromRemote

func DetectFromRemote() (*ProjectInfo, error)

DetectFromRemote resolves the project from the git "origin" remote without consulting .circleci/info.yml. Use this from the `project link` command itself — reading info.yml there would short-circuit the very write that link is about to perform.

Jump to

Keyboard shortcuts

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