githubrelease

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 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 githubrelease is the "github-release" Source: it lists the releases of a GitHub (or GitHub Enterprise) repository.

Target coordinates: {"repo": "owner/name"}. A repository that was renamed is still served through GitHub's 301 redirect, which is followed, but the stored coordinate goes stale until it is edited.

Requests and rate limit

List calls GET {base}/repos/{owner}/{repo}/releases?per_page=100. The ETag of the first page is kept in FetchState.ETag and sent as If-None-Match. A 304 to an authenticated request does not count against GitHub's rate limit (authenticated 304s are free; anonymous ones are charged), which is what lets one token watch thousands of repositories. Later pages are fetched without validators.

Pagination and known versions

FetchState.Cursor is JSON {"max_id":N,"full_at":unix}: the highest release id seen and the time of the last full scan (a bare decimal number from an earlier format is read as max_id). Release ids only grow, so a page whose releases all have an id at or below max_id holds nothing new and pagination stops after it. The first page is always returned in full.

GitHub sorts releases by created_at, which is the date of the tagged commit, so a release created later for an old tag can sit below a page that looks known. List therefore ignores the cursor and the ETag and walks every page (at most maxPages, 10 requests) when the last full scan is 24 hours old or missing.

Tokens

The token is read at request time from WithToken or WithTokenEnv; a configured but empty token is an error, not an anonymous request. It is sent only as an Authorization header, and only over https (or to a loopback host). It is held in a redacting type and never appears in an error or a log. The injected client is wrapped so that a redirect carrying the token to another host (including another port or a subdomain) or to plain http fails instead of being followed.

Index

Constants

View Source
const DefaultBaseURL = ghapi.DefaultBaseURL

DefaultBaseURL is the GitHub.com API. For GitHub Enterprise use "https://HOST/api/v3".

View Source
const Kind = "github-release"

Kind is the registry key of this source.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Source)

Option configures a Source.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the clock used for the periodic full rescan.

func WithPageSize

func WithPageSize(n int) Option

WithPageSize overrides the page size (default 100, GitHub's maximum).

func WithToken

func WithToken(token string) Option

WithToken sets a fixed API token. A blank token makes List fail.

func WithTokenEnv

func WithTokenEnv(name string) Option

WithTokenEnv reads the token from the environment variable name on every List call (so a rotated token is picked up). If the variable is unset, empty or blank, List fails rather than silently falling back to the 60 requests per hour anonymous limit.

type Source

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

Source implements source.Source for GitHub releases. It is safe for concurrent use.

func New

func New(baseURL string, hc *http.Client, opts ...Option) *Source

New returns a Source that sends requests to baseURL (DefaultBaseURL if empty) with hc, normally the netguard client. hc must not be nil. An invalid baseURL, or a token with a plain-http non-loopback base URL, does not panic: List returns the error.

New works on a shallow copy of hc whose CheckRedirect refuses to follow a redirect that would carry the token to another host or to plain http (net/http only compares host names, so it would keep the header across ports and subdomains).

func (*Source) Kind

func (*Source) Kind() string

Kind implements source.Source.

func (*Source) List

List implements source.Source.

func (*Source) Validate

func (*Source) Validate(t source.Target) error

Validate implements source.Source. It does no I/O.

Jump to

Keyboard shortcuts

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