gitlab

package
v0.0.0-...-5643740 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableMergePipelineProtection

func EnableMergePipelineProtection(ctx context.Context, gitlabClient *goGitLab.Client, projectID int) error

EnableMergePipelineProtection enables the pipeline protection on given project, by default it's turned off and when a new MR is raised users can merge requests bypassing the pipelines. With this setting gitlab disables the Merge button if any of the pipelines are failing

func EncryptAuthInfo

func EncryptAuthInfo(oauthResp *OauthSuccessResponse, gitLabApp *App) (string, error)

EncryptAuthInfo encrypts the oauth response into a string

func FetchMrInfo

func FetchMrInfo(client *gitlab.Client, projectID int, mergeID int) (*gitlab.MergeRequest, error)

FetchMrInfo is responsible for fetching the MR info for given project

func FetchMrParticipants

func FetchMrParticipants(client *gitlab.Client, projectID int, mergeID int) ([]*gitlab.User, error)

FetchMrParticipants is responsible to get unique mr participants

func GetDefaultBranch

func GetDefaultBranch(client *gitlab.Client, projectID int) (*gitlab.Branch, error)

GetDefaultBranch finds the default branch for the given project

func GetGroupByFullPath

func GetGroupByFullPath(ctx context.Context, client *goGitLab.Client, fullPath string) (*goGitLab.Group, error)

GetGroupByFullPath gets a gitlab Group by the given full path

func GetGroupByID

func GetGroupByID(ctx context.Context, client *goGitLab.Client, groupID int) (*goGitLab.Group, error)

GetGroupByID gets a gitlab Group by the given name

func GetGroupByName

func GetGroupByName(ctx context.Context, client *goGitLab.Client, name string) (*goGitLab.Group, error)

GetGroupByName gets a gitlab Group by the given name

func GetGroupProjectListByGroupID

func GetGroupProjectListByGroupID(ctx context.Context, client *goGitLab.Client, groupID int) ([]*goGitLab.Project, error)

GetGroupProjectListByGroupID returns a list of GitLab projects under the specified Organization

func GetGroupsListAll

func GetGroupsListAll(ctx context.Context, client *goGitLab.Client, minAccessLevel goGitLab.AccessLevelValue) ([]*goGitLab.Group, error)

GetGroupsListAll returns a complete list of GitLab groups for which the client as authorization/visibility

func GetLatestCommit

func GetLatestCommit(client *gitlab.Client, projectID int, mergeID int) (*gitlab.Commit, error)

func GetProjectByID

func GetProjectByID(ctx context.Context, client *goGitLab.Client, gitLabProjectID int) (*goGitLab.Project, error)

GetProjectByID returns the GitLab project for the specified ID

func GetProjectListAll

func GetProjectListAll(ctx context.Context, client *goGitLab.Client) ([]*goGitLab.Project, error)

GetProjectListAll returns a complete list of GitLab projects for which the client as authorization/visibility

func GetProjectListByOrgName

func GetProjectListByOrgName(ctx context.Context, client *goGitLab.Client, organizationName string) ([]*goGitLab.Project, error)

GetProjectListByOrgName returns a list of GitLab projects under the specified Organization

func GetUserByName

func GetUserByName(ctx context.Context, client *goGitLab.Client, name string) (*goGitLab.User, error)

GetUserByName gets a gitlab user object by the given name

func ListGroupMembers

func ListGroupMembers(ctx context.Context, client *goGitLab.Client, groupID int) ([]*goGitLab.GroupMember, error)

ListGroupMembers lists the members of a given groupID

func NewGitlabOauthClient

func NewGitlabOauthClient(authInfo string, gitLabApp *App) (*goGitLab.Client, error)

NewGitlabOauthClient creates a new gitlab client from the given oauth info, authInfo is encrypted

func NewGitlabOauthClientFromAccessToken

func NewGitlabOauthClientFromAccessToken(accessToken string) (*goGitLab.Client, error)

NewGitlabOauthClientFromAccessToken creates a new gitlab client from the given access token

func RemoveWebHook

func RemoveWebHook(gitLabClient *gitlab.Client, hookURL string, projectID int) error

RemoveWebHook removes existing webhook from the given project

func SetCommitStatus

func SetCommitStatus(client *gitlab.Client, projectID int, commitSha string, state gitlab.BuildStateValue, message string, targetURL string) error

SetCommitStatus is responsible for setting the MR status for commit sha

func SetMrComment

func SetMrComment(client *gitlab.Client, projectID int, mergeID int, message string) error

SetMrComment is responsible for setting the comment body for project and merge id

func SetOrCreateBranchProtection

func SetOrCreateBranchProtection(ctx context.Context, client *gitlab.Client, projectID int, protectionPattern string) error

SetOrCreateBranchProtection sets the required parameters if existing pattern exists or creates a new one

func SetWebHook

func SetWebHook(gitLabClient *gitlab.Client, hookURL string, projectID int, token string) error

SetWebHook is responsible for adding the webhook for given projectID, if webhook is there already tries to set the attributes if anything is missing, should be idempotent operation

Types

type App

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

App is a wrapper for the GitLab configuration items

func Init

func Init(glAppID, glAppSecret, glAppPrivateKey string) *App

Init initializes the required gitlab variables

func (*App) GetAppID

func (app *App) GetAppID() string

GetAppID returns the GitLab application ID

func (*App) GetAppPrivateKey

func (app *App) GetAppPrivateKey() string

GetAppPrivateKey returns the GitLab application private key

func (*App) GetAppSecret

func (app *App) GetAppSecret() string

GetAppSecret returns the GitLab application secret

type OauthSuccessResponse

type OauthSuccessResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	CreatedAt    int    `json:"created_at"`
}

OauthSuccessResponse is success response from Gitlab

func DecryptAuthInfo

func DecryptAuthInfo(authInfoEncoded string, gitLabApp *App) (*OauthSuccessResponse, error)

DecryptAuthInfo decrypts the auth info into OauthSuccessResponse data structure

func FetchOauthCredentials

func FetchOauthCredentials(code string) (*OauthSuccessResponse, error)

FetchOauthCredentials is responsible for fetching the credentials from gitlab for alredy started Oauth process (access_token, refresh_token)

func RefreshOauthToken

func RefreshOauthToken(refreshToken string) (*OauthSuccessResponse, error)

RefreshOauthToken common routine to refresh the GitLab token

type UserGroup

type UserGroup struct {
	Name     string
	FullPath string
}

UserGroup represents gitlab group

func ListUserProjectGroups

func ListUserProjectGroups(ctx context.Context, client *goGitLab.Client, userID int) ([]*UserGroup, error)

ListUserProjectGroups fetches the unique groups of a gitlab users groups, note: it doesn't list the projects/groups the user is member of ..., it's very limited

Jump to

Keyboard shortcuts

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