cmdutils

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssueTemplate        = "issue_templates"
	MergeRequestTemplate = "merge_request_templates"
)

Variables

View Source
var GroupMemberLevel = map[int]string{
	0:  "no access",
	5:  "minimal access",
	10: "guest",
	20: "reporter",
	30: "developer",
	40: "maintainer",
	50: "owner",
}

GroupMemberLevel maps a number representing the access level to a string shown to the user. API docs: https://docs.gitlab.com/ce/api/members.html#valid-access-levels

View Source
var SilentError = errors.New("SilentError")

SilentError is an error that triggers exit Code 1 without any error messaging

Functions

func AddGlobalRepoOverride

func AddGlobalRepoOverride(cmd *cobra.Command, f Factory)

AddGlobalRepoOverride adds the -R flag globally but keeps it hidden

func CancelError

func CancelError(log ...any) error

func ConfirmTransfer

func ConfirmTransfer() error

func EditorPrompt

func EditorPrompt(response *string, question, templateContent, editorCommand string) error

func EnableRepoOverride

func EnableRepoOverride(cmd *cobra.Command, f Factory)

func GetEditor

func GetEditor(cf func() config.Config) (string, error)

func GroupOverride

func GroupOverride(cmd *cobra.Command) (string, error)

func IDsFromUsers

func IDsFromUsers(users []*gitlab.User) *[]int

IDsFromUsers collects all user IDs from a slice of users

func LabelsPrompt

func LabelsPrompt(response *[]string, apiClient *gitlab.Client, repoRemote *glrepo.Remote) error

func ListGitLabTemplates

func ListGitLabTemplates(tmplType string) ([]string, error)

TODO: properly handle errors in this function.

For now, it returns nil and empty slice if there's an error

func LoadGitLabTemplate

func LoadGitLabTemplate(tmplType, tmplName string) (string, error)

LoadGitLabTemplate finds and loads the GitLab template from the working git directory Follows the format officially supported by GitLab https://docs.gitlab.com/user/project/description_templates/#set-a-default-template-for-merge-requests-and-issues.

TODO: load from remote repository if repo is overridden by -R flag

func MilestonesPrompt

func MilestonesPrompt(response *int, apiClient *gitlab.Client, repoRemote *glrepo.Remote, io *iostreams.IOStreams) error

func MinimumArgs

func MinimumArgs(n int, msg string) cobra.PositionalArgs

func NewEnumValue added in v1.64.0

func NewEnumValue(allowed []string, d string, v *string) *enumValue

func ParseMilestone

func ParseMilestone(apiClient *gitlab.Client, repo glrepo.Interface, milestoneTitle string) (int, error)

func UsersPrompt

func UsersPrompt(response *[]string, apiClient *gitlab.Client, repoRemote *glrepo.Remote, io *iostreams.IOStreams, minimumAccessLevel int, role string) error

UsersPrompt creates a multi-selection prompt of all the users above the given access level for the remote referenced by the `*glrepo.Remote`.

`role` will appear on the prompt to keep the user informed of the reason of the selection.

Types

type Action

type Action int
const (
	NoAction Action = iota
	SubmitAction
	PreviewAction
	AddMetadataAction
	CancelAction
	EditCommitMessageAction
)
const (
	AddLabelAction Action = iota
	AddAssigneeAction
	AddMilestoneAction
)

func ConfirmSubmission

func ConfirmSubmission(allowPreview bool, allowAddMetadata bool) (Action, error)

func PickMetadata

func PickMetadata() ([]Action, error)

type DefaultFactory

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

func NewFactory

func NewFactory(io *iostreams.IOStreams, resolveRepos bool, cfg config.Config, buildInfo api.BuildInfo) *DefaultFactory

func (*DefaultFactory) ApiClient

func (f *DefaultFactory) ApiClient(repoHost string) (*api.Client, error)

func (*DefaultFactory) BaseRepo

func (f *DefaultFactory) BaseRepo() (glrepo.Interface, error)

func (*DefaultFactory) Branch

func (f *DefaultFactory) Branch() (string, error)

func (*DefaultFactory) BuildInfo

func (f *DefaultFactory) BuildInfo() api.BuildInfo

func (*DefaultFactory) Config

func (f *DefaultFactory) Config() config.Config

func (*DefaultFactory) DefaultHostname

func (f *DefaultFactory) DefaultHostname() string

func (*DefaultFactory) HttpClient

func (f *DefaultFactory) HttpClient() (*gitlab.Client, error)

func (*DefaultFactory) IO

func (*DefaultFactory) Remotes

func (f *DefaultFactory) Remotes() (glrepo.Remotes, error)

func (*DefaultFactory) RepoOverride

func (f *DefaultFactory) RepoOverride(repo string) error

type ExitError

type ExitError struct {
	Err     error
	Code    int
	Details string
}

func WrapError

func WrapError(err error, log string) *ExitError

func WrapErrorWithCode

func WrapErrorWithCode(err error, code int, details string) *ExitError

func (*ExitError) Error

func (e *ExitError) Error() string

func (ExitError) Unwrap

func (e ExitError) Unwrap() error

type Factory

type Factory interface {
	RepoOverride(repo string) error
	ApiClient(repoHost string) (*api.Client, error)
	// HttpClient returns an HTTP client that is initialize with the host from BaseRepo.
	// You must only use HttpClient if your command is tied to a single repository,
	// otherwise use ApiClient
	HttpClient() (*gitlab.Client, error)
	BaseRepo() (glrepo.Interface, error)
	Remotes() (glrepo.Remotes, error)
	Config() config.Config
	Branch() (string, error)
	IO() *iostreams.IOStreams
	DefaultHostname() string
	BuildInfo() api.BuildInfo
}

Factory is a way to obtain core tools for the commands. Safe for concurrent use.

type FlagError

type FlagError struct {
	Err error
}

FlagError is the kind of error raised in flag processing

func (FlagError) Error

func (fe FlagError) Error() string

func (FlagError) Unwrap

func (fe FlagError) Unwrap() error

type GetTextUsingEditor

type GetTextUsingEditor func(editor, tmpFileName, content string) (string, error)

type UserAssignmentType

type UserAssignmentType int
const (
	AssigneeAssignment UserAssignmentType = iota
	ReviewerAssignment
)

type UserAssignments

type UserAssignments struct {
	ToAdd          []string
	ToRemove       []string
	ToReplace      []string
	AssignmentType UserAssignmentType
}

UserAssignments holds 3 slice strings that represent which assignees should be added, removed, and replaced helper functions are also provided

func ParseAssignees

func ParseAssignees(assignees []string) *UserAssignments

ParseAssignees takes a String Slice and splits them into 3 Slice Strings based on the first character of a string.

'+' is put in the first slice, '!' and '-' in the second slice and all other cases in the third slice.

The 3 String slices are returned regardless if anything was put it in or not the user is responsible for checking the length to see if anything is in it

func (*UserAssignments) UsersFromAddRemove

func (ua *UserAssignments) UsersFromAddRemove(
	issueAssignees []*gitlab.IssueAssignee,
	mergeRequestAssignees []*gitlab.BasicUser,
	apiClient *gitlab.Client,
	actions []string,
) (*[]int, []string, error)

UsersFromAddRemove works with both `ToAdd` and `ToRemove` members to produce a Slice of Ints that represents the final collection of IDs to assigned.

It starts by getting all IDs already assigned, but ignoring ones present in `ToRemove`, it then converts all `usernames` in `ToAdd` into IDs by using the `api` package and adds them to the IDs to be assigned

func (*UserAssignments) UsersFromReplaces

func (ua *UserAssignments) UsersFromReplaces(apiClient *gitlab.Client, actions []string) (*[]int, []string, error)

UsersFromReplaces converts all users from the `ToReplace` member of the struct into an Slice of String representing the Users' IDs, it also takes a Slice of Strings and writes a proper action message to it

func (*UserAssignments) VerifyAssignees

func (ua *UserAssignments) VerifyAssignees() error

VerifyAssignees is a method for UserAssignments that checks them for validity

Jump to

Keyboard shortcuts

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