Documentation
¶
Overview ¶
Package github provides functionality to interact with GitHub repositories, releases, and assets via the GitHub API. It includes utilities for filtering and retrieving release information, assets, and repository metadata.
The main types and functions in this package include:
- Asset: Represents a GitHub release asset with name, URL, and content type.
- Assets: A collection of Asset objects with filtering methods.
- Release: Represents a GitHub release containing a tag, name, and assets.
- Repository: Represents a GitHub repository, with methods for retrieving releases, assets, and repository details.
- NewClient: Creates a new GitHub API client.
- NewRepository: Creates a new Repository instance for accessing repository data.
This package uses the Google GitHub client (github.com/google/go-github/v64) for making API calls and provides additional utilities to handle GitHub data.
Index ¶
- Variables
- func NewClient(token string) *github.Client
- type Asset
- type Assets
- type ExportConfig
- type Release
- type Repository
- func (g *Repository) Export(release *Release, config ExportConfig) error
- func (g *Repository) ExportWithDefaults(release *Release) error
- func (g *Repository) GetRelease(tag string) (*Release, error)
- func (g *Repository) Languages() ([]string, error)
- func (g *Repository) LatestRelease() (*Release, error)
- func (g *Repository) LatestReleaseFromExport(config ExportConfig) (*Release, error)
- func (g *Repository) LatestReleaseFromExportWithDefaults() (*Release, error)
- func (g *Repository) WithContext(ctx context.Context) *Repository
Constants ¶
This section is empty.
Variables ¶
var ErrExporter = errors.New("exporter error")
ErrExporter is an error returned when an exporter operation fails.
var ErrRelease = errors.New("release")
ErrRelease is returned when a release issue is encountered.
Functions ¶
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
URL string `json:"browser_download_url"` //nolint:tagliatelle
Type string `json:"content_type"` //nolint:tagliatelle
}
Asset represents a GitHub release asset with its name, download URL, and content type.
func (Asset) HasExtension ¶
HasExtension checks if the asset has the given file extension.
type Assets ¶
type Assets []Asset
Assets represents a collection of GitHub release assets.
func (Assets) FilterByName ¶
FilterByName returns the assets that match the given name. It compares asset names in a case-insensitive manner.
type ExportConfig ¶ added in v0.0.1
type ExportConfig struct {
ExportPath string // Path to export data to
ImportPath string // Path to import data from
}
ExportConfig holds configuration for exporting GitHub data.
func DefaultExportConfig ¶ added in v0.0.1
func DefaultExportConfig() ExportConfig
DefaultExportConfig returns the default export configuration.
type Release ¶
type Release struct {
// Name is the name of the release.
Name string `json:"name"`
// Tag is the tag associated with the release (e.g., version number).
Tag string `json:"tag_name"` //nolint:tagliatelle
// Assets is a collection of assets attached to the release.
Assets Assets `json:"assets"`
}
Release represents a GitHub release, containing the release name, tag, and associated assets.
func (*Release) FromRepositoryRelease ¶
func (r *Release) FromRepositoryRelease(release *github.RepositoryRelease) error
FromRepositoryRelease converts a GitHub repository release to a Release object.
type Repository ¶
type Repository struct {
Owner string // Owner is the owner of the repository (GitHub username or organization).
Repo string // Repo is the name of the repository.
// contains filtered or unexported fields
}
Repository represents a GitHub repository with its owner and name. It contains a GitHub client and context for making API calls.
func NewRepository ¶
func NewRepository(owner, repo string, client *github.Client) *Repository
NewRepository creates a new instance of Repository. It requires the repository owner, repository name, and a GitHub client.
func (*Repository) Export ¶
func (g *Repository) Export(release *Release, config ExportConfig) error
Export retrieves the latest release for the repository and stores its assets in a JSON file.
func (*Repository) ExportWithDefaults ¶ added in v0.0.1
func (g *Repository) ExportWithDefaults(release *Release) error
ExportWithDefaults exports the release with default configuration.
func (*Repository) GetRelease ¶
func (g *Repository) GetRelease(tag string) (*Release, error)
GetRelease retrieves a specific release for the repository based on the provided tag.
func (*Repository) Languages ¶
func (g *Repository) Languages() ([]string, error)
Languages retrieves the programming languages used in the repository, sorted by usage in descending order.
func (*Repository) LatestRelease ¶
func (g *Repository) LatestRelease() (*Release, error)
LatestRelease retrieves the latest release for the repository.
func (*Repository) LatestReleaseFromExport ¶
func (g *Repository) LatestReleaseFromExport(config ExportConfig) (*Release, error)
LatestReleaseFromExport retrieves the latest release information from the exported JSON file.
func (*Repository) LatestReleaseFromExportWithDefaults ¶ added in v0.0.1
func (g *Repository) LatestReleaseFromExportWithDefaults() (*Release, error)
LatestReleaseFromExportWithDefaults retrieves the latest release with default configuration.
func (*Repository) WithContext ¶ added in v0.0.1
func (g *Repository) WithContext(ctx context.Context) *Repository
WithContext returns a copy of the repository with the given context.