cmdutils

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

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 CancelError

func CancelError(log ...interface{}) 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, error)) (string, error)

func HTTPClientFactory

func HTTPClientFactory(f *Factory)

func IDsFromUsers

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

IDsFromUsers collects all user IDs from a slice of users

func LabClientFunc

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

func LabelsPrompt

func LabelsPrompt(response *[]string, apiClient *gitlab.Client, repoRemote *glrepo.Remote) (err 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/ee/user/project/description_templates.html#setting-a-default-template-for-issues-and-merge-requests.

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) (err error)

func MinimumArgs

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

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

func UsersPrompt added in v1.31.0

func UsersPrompt(response *[]string, apiClient *gitlab.Client, repoRemote *glrepo.Remote, io *iostreams.IOStreams, minimumAccessLevel int, role string) (err 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 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 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 GetTextUsingEditor added in v1.46.0

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