gitlab

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gitlab provides functionality to interact with GitLab repositories, releases, and assets via the GitLab 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 GitLab release asset with name, URL, and content type.
  • Assets: A collection of Asset objects with filtering methods.
  • Release: Represents a GitLab release containing a tag, name, and assets.
  • Repository: Represents a GitLab repository, with methods for retrieving releases, assets, and repository details.
  • NewClient: Creates a new GitLab API client.
  • NewRepository: Creates a new Repository instance for accessing repository data.

This package uses the official GitLab client (gitlab.com/gitlab-org/api/client-go) for making API calls and provides additional utilities to handle GitLab data.

Index

Constants

This section is empty.

Variables

View Source
var ErrRelease = errors.New("release")

ErrRelease is returned when a release issue is encountered.

Functions

func NewClient

func NewClient(token, baseURL string) (*gitlab.Client, error)

NewClient creates a new GitLab client. If a token is provided, the client is authenticated using the token. If baseURL is provided, the client will connect to that GitLab instance instead of gitlab.com.

Types

type Asset

type Asset struct {
	// Name is the name of the asset.
	Name string `json:"name"`
	// URL is the browser download URL for the asset.
	URL string `json:"url"`
	// Type is the content type of the asset.
	Type string `json:"content_type"` //nolint:tagliatelle // GitLab API uses snake_case field names
}

Asset represents a GitLab release asset with its name, download URL, and content type.

func (Asset) HasExtension

func (a Asset) HasExtension(extension string) (bool, error)

HasExtension checks if the asset has the given file extension.

func (Asset) Match

func (a Asset) Match(pattern string) (bool, error)

Match checks if the asset name matches the given pattern.

type Assets

type Assets []Asset

Assets represents a collection of GitLab release assets.

func (Assets) FilterByName

func (as Assets) FilterByName(name string) (assets Assets)

FilterByName returns the assets that match the given name. It compares asset names in a case-insensitive manner.

func (Assets) Match

func (as Assets) Match(requirements match.Requirements) (matches match.Results)

Match checks if the assets match the given requirements. It processes each asset to extract platform and extension information.

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 // GitLab API uses snake_case field names
	// Assets is a collection of assets attached to the release.
	Assets Assets `json:"assets"`
}

Release represents a GitLab release, containing the release name, tag, and associated assets.

func (*Release) FromRepositoryRelease

func (r *Release) FromRepositoryRelease(release *gitlab.Release) error

FromRepositoryRelease converts a GitLab repository release to a Release object.

type Repository

type Repository struct {
	Namespace string
	Repo      string
	// contains filtered or unexported fields
}

Repository represents a GitLab repository with its owner and name. It contains a GitLab client for making API calls.

func NewRepository

func NewRepository(namespace, repo string, client *gitlab.Client) *Repository

NewRepository creates a new instance of Repository. It requires the repository owner, repository name, and a GitLab client.

func (*Repository) GetLatestIncludingPreRelease

func (g *Repository) GetLatestIncludingPreRelease(ctx context.Context, perPage int) (*Release, error)

GetLatestIncludingPreRelease retrieves the most recently published release for the repository, including pre-releases. This returns the newest release by published date, regardless of whether it's a regular release or pre-release.

func (*Repository) GetRelease

func (g *Repository) GetRelease(_ context.Context, tag string) (*Release, error)

GetRelease retrieves a specific release for the repository based on the provided tag.

func (*Repository) LatestRelease

func (g *Repository) LatestRelease(ctx context.Context) (*Release, error)

LatestRelease retrieves the latest release for the repository.

Jump to

Keyboard shortcuts

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