Documentation
¶
Overview ¶
Package fetch provides utilities for fetching GitHub repository metadata and computing checksums.
Index ¶
Constants ¶
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 ¶
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:
- Check if extracted directory exists and contains files. If so, return it.
- 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.
- 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.