gitlab_util

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApprovalRuleToString

func ApprovalRuleToString(rule *gitlab.ProjectApprovalRule) string

ApprovalRuleToString converts the approval rule into a human-readable string.

func FindExactGroup

func FindExactGroup(s *gitlab.GroupsService, group string) (*gitlab.Group, error)

FindExactGroup returns the ID of the group that exactly matches the search string.

func FindUsers

func FindUsers(
	s *gitlab.UsersService,
	user string,
	exact bool,
	date time.Time,
) ([]*gitlab.User, error)

FindUser search for the user and returns the user that exactly matches the search string or all substring matches if exact is false. The search string can be the user ID, name, username or e-mail address of the user. If the search string is a user ID, the exact flag is ignored, and only the exact user with that ID will be returned.

func ForEachApprovalRuleInProject

func ForEachApprovalRuleInProject(
	s ApprovalRulesGetter,
	p *gitlab.Project,
	f func(
		approvalRule *gitlab.ProjectApprovalRule,
	) (bool, error),
) error

ForEachApprovalRuleInProject iterates over the approval rules in a project and calls the function f once for each approval rule. The function f must return true and no error to indicate that it wants to continue being called with the remaining projects. If f returns an error, it will be forwarded to the caller as the error return value for this function.

func ForEachProjectInGroup

func ForEachProjectInGroup(
	s *gitlab.GroupsService,
	group string,
	expr string,
	recursive bool,
	f func(group *gitlab.Group, project *gitlab.Project) (bool, error),
) error

ForEachProjectInGroup iterates over the projects in a group and recursively or not) calls the function f once for each project whose full path name matches the regular expression. An empty regular expression matches any string. The function f must return true and no error to indicate that it wants to continue being called with the remaining projects. If f returns an error, it will be forwarded to the caller as the error return value for this function. Prefer this function over GetAllProjects() to avoid the long delay to the user while waiting to collect all the projects.

func ForEachUser

func ForEachUser(
	s *gitlab.UsersService,
	user string,
	date time.Time,
	f func(user *gitlab.User) (bool, error),
) error

ForEachUser iterates over users calling the function f once for each user matching the search string. An empty search string matches all users. The search string can be the name, username, or e-mail address of the user. The function f must return true and no error to indicate that it wants to continue being called with the remaining users. If f returns an error, it will be forwarded to the caller as the error return value for this function.

Also see [FindExactUser()].

func GetAllProjects

func GetAllProjects(
	s *gitlab.GroupsService,
	group string,
	expr string,
	recursive bool,
) ([]*gitlab.Project, error)

GetAllProjects returns all the projects in a group recursively (or not) for each project whose full path name matches the regular expression. An empty regular expression matches any string. Prefer ForEachProjectInGroup() over this function to avoid the long delay while waiting to collect all the projects. The main reason to use this function is when deleting projects because Gitlab's paging gets confused because Gitlab's paging is relative to when you make the request for the next page, not when you made the request for the first page, and deleting projects necessarily changes the page on which some remaining projects appear. This function is better to use when deleting projects because it collects all the projects up front allowing the caller to delete them with impunity because there will be no next page to get.

func GetApprovalRuleUsernames

func GetApprovalRuleUsernames(rule *gitlab.ProjectApprovalRule) []string

GetApprovalRuleUsernames returns the sorted list of usernames for the given approval rule.

func GroupFullPaths

func GroupFullPaths(groups []*gitlab.Group) []string

GroupFullPaths returns just the full paths for the groups.

func UpdateApprovalRule

func UpdateApprovalRule(
	s *gitlab.ProjectsService,
	projectID int,
	rule *gitlab.ProjectApprovalRule,
	userIDs []int,
) (
	*gitlab.ProjectApprovalRule,
	error,
)

UpdateApprovalRule updates the approval rule for the project to have the same values as before except with a new list of user IDs. This function is designed to be the callback for [ForEachApprovalRuleInProject()].

Types

type ApprovalRulesGetter

type ApprovalRulesGetter interface {
	GetProjectApprovalRules(
		pid interface{},
		opt *gitlab.GetProjectApprovalRulesListsOptions,
		options ...gitlab.RequestOptionFunc,
	) ([]*gitlab.ProjectApprovalRule, *gitlab.Response, error)
}

ApprovalRulesGetter is an abstraction of GetProjectApprovalRules() in gitlab.ProjectsService which was added so ForEachApprovalRuleInProject() can be tested with requiring a paid Gitlab account because Gitlab CE (the free version of Gitlab) does not support approval rules.

Jump to

Keyboard shortcuts

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