cmdutils

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 22 Imported by: 1

Documentation

Overview

Forked from https://github.com/cli/cli/blob/929e082c13909044e2585af292ae952c9ca6f25c/pkg/cmd/factory/default.go

Index

Constants

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

Variables

View Source
var (
	CachedConfig config.Config
	ConfigError  error
)
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 AssigneesPrompt added in v1.14.0

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

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

func CancelError added in v1.18.0

func CancelError(log ...interface{}) error

func EditorPrompt added in v1.17.0

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

func EnableRepoOverride

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

func GetEditor added in v1.12.0

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

func HTTPClientFactory

func HTTPClientFactory(f *Factory)

func IDsFromUsers added in v1.13.0

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

IDsFromUsers collects all user IDs from a slice of users

func LabClientFunc added in v1.12.0

func LabClientFunc(repoHost string, cfg config.Config, isGraphQL bool) (*gitlab.Client, error)

func LabelsPrompt added in v1.12.0

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

func ListGitLabTemplates added in v1.12.0

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 added in v1.12.0

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/ee/user/project/description_templates.html#setting-a-default-template-for-issues-and-merge-requests.

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

func MilestonesPrompt added in v1.14.0

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

func MinimumArgs added in v1.18.0

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

func OverrideAPIProtocol

func OverrideAPIProtocol(cfg config.Config, repo glrepo.Interface)

OverrideAPIProtocol sets api protocol for host to initialize http client

func ParseMilestone added in v1.14.0

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

Types

type Action added in v1.13.0

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

func ConfirmSubmission added in v1.13.0

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

func PickMetadata added in v1.14.0

func PickMetadata() ([]Action, error)

type ExitError added in v1.18.0

type ExitError struct {
	Err     error
	Code    int
	Details string
}

func WrapError added in v1.18.0

func WrapError(err error, log string) *ExitError

func WrapErrorWithCode added in v1.18.0

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

func (*ExitError) Error added in v1.18.0

func (e *ExitError) Error() string

func (ExitError) Unwrap added in v1.18.0

func (e ExitError) Unwrap() error

type Factory

type Factory struct {
	HttpClient func() (*gitlab.Client, error)
	BaseRepo   func() (glrepo.Interface, error)
	Remotes    func() (glrepo.Remotes, error)
	Config     func() (config.Config, error)
	Branch     func() (string, error)
	IO         *iostreams.IOStreams
}

func NewFactory

func NewFactory() *Factory

func (*Factory) RepoOverride

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

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 UserAssignmentType added in v1.17.0

type UserAssignmentType int
const (
	AssigneeAssignment UserAssignmentType = iota
	ReviewerAssignment
)

type UserAssignments added in v1.14.0

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 added in v1.14.0

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 added in v1.14.0

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 added in v1.14.0

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 added in v1.14.0

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