webhook

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypePR   = "pr"
	EventTypePush = "push"
	EventTypeTag  = "tag"
)
View Source
const SplitSymbol = "&"

Variables

This section is empty.

Functions

func AutoCancelTask

func AutoCancelTask(autoCancelOpt *AutoCancelOpt, log *zap.SugaredLogger) error

func AutoCancelTestTask

func AutoCancelTestTask(autoCancelOpt *AutoCancelOpt, task *task.Task, log *zap.SugaredLogger) error

func AutoCancelWorkflowTask

func AutoCancelWorkflowTask(autoCancelOpt *AutoCancelOpt, task *task.Task, log *zap.SugaredLogger) error

func AutoCancelWorkflowV4Task

func AutoCancelWorkflowV4Task(autoCancelOpt *AutoCancelOpt, log *zap.SugaredLogger) error

func ContainsFile

func ContainsFile(h *commonmodels.GitHook, file string) bool

ContainsFile "/" 代表全部文件

func ConvertScanningHookToMainHookRepo

func ConvertScanningHookToMainHookRepo(hook *commonmodels.ScanningHook) *commonmodels.MainHookRepo

func CreateEnvAndTaskByPR

func CreateEnvAndTaskByPR(workflowArgs *commonmodels.WorkflowTaskArgs, prID int, requestID string, log *zap.SugaredLogger) error

CreateEnvAndTaskByPR 根据pr触发创建环境、使用工作流更新该创建的环境、根据环境删除策略删除环境

func EventConfigured

func EventConfigured(m *commonmodels.MainHookRepo, event config.HookEventType) bool

func GetAddress

func GetAddress(URL string) (string, error)

func GetGerritProductionServiceTemplates added in v2.3.0

func GetGerritProductionServiceTemplates() ([]*commonmodels.Service, error)

GetGerritProductionServiceTemplates Get all service templates maintained in gerrit

func GetGerritTestingServiceTemplates added in v2.3.0

func GetGerritTestingServiceTemplates() ([]*commonmodels.Service, error)

GetGerritTestingServiceTemplates Get all service templates maintained in gerrit

func GetGerritWorkspaceBasePath

func GetGerritWorkspaceBasePath(repoName string) (string, error)

func GetGiteeProductionServiceTemplates added in v2.3.0

func GetGiteeProductionServiceTemplates() ([]*commonmodels.Service, error)

GetGiteeProductionServiceTemplates Get all service templates maintained in gitee

func GetGiteeTestingServiceTemplates added in v2.3.0

func GetGiteeTestingServiceTemplates() ([]*commonmodels.Service, error)

GetGiteeTestingServiceTemplates Get all service templates maintained in gitee

func GetGithubProductionServiceTemplates added in v2.3.0

func GetGithubProductionServiceTemplates() ([]*commonmodels.Service, error)

func GetGithubTestingServiceTemplates added in v2.3.0

func GetGithubTestingServiceTemplates() ([]*commonmodels.Service, error)

func GetGitlabProductionServiceTemplates added in v2.3.0

func GetGitlabProductionServiceTemplates() ([]*commonmodels.Service, error)

func GetGitlabTestingServiceTemplates added in v2.3.0

func GetGitlabTestingServiceTemplates() ([]*commonmodels.Service, error)

func GetOwnerRepoBranchPath

func GetOwnerRepoBranchPath(URL string) (string, string, string, string, string, string, error)

GetOwnerRepoBranchPath 获取gitlab路径中的owner、repo、branch和path return address, owner, repo, branch, path, pathType Note this function needs be optimized badly!

func GetWorkspaceBasePath

func GetWorkspaceBasePath(repoName string) (string, error)

func GitlabGetLatestCommit

func GitlabGetLatestCommit(client *gitlabtool.Client, owner, repo string, ref, path string) (*gitlab.Commit, error)

func GitlabGetRawFiles

func GitlabGetRawFiles(client *gitlabtool.Client, owner, repo, ref, path, pathType string) (files []string, err error)

GitlabGetRawFiles ... projectID: identity of project, can be retrieved from s.GitlabGetProjectID(owner, repo) ref: branch (e.g. master) or commit (commit id) or tag path: file path of raw files, only retrieve leaf node(blob type == file), no recursive get

func MatchChanges

func MatchChanges(m *commonmodels.MainHookRepo, files []string) bool

func ProcessGerritHook

func ProcessGerritHook(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGiteeHook

func ProcessGiteeHook(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGithubHook

func ProcessGithubHook(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) (string, error)

func ProcessGithubWebHook

func ProcessGithubWebHook(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGithubWebHookForTest

func ProcessGithubWebHookForTest(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGithubWebHookForWorkflowV4

func ProcessGithubWebHookForWorkflowV4(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGithubWebhookForScanning

func ProcessGithubWebhookForScanning(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func ProcessGitlabHook

func ProcessGitlabHook(payload []byte, req *http.Request, requestID string, log *zap.SugaredLogger) error

func SyncServiceTemplateFromGerrit

func SyncServiceTemplateFromGerrit(service *commonmodels.Service, log *zap.SugaredLogger) error

SyncServiceTemplateFromGerrit Force to sync Service Template to the latest commit and content, Notes: if remains the same, quit sync; if updates, revision +1

func SyncServiceTemplateFromGitee

func SyncServiceTemplateFromGitee(service *commonmodels.Service, log *zap.SugaredLogger) error

func SyncServiceTemplateFromGithub

func SyncServiceTemplateFromGithub(service *commonmodels.Service, latestCommitID, latestCommitMessage string, log *zap.SugaredLogger) error

SyncServiceTemplateFromGithub Force to sync Service Template to latest commit and content, Notes: if remains the same, quit sync; if updates, revision +1

func SyncServiceTemplateFromGitlab

func SyncServiceTemplateFromGitlab(service *commonmodels.Service, log *zap.SugaredLogger) error

SyncServiceTemplateFromGitlab Force to sync Service Template to latest commit and content, Notes: if remains the same, quit sync; if updates, revision +1

func TriggerPipelineByGitlabEvent

func TriggerPipelineByGitlabEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerScanningByGithubEvent

func TriggerScanningByGithubEvent(event interface{}, requestID string, log *zap.SugaredLogger) error

func TriggerScanningByGitlabEvent

func TriggerScanningByGitlabEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerTestByGiteeEvent

func TriggerTestByGiteeEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerTestByGithubEvent

func TriggerTestByGithubEvent(event interface{}, requestID string, log *zap.SugaredLogger) error

func TriggerTestByGitlabEvent

func TriggerTestByGitlabEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

TriggerTestByGitlabEvent 测试管理模块的触发器任务

func TriggerWorkflowByGerritEvent

func TriggerWorkflowByGerritEvent(event *gerritTypeEvent, body []byte, uri, baseURI, domain, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowByGiteeEvent

func TriggerWorkflowByGiteeEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowByGithubEvent

func TriggerWorkflowByGithubEvent(event interface{}, baseURI, deliveryID, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowByGitlabEvent

func TriggerWorkflowByGitlabEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowV4ByGerritEvent

func TriggerWorkflowV4ByGerritEvent(event *gerritTypeEvent, body []byte, uri, baseURI, domain, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowV4ByGiteeEvent

func TriggerWorkflowV4ByGiteeEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowV4ByGithubEvent

func TriggerWorkflowV4ByGithubEvent(event interface{}, baseURI, deliveryID, requestID string, log *zap.SugaredLogger) error

func TriggerWorkflowV4ByGitlabEvent

func TriggerWorkflowV4ByGitlabEvent(event interface{}, baseURI, requestID string, log *zap.SugaredLogger) error

func UpdateWorkflowTaskArgs

func UpdateWorkflowTaskArgs(triggerYaml *TriggerYaml, workflow *commonmodels.Workflow, workFlowArgs *commonmodels.WorkflowTaskArgs, item *commonmodels.WorkflowHook, branref string, prId int) error

func WaitEnvCreate

func WaitEnvCreate(timeoutSeconds int, envName string, workflowArgs *commonmodels.WorkflowTaskArgs, log *zap.SugaredLogger) error

func WaitEnvDelete

func WaitEnvDelete(timeoutSeconds int, envName string, workflowArgs *commonmodels.WorkflowTaskArgs, log *zap.SugaredLogger) error

Types

type AuthorInfo

type AuthorInfo struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

type AutoCancelOpt

type AutoCancelOpt struct {
	Type           string
	MergeRequestID string
	Ref            string
	CommitID       string
	TaskType       config.PipelineType
	MainRepo       *commonmodels.MainHookRepo
	WorkflowArgs   *commonmodels.WorkflowTaskArgs
	TestArgs       *commonmodels.TestTaskArgs
	IsYaml         bool
	AutoCancel     bool
	YamlHookPath   string
	WorkflowName   string
}

type Build

type Build struct {
	Services []*BuildServices `yaml:"services"`
}

type BuildServices

type BuildServices struct {
	Name          string       `yaml:"name"`
	ServiceModule string       `yaml:"service_module"`
	Variables     []*Variables `yaml:"variables"`
}

func ServicesMatchChangesFiles

func ServicesMatchChangesFiles(mf *MatchFoldersElem, files []string) []BuildServices

type CacheSet

type CacheSet struct {
	IgnoreCache bool `yaml:"ignore_cache"`
	ResetCache  bool `yaml:"reset_cache"`
}

type ChangeInfo

type ChangeInfo struct {
	Project       string    `json:"project"`
	Branch        string    `json:"branch"`
	ID            string    `json:"id"`
	Number        int       `json:"number"`
	Subject       string    `json:"subject"`
	Owner         OwnerInfo `json:"owner"`
	URL           string    `json:"url"`
	CommitMessage string    `json:"commitMessage"`
	CreatedOn     int       `json:"createdOn"`
	Status        string    `json:"status"`
}

type ChangeKeyInfo

type ChangeKeyInfo struct {
	ID string `json:"id"`
}

type CommitInfo

type CommitInfo struct {
	ID        string        `json:"id"`
	Message   string        `json:"message"`
	Timestamp time.Time     `json:"timestamp"`
	URL       string        `json:"url"`
	Author    AuthorInfo    `json:"author"`
	Added     []interface{} `json:"added"`
	Modified  []string      `json:"modified"`
	Removed   []interface{} `json:"removed"`
}

type Deploy

type Deploy struct {
	Strategy         DeployStrategy   `yaml:"strategy"`
	Envsname         []string         `yaml:"envs_name"`
	EnvRecyclePolicy EnvRecyclePolicy `yaml:"env_recycle_policy"`
	BaseNamespace    string           `yaml:"base_env"`
}

Strategy

 single:
	Update to the specified environment;
 dynamic:
	Dynamic selection of idle environment;
 base:
	Create a new environment based on the baseline environment
	And Need to set EnvRecyclePolicy:success/always/never

type DeployStrategy

type DeployStrategy string
const (
	DeployStrategySingle  DeployStrategy = "single"
	DeployStrategyDynamic DeployStrategy = "dynamic"
	DeployStrategyBase    DeployStrategy = "base"
)

type EnvRecyclePolicy

type EnvRecyclePolicy string
const (
	EnvRecyclePolicySuccess EnvRecyclePolicy = "success"
	EnvRecyclePolicyAlways  EnvRecyclePolicy = "always"
	EnvRecyclePolicyNever   EnvRecyclePolicy = "never"
)

type EventPush

type EventPush struct {
	EventName   string `json:"event_name"`
	Before      string `json:"before"`
	After       string `json:"after"`
	Ref         string `json:"ref"`
	CheckoutSha string `json:"checkout_sha"`
	ProjectID   int    `json:"project_id"`
	Body        string `json:"body"`
}

type GitlabEvent

type GitlabEvent struct {
	ObjectKind        string         `json:"object_kind"`
	EventName         string         `json:"event_name"`
	Before            string         `json:"before"`
	After             string         `json:"after"`
	Ref               string         `json:"ref"`
	CheckoutSha       string         `json:"checkout_sha"`
	Message           interface{}    `json:"message"`
	UserID            int            `json:"user_id"`
	UserName          string         `json:"user_name"`
	UserUsername      string         `json:"user_username"`
	UserEmail         string         `json:"user_email"`
	UserAvatar        string         `json:"user_avatar"`
	ProjectID         int            `json:"project_id"`
	Project           ProjectDetail  `json:"project"`
	Commits           []CommitInfo   `json:"commits"`
	TotalCommitsCount int            `json:"total_commits_count"`
	Repository        RepositoryInfo `json:"repository"`
}

type MatchFolders

type MatchFolders []string

func (MatchFolders) ContainsFile

func (m MatchFolders) ContainsFile(file string) bool

type MatchFoldersElem

type MatchFoldersElem struct {
	MatchSwitch          string              `yaml:"match_switch"`
	MatchFoldersTree     []*MatchFoldersTree `yaml:"match_folders_tree"`
	MatchFoldersSpecific string              `yaml:"match_folders_specific"`
}

type MatchFoldersTree

type MatchFoldersTree struct {
	Name          string   `yaml:"name"`
	ServiceModule string   `yaml:"service_module"`
	FileTree      []string `yaml:"file_tree"`
}

type OwnerInfo

type OwnerInfo struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

type PatchSetInfo

type PatchSetInfo struct {
	Number         int          `json:"number"`
	Revision       string       `json:"revision"`
	Parents        []string     `json:"parents"`
	Ref            string       `json:"ref"`
	Uploader       UploaderInfo `json:"uploader"`
	CreatedOn      int          `json:"createdOn"`
	Author         AuthorInfo   `json:"author"`
	Kind           string       `json:"kind"`
	SizeInsertions int          `json:"sizeInsertions"`
	SizeDeletions  int          `json:"sizeDeletions"`
}

type PipelineHook

type PipelineHook struct {
	PipelineName string
	GitHook      commonmodels.GitHook
}

type ProjectDetail

type ProjectDetail struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Description       string      `json:"description"`
	WebURL            string      `json:"web_url"`
	AvatarURL         interface{} `json:"avatar_url"`
	GitSSHURL         string      `json:"git_ssh_url"`
	GitHTTPURL        string      `json:"git_http_url"`
	Namespace         string      `json:"namespace"`
	VisibilityLevel   int         `json:"visibility_level"`
	PathWithNamespace string      `json:"path_with_namespace"`
	DefaultBranch     string      `json:"default_branch"`
	CiConfigPath      interface{} `json:"ci_config_path"`
	Homepage          string      `json:"homepage"`
	URL               string      `json:"url"`
	SSHURL            string      `json:"ssh_url"`
	HTTPURL           string      `json:"http_url"`
}

type ProjectInfo

type ProjectInfo struct {
	Name string `json:"name"`
}

type Repo

type Repo struct {
	Strategy TestRepoStrategy `yaml:"strategy"`
}

Strategy

 default:
	Code repository information configured by default on the zadig platform
 currentRepo:
	Use current changed code information

type RepositoryInfo

type RepositoryInfo struct {
	Name            string `json:"name"`
	URL             string `json:"url"`
	Description     string `json:"description"`
	Homepage        string `json:"homepage"`
	GitHTTPURL      string `json:"git_http_url"`
	GitSSHURL       string `json:"git_ssh_url"`
	VisibilityLevel int    `json:"visibility_level"`
}

type Rules

type Rules struct {
	Branchs      []string               `yaml:"branchs"`
	Events       []config.HookEventType `yaml:"events"`
	Strategy     *StrategyRules         `yaml:"strategy"`
	MatchFolders *MatchFoldersElem      `yaml:"match_folders"`
}

type Stage

type Stage string
const (
	StageBuild  Stage = "build"
	StageDeploy Stage = "deploy"
	StageTest   Stage = "test"
)

type StrategyRules

type StrategyRules struct {
	AutoCancel bool `yaml:"auto_cancel"`
}

type SubmitterInfo

type SubmitterInfo struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

type Test

type Test struct {
	Name      string       `yaml:"name"`
	Repo      *Repo        `yaml:"repo"`
	Variables []*Variables `yaml:"variables"`
}

type TestRepoStrategy

type TestRepoStrategy string
const (
	TestRepoStrategyDefault     TestRepoStrategy = "default"
	TestRepoStrategyCurrentRepo TestRepoStrategy = "currentRepo"
)

type TriggerYaml

type TriggerYaml struct {
	Stages   []Stage          `yaml:"stages"`
	Build    []*BuildServices `yaml:"build"`
	Deploy   *Deploy          `yaml:"deploy"`
	Test     []*Test          `yaml:"test"`
	Rules    *Rules           `yaml:"rules"`
	CacheSet *CacheSet        `yaml:"cache_set"`
}

type UploaderInfo

type UploaderInfo struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

type Variables

type Variables struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

Jump to

Keyboard shortcuts

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