fetch

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fetch provides utilities for fetching GitHub repository metadata and computing checksums.

Index

Constants

View Source
const (
	// DefaultBranchMaster represents the default git branch "master".
	DefaultBranchMaster = "master"
)

Variables

This section is empty.

Functions

func LatestCommitAndChecksum added in v0.8.0

func LatestCommitAndChecksum(endpoints *Endpoints, repo *RepoRef) (commit, sha256 string, err error)

LatestCommitAndChecksum fetches the latest commit SHA and the SHA256 of the tarball for that commit from the GitHub API for the given repository.

func Repo

func Repo(ctx context.Context, repo, commit, expectedSHA256 string) (string, error)

Repo downloads a repository tarball and returns the path to the extracted directory.

The cache directory is determined by LIBRARIAN_CACHE environment variable, or defaults to $HOME/.cache/librarian if not set.

The diagrams below explains the structure of the librarian cache. For each path, $repo is a repository path (i.e. github.com/googleapis/googleapis), and $commit is a commit hash in that repository.

Cache structure:

$LIBRARIAN_CACHE/
├── download/                    # Downloaded artifacts
│   └── $repo@$commit.tar.gz     # Source tarball (kept for re-extraction)
└── $repo@$commit/               # Extracted source files
    └── {files...}

Example for github.com/googleapis/googleapis at commit abc123:

$HOME/.cache/librarian/
├── download/
│   └── github.com/googleapis/googleapis@abc123.tar.gz
└── github.com/googleapis/googleapis@abc123/
    └── google/
        └── api/
            └── annotations.proto

Cache lookup order:

  1. Check if extracted directory exists and contains files. If so, return it.
  2. Check if tarball exists. Verify its SHA256 matches expectedSHA256. If yes, extract tarball and return the directory. If the hash mismatches, fall through to step 3.
  3. Download tarball, compute SHA256, verify it matches expectedSHA256 from librarian.yaml, extract, and return the path.

Types

type Endpoints

type Endpoints struct {
	// API defines the endpoint used to make API calls.
	API string

	// Download defines the endpoint to download tarballs.
	Download string
}

Endpoints defines the endpoints used to access GitHub.

type RepoRef added in v0.9.1

type RepoRef struct {
	// Branch is the name of the repository branch, such as `master` or `preview`.
	Branch string

	// Org defines the GitHub organization (or user), that owns the repository.
	Org string

	// Name is the name of the repository, such as `googleapis` or `google-cloud-rust`.
	Name string
}

RepoRef represents a GitHub repository name.

Jump to

Keyboard shortcuts

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