glen

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package glen provides an API to get GitLab project and group variables

Glen has a VERY simple API with two structs that combined can get GitLab environment variables from a local repo with a GitLab remote.

Repo

The Repo struct holds information about a local repo and can be passed to a Variables struct. By default Repo assumes that your current working directory has a remote named 'origin'. However, you can specify custom directtories and custom origin names.

Variables

The Variables struct holds information about a GitLab project's CI/CD variables. By default Variables collects a project's variables using your GITLAB_TOKEN environment variable API key. However, you can set a custom API key and you can set Variables.Recurse=true to also collect the group variables of the project's parent groups. Variables are merged according to the GitLab specified precedence here: https://docs.gitlab.com/ee/ci/variables/#priority-of-environment-variables

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo struct {
	LocalPath  string
	RemoteName string

	Path      string
	BaseURL   string
	HTTPURL   string
	RemoteURL string

	Groups []string
}

Repo represents information about a git repo. Repo does not represent ALL information about a repo, only the information needed for this package (for gathering GitLab variables).

func NewRepo

func NewRepo() *Repo

NewRepo creates a new repo struct with defaults that assume you have a remote named 'origin' and that you are calling this function while your current directory is the repo you're interested in. If you have a custom local path or your remote is not named 'origin' then make sure you set those before you Init() the repo.

func (*Repo) Init

func (r *Repo) Init() error

Init gathers information about the repo struct, populating all required fields.

type Variables

type Variables struct {
	Env       map[string]string
	GroupOnly bool
	Recurse   bool
	Repo      *Repo
	// contains filtered or unexported fields
}

Variables represents a set of CI/CD environment variables and the repo that those variables were collected from.

func NewVariables

func NewVariables(r *Repo) *Variables

NewVariables takes a *Repo and returns an empty Variables struct. This assumes that you have a GitLab API key set as GITLAB_TOKEN. If not, make sure you set one with Variables.SetAPIKey(). Note that by default we do not 'recurse' and get the group variables. If you want group variables merged in make sure you set Variables.Recurse=true.

func (*Variables) Init

func (v *Variables) Init() error

Init collects GitLab variables from the repo, and optionally from the parent groups if Variables.Recurse=true. Variable precedence respects https://docs.gitlab.com/ee/ci/variables/#priority-of-environment-variables

func (*Variables) IsAPIKeySet added in v1.8.0

func (v *Variables) IsAPIKeySet() bool

IsAPIKeySet checks if apiKey is set to a non-empty value.

func (*Variables) SetAPIKey

func (v *Variables) SetAPIKey(key string)

SetAPIKey takes a GitLab API key and adds it to the Variables struct. Note that if you used NewVariables() to create your struct and you had GITLAB_TOKEN exported then that token is already set and you don't need to call this function.

Jump to

Keyboard shortcuts

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