client

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("403 Forbidden")
View Source
var ErrNotFound = errors.New("404 Not Found")

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present.

func IsEmailTakenConflict added in v0.3.1

func IsEmailTakenConflict(err error) bool

IsEmailTakenConflict reports whether err is GitLab's 409 response for a create-user request whose email already belongs to an existing user.

func PathEscape

func PathEscape(s string) string

func WithOffsetPagination

func WithOffsetPagination(url *url.URL, nextPageToken string)

func WithSearch

func WithSearch(url *url.URL, search string)

Types

type APIError added in v0.3.1

type APIError struct {
	StatusCode int
	// contains filtered or unexported fields
}

APIError is returned for a request that got an HTTP error response. It keeps the status and the GitLab error body so callers can classify specific provider errors without parsing the formatted error text. Error and Unwrap are unchanged from the plain wrapped error, so status.Code still works.

func (*APIError) Error added in v0.3.1

func (e *APIError) Error() string

func (*APIError) Unwrap added in v0.3.1

func (e *APIError) Unwrap() error

type AccessLevelValue

type AccessLevelValue int
const (
	NoPermissions            AccessLevelValue = 0
	MinimalAccessPermissions AccessLevelValue = 5
	GuestPermissions         AccessLevelValue = 10
	ReporterPermissions      AccessLevelValue = 20
	DeveloperPermissions     AccessLevelValue = 30
	MaintainerPermissions    AccessLevelValue = 40
	OwnerPermissions         AccessLevelValue = 50
	AdminPermissions         AccessLevelValue = 60
)

func GetAccessLevelByName

func GetAccessLevelByName(name string) (AccessLevelValue, bool)

func (AccessLevelValue) String

func (a AccessLevelValue) String() string

type AddGroupMemberRequest

type AddGroupMemberRequest struct {
	UserID      int              `json:"user_id"`
	AccessLevel AccessLevelValue `json:"access_level"`
}

type AddProjectMemberRequest

type AddProjectMemberRequest struct {
	UserID      int              `json:"user_id"`
	AccessLevel AccessLevelValue `json:"access_level"`
}

type CreateUserOptions

type CreateUserOptions struct {
	Email               *string `url:"email,omitempty" json:"email,omitempty"`
	ForceRandomPassword *bool   `url:"force_random_password,omitempty" json:"force_random_password,omitempty"`
	GroupIDForSAML      *string `url:"group_id_for_saml,omitempty" json:"group_id_for_saml,omitempty"`
	Name                *string `url:"name,omitempty" json:"name,omitempty"`
	Password            *string `url:"password,omitempty" json:"password,omitempty"`
	Username            *string `url:"username,omitempty" json:"username,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Body     []byte
	Response *http.Response
	Message  string
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type GitlabClient

type GitlabClient struct {
	AccountCreationGroup string
	IsOnPremise          bool

	SyncDirectMembersOnly bool
	SyncAccessPaths       bool
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, accessToken, baseURL, accountCreationGroup string, syncDirectMembersOnly, syncAccessPaths bool) (*GitlabClient, error)

func (*GitlabClient) AddGroupMember

func (c *GitlabClient) AddGroupMember(ctx context.Context, groupID string, memberRequest *AddGroupMemberRequest) (*GroupMember, *v2.RateLimitDescription, error)

AddGroupMember adds a member to a group.

func (*GitlabClient) AddProjectMember

func (c *GitlabClient) AddProjectMember(ctx context.Context, projectID string, memberRequest *AddProjectMemberRequest) (*ProjectMember, *v2.RateLimitDescription, error)

AddProjectMember adds a member to a project.

func (*GitlabClient) CreateUser

func (c *GitlabClient) CreateUser(ctx context.Context, userRequest *CreateUserOptions) (*User, *v2.RateLimitDescription, error)

CreateUser creates a new user in GitLab.

func (*GitlabClient) DeleteUser

func (c *GitlabClient) DeleteUser(ctx context.Context, userID string) (*v2.RateLimitDescription, error)

DeleteUser deletes a user from GitLab.

func (*GitlabClient) FindGroupByName

func (c *GitlabClient) FindGroupByName(ctx context.Context, groupName string) (*Group, *v2.RateLimitDescription, error)

FindGroupByName searches for groups across all pages and then filters for an exact match.

func (*GitlabClient) GetCurrentlyAuthenticatedUser added in v0.0.26

func (c *GitlabClient) GetCurrentlyAuthenticatedUser(ctx context.Context) (*User, *v2.RateLimitDescription, error)

func (*GitlabClient) GetGroup

func (c *GitlabClient) GetGroup(ctx context.Context, groupID string) (*Group, *v2.RateLimitDescription, error)

GetGroup retrieves a specific group by ID.

func (*GitlabClient) GetGroupMemberAll added in v0.0.33

func (c *GitlabClient) GetGroupMemberAll(ctx context.Context, groupID, userID string) (*GroupMember, *v2.RateLimitDescription, error)

GetGroupMemberAll retrieves a single member of a group including inherited and invited (shared) members (GET /groups/:id/members/all/:user_id). Returns a gRPC NotFound status (not the ErrNotFound sentinel — doRequest surfaces uhttp's 4xx error before CheckResponse runs) when the user has no effective access to the group. Used to tell a direct membership apart from inherited/invited access on revoke.

func (*GitlabClient) GetProject

func (c *GitlabClient) GetProject(ctx context.Context, projectID string) (*Project, *v2.RateLimitDescription, error)

GetProject retrieves a specific project by ID.

func (*GitlabClient) GetProjectMemberAll added in v0.0.33

func (c *GitlabClient) GetProjectMemberAll(ctx context.Context, projectID, userID string) (*ProjectMember, *v2.RateLimitDescription, error)

GetProjectMemberAll retrieves a single member of a project including inherited and invited (shared) members (GET /projects/:id/members/all/:user_id). Returns a gRPC NotFound status (not the ErrNotFound sentinel — doRequest surfaces uhttp's 4xx error before CheckResponse runs) when the user has no effective access to the project. Used to tell a direct membership apart from inherited/invited access on revoke.

func (*GitlabClient) InviteGroupMember

func (c *GitlabClient) InviteGroupMember(ctx context.Context, groupID string, userEmail string, accessLevel AccessLevelValue) (*v2.RateLimitDescription, error)

InviteGroupMember invites a member to a group.

func (*GitlabClient) ListAllGroupMembers added in v0.0.26

func (c *GitlabClient) ListAllGroupMembers(ctx context.Context, groupID string, nextPageToken string) ([]*GroupMember, string, *v2.RateLimitDescription, error)

ListAllGroupMembers retrieves members and pending invites of a specific group including inherited members through ancestor groups.

func (*GitlabClient) ListAllProjectMembers added in v0.0.29

func (c *GitlabClient) ListAllProjectMembers(ctx context.Context, projectID string, nextPageToken string) ([]*ProjectMember, string, *v2.RateLimitDescription, error)

func (*GitlabClient) ListGroupMembers

func (c *GitlabClient) ListGroupMembers(ctx context.Context, groupID string, nextPageToken string) ([]*GroupMember, string, *v2.RateLimitDescription, error)

ListGroupMembers retrieves members of a specific group.

func (*GitlabClient) ListGroups

func (c *GitlabClient) ListGroups(ctx context.Context, nextLink string) ([]*Group, string, *v2.RateLimitDescription, error)

ListGroups retrieves all groups from GitLab API using keyset pagination.

func (*GitlabClient) ListPendingGroupInvitations

func (c *GitlabClient) ListPendingGroupInvitations(ctx context.Context, groupID string, nextPageToken string) ([]*PendingInviteUser, string, *v2.RateLimitDescription, error)

ListPendingGroupInvitations lists pending invitations for a group.

func (*GitlabClient) ListProjectMembers

func (c *GitlabClient) ListProjectMembers(ctx context.Context, projectID string, nextPageToken string) ([]*ProjectMember, string, *v2.RateLimitDescription, error)

ListProjectMembers retrieves members of a specific project.

func (*GitlabClient) ListProjects

func (c *GitlabClient) ListProjects(ctx context.Context, groupID string, nextLink string) ([]*Project, string, *v2.RateLimitDescription, error)

ListProjects retrieves all projects from GitLab API.

func (*GitlabClient) ListUsers

func (c *GitlabClient) ListUsers(ctx context.Context, nextLink string) ([]*User, string, *v2.RateLimitDescription, error)

ListUsers retrieves all users from GitLab API.

func (*GitlabClient) RemoveGroupMember

func (c *GitlabClient) RemoveGroupMember(ctx context.Context, groupID, userID string) (*v2.RateLimitDescription, error)

RemoveGroupMember removes a member from a group.

func (*GitlabClient) RemoveProjectMember

func (c *GitlabClient) RemoveProjectMember(ctx context.Context, projectID, userID string) (*v2.RateLimitDescription, error)

RemoveProjectMember removes a member from a project.

func (*GitlabClient) SearchGroups

func (c *GitlabClient) SearchGroups(ctx context.Context, search string, nextPageToken string) ([]*Group, string, *v2.RateLimitDescription, error)

SearchGroups searches for groups by name.

func (*GitlabClient) SearchUsers added in v0.3.1

func (c *GitlabClient) SearchUsers(ctx context.Context, search string, nextPageToken string) ([]*User, string, *v2.RateLimitDescription, error)

SearchUsers lists users matching search (GET /users?search=), one page at a time. For administrators GitLab also matches exact primary and secondary emails, so callers must verify the returned email themselves.

type GitlabError added in v0.0.25

type GitlabError struct {
	Detail json.RawMessage `json:"message"`
}

GitlabError is the body of a GitLab error response. Its "message" is a string for most errors and an object of field errors for validation failures, such as {"access_level":["should be greater than or equal to ..."]}.

func (*GitlabError) Message added in v0.0.25

func (e *GitlabError) Message() string

Message implements the uhttp.ErrorResponse interface.

type Group

type Group struct {
	ID                int           `json:"id"`
	Name              string        `json:"name"`
	Description       string        `json:"description"`
	FullName          string        `json:"full_name"`
	ParentID          int           `json:"parent_id"`
	Archived          bool          `json:"archived"`
	Visibility        string        `json:"visibility"`
	MarkedForDeletion *ISOTime      `json:"marked_for_deletion"`
	SharedWithGroups  []SharedGroup `json:"shared_with_groups"`
}

type GroupMember

type GroupMember struct {
	ID                int           `json:"id"`
	Email             string        `json:"email"`
	Username          string        `json:"username"`
	Name              string        `json:"name"`
	State             string        `json:"state"`
	AccessLevel       int           `json:"access_level"`
	GroupSAMLIdentity *SAMLIdentity `json:"group_saml_identity"`
	MembershipState   string        `json:"membership_state"`
	Locked            bool          `json:"locked"`
}

type ISOTime

type ISOTime time.Time

func (*ISOTime) EncodeValues

func (t *ISOTime) EncodeValues(key string, v *url.Values) error

func (*ISOTime) MarshalJSON

func (t *ISOTime) MarshalJSON() ([]byte, error)

func (*ISOTime) String

func (t *ISOTime) String() string

func (*ISOTime) UnmarshalJSON

func (t *ISOTime) UnmarshalJSON(data []byte) error

type InviteGroupMemberRequest

type InviteGroupMemberRequest struct {
	Email       string           `json:"email"`
	AccessLevel AccessLevelValue `json:"access_level"`
}

type KeysetPaginationOpts added in v0.0.28

type KeysetPaginationOpts struct {
	OrderBy string
	Sort    string
}

type Namespace added in v0.0.29

type Namespace struct {
	Id       int    `json:"id"`
	Name     string `json:"name"`
	Path     string `json:"path"`
	Kind     string `json:"kind"`
	FullPath string `json:"full_path"`
	ParentId int    `json:"parent_id"`
}

type PendingInviteUser

type PendingInviteUser struct {
	InviteEmail string `json:"invite_email"`
}

type Project

type Project struct {
	ID                int           `json:"id"`
	Name              string        `json:"name"`
	Description       string        `json:"description"`
	NameWithNamespace string        `json:"name_with_namespace"`
	Namespace         *Namespace    `json:"namespace"`
	SharedWithGroups  []SharedGroup `json:"shared_with_groups"`
}

type ProjectMember

type ProjectMember struct {
	ID                int           `json:"id"`
	Username          string        `json:"username"`
	Name              string        `json:"name"`
	State             string        `json:"state"`
	AvatarURL         string        `json:"avatar_url"`
	WebURL            string        `json:"web_url"`
	AccessLevel       int           `json:"access_level"`
	ExpiresAt         *ISOTime      `json:"expires_at"`
	GroupSAMLIdentity *SAMLIdentity `json:"group_saml_identity"`
	Email             string        `json:"email"`
}

type ReqOpt added in v0.0.29

type ReqOpt func(reqURL *url.URL)

func WithQueryParam added in v0.0.29

func WithQueryParam(key string, value string) ReqOpt

type SAMLIdentity

type SAMLIdentity struct {
	ExternUID      string `json:"extern_uid"`
	Provider       string `json:"provider"`
	SAMLProviderID int    `json:"saml_provider_id"`
}

SAMLIdentity represents SAML identity information.

type SharedGroup added in v0.0.33

type SharedGroup struct {
	GroupID          int    `json:"group_id"`
	GroupName        string `json:"group_name"`
	GroupFullPath    string `json:"group_full_path"`
	GroupAccessLevel int    `json:"group_access_level"`
}

SharedGroup is a group invited (shared) into another group or project. GitLab reports it under shared_with_groups on the group/project object. GroupAccessLevel is the ceiling access the invited group's members receive on the target.

type User

type User struct {
	ID              int      `json:"id"`
	Email           string   `json:"email"`
	Username        string   `json:"username"`
	Name            string   `json:"name"`
	State           string   `json:"state"`
	LastActivityOn  *ISOTime `json:"last_activity_on"`
	MembershipState string   `json:"membership_state"`
	Locked          bool     `json:"locked"`
	Bot             bool     `json:"bot"`
}

Jump to

Keyboard shortcuts

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