configfile

package
v2.7.10 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package configfile provides a simple interface for reading and writing configuration file. The configuration file is stored in the user's GitHub CLI configuration under a dedicated section. The configuration file is encoded in YAML format.

Index

Constants

View Source
const AuthenticationFailed = "Authentication for %q failed. Make sure to configure GitHub CLI for %q."

Message, when authentication fails.

View Source
const ConfigInvalidFormat = "Invalid format %q. Supported formats are: [%s]."

Message, when unsupported format for config provided.

View Source
const ConfigNotFound = "No configuration found. Make sure to run 'init' to create initial configuration " +
	"or run 'import' to import configuration from stdin."

Message, when config not found.

View Source
const ConfigShouldNotExist = "Configuration already exists. " +
	"Please run 'update' if you want to update your settings. " +
	"Alternatively, run 'remove' if you want to setup from scratch once again."

Message, when config exists, although it should not.

View Source
const DefaultExportDestination = "stdout"

Default destination for export.

View Source
const DefaultImportSource = "stdin"

Default source for import.

View Source
const JSON = "json"

json format

View Source
const YAML = "yaml"

yaml format

Variables

This section is empty.

Functions

func ConfigurationExists

func ConfigurationExists() bool

Check if configuration exists within GitHub CLI config.

func GetHosts

func GetHosts() []string

Retrieve all configured hosts from GitHub CLI.

func GetListOfSupportedFormats

func GetListOfSupportedFormats(quote bool) (formats []string)

Get list of supported formats.

func GetRepositorySlugFromURL added in v2.7.1

func GetRepositorySlugFromURL(repo Repository) string

GetRepositorySlugFromURL extracts repository slug from URL.

func GetTokens

func GetTokens() map[string]string

Retrieve all authentication tokens for each host from GitHub CLI.

func Import

func Import(format, input string)

Import configuration from Stdin or local file.

func OpenLins added in v2.7.5

func OpenLins(links []string)

Open links in browser.

Types

type Configuration

type Configuration struct {
	BaseDirectory         string        `json:"baseDirectory" yaml:"baseDirectory"`
	AbsoluteDirectoryPath string        `json:"directoryPath" yaml:"directoryPath"`
	Profiles              Profiles      `json:"profiles,omitempty" yaml:"profiles,omitempty"`
	Concurrency           uint          `json:"concurrency" yaml:"concurrency"`
	SubDirectories        bool          `json:"subDirectories" yaml:"subDirectories"`
	SizeLimit             uint64        `json:"sizeLimit" yaml:"sizeLimit"`
	Timeout               time.Duration `json:"timeout" yaml:"timeout"`
	Excluded              []string      `json:"excluded,omitempty" yaml:"excluded,omitempty"`
	Included              []string      `json:"included,omitempty" yaml:"included,omitempty"`
	Total                 int64         `json:"total,omitempty" yaml:"total,omitempty"`
	Repositories          Repositories  `json:"repositories,omitempty" yaml:"repositories,omitempty"`
}

Configuration holds gr configuration data

func Load

func Load() *Configuration

Load configuration from GitHub CLI config.

func (*Configuration) AppendRepositories

func (conf *Configuration) AppendRepositories(user *resources.User, repos ...resources.Repository)

AppendRepositories appends multiple repositories to the configuration and sorts them alphabetically by Directory.

func (Configuration) AuthenticateURL

func (conf Configuration) AuthenticateURL(targetURL *string)

AuthenticateURL encodes username and token into URL. In the case, no matching token can be found for given URL, emit message and exit.

func (Configuration) Cleanup

func (conf Configuration) Cleanup()

Remove local repositories which are not enlisted.

func (*Configuration) Copy

func (conf *Configuration) Copy() *Configuration

Clone config.

func (Configuration) Display

func (conf Configuration) Display(format, output string, export bool, filters []string)

Display flushes config into Stdout. Supports multiple formats and partial emission (if !export).

func (*Configuration) Edit added in v2.6.9

func (conf *Configuration) Edit(format, editor string)

Edit configuration.

func (*Configuration) FilterRepositories

func (conf *Configuration) FilterRepositories(repositories *[]resources.Repository)

Filter repositories. Applied filters: included || !excluded || size below x || archived || disabled || !pullPermission || !pushPermission.

func (Configuration) GeneralizeURL

func (conf Configuration) GeneralizeURL(targetURL *string)

GeneralizeURL removes username and token from URL.

func (*Configuration) GetProgressbarDescriptionForVerb

func (conf *Configuration) GetProgressbarDescriptionForVerb(verb string, repo Repository) string

Produce progressbar description considering the length of the repository with the longest name.

func (Configuration) ListUntracked

func (conf Configuration) ListUntracked() (untracked []string)

List local repositories which are not enlisted any longer.

func (*Configuration) Overwrite added in v2.6.9

func (conf *Configuration) Overwrite(from *Configuration)

Overwrite config.

func (Configuration) Remove

func (conf Configuration) Remove(purge bool)

Remove config. If purge, remove all local repositories.

func (*Configuration) SanitizeDirectory

func (conf *Configuration) SanitizeDirectory()

Transform base directory into UNIx style path and set absolute directory path.

func (Configuration) Save

func (conf Configuration) Save()

Save configuration into GitHub CLI config.

type Profile

type Profile struct {
	Username string `json:"username" yaml:"username"`
	Fullname string `json:"fullname" yaml:"fullname"`
	Email    string `json:"email,omitempty" yaml:"email,omitempty"`
	Host     string `json:"host" yaml:"host"`
}

Profile holds the context of authenticated user profile.

func NewProfile

func NewProfile(user *resources.User, host string) *Profile

Create new profile for given GitHub user and host.

type Profiles

type Profiles []Profile

func (*Profiles) Append

func (p *Profiles) Append(profile *Profile)

Append profile (only if not present).

func (Profiles) Has

func (p Profiles) Has(profile Profile) bool

Check if profile is enlisted (Username and Host are considered to be unique).

func (Profiles) ToMap

func (p Profiles) ToMap() map[string]Profile

Map profiles to hosts: <host> => <Profile>.

type PullRequest added in v2.7.0

type PullRequest struct {
	Assignees  []string         `json:"assignee" yaml:"assignee"`
	Author     string           `json:"author" yaml:"author"`
	Base       string           `json:"base" yaml:"base"`
	ClosedAt   time.Time        `json:"closed_at" yaml:"closed_at"`
	Error      PullRequestError `json:"error" yaml:"error"`
	Head       string           `json:"head" yaml:"head"`
	Labels     []string         `json:"labels" yaml:"labels"`
	Number     int              `json:"number" yaml:"number"`
	Repository string           `json:"repository" yaml:"repository"`
	State      string           `json:"state" yaml:"state"`
	Title      string           `json:"title" yaml:"title"`
	URL        string           `json:"URL" yaml:"URL"`
}

PullRequest represents a GitHub pull request.

func PullRequestFromResponse added in v2.7.1

func PullRequestFromResponse(response resources.PullRequest) PullRequest

PullRequestFromResponse creates a PullRequest from a GitHub API response.

func (PullRequest) Status added in v2.7.1

func (prl PullRequest) Status() any

Status returns the status of the PullRequest.

type PullRequestError added in v2.7.1

type PullRequestError string

PullRequestError represents an error that occurred while processing a PullRequest.

func (PullRequestError) Error added in v2.7.1

func (err PullRequestError) Error() string

Error returns the error message.

type PullRequestList added in v2.7.0

type PullRequestList []PullRequest

PullRequestList is a list of PullRequest.

func (*PullRequestList) Append added in v2.7.0

func (prl *PullRequestList) Append(pr PullRequest)

Append appends a PullRequest to the PullRequestList if it is not already in the list.

func (PullRequestList) Browse added in v2.7.5

func (prl PullRequestList) Browse()

Browse allows to open the URLs of the PullRequests in the default browser.

func (PullRequestList) Has added in v2.7.0

func (prl PullRequestList) Has(pr PullRequest) bool

Has returns true if the PullRequestList contains the given PullRequest.

type Repositories

type Repositories []Repository

func (*Repositories) Append

func (r *Repositories) Append(repo Repository)

Append repository (only if not present).

func (Repositories) Has

func (r Repositories) Has(repo Repository) bool

Check if repo is enlisted (URL is considered to be unique).

func (Repositories) LongestName

func (r Repositories) LongestName() string

Get the name of the repository with the longest name.

type Repository

type Repository struct {
	URL       string `json:"URL" yaml:"URL"`
	Directory string `json:"directory" yaml:"directory"`
	Branch    string `json:"branch" yaml:"branch"`
	ParentURL string `json:"parentURL,omitempty" yaml:"parentURL,omitempty"`
	Public    bool   `json:"public,omitempty" yaml:"public,omitempty"`
	Size      string `json:"size" yaml:"size"`
}

Repository holds a repository URL and its local directory equivalent.

Jump to

Keyboard shortcuts

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