36 Star 395 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
phli 提交于 2018-09-19 16:48 . add bitbucket support in pipeline
package drivers
import (
"fmt"
"net/http"
"github.com/rancher/rancher/pkg/pipeline/providers"
"github.com/rancher/rancher/pkg/pipeline/remote/model"
"github.com/rancher/rancher/pkg/pipeline/utils"
"github.com/rancher/types/apis/project.cattle.io/v3"
)
const (
RefsBranchPrefix = "refs/heads/"
RefsTagPrefix = "refs/tags/"
)
func isEventActivated(info *model.BuildInfo, pipeline *v3.Pipeline) bool {
if (info.Event == utils.WebhookEventPush && pipeline.Spec.TriggerWebhookPush) ||
(info.Event == utils.WebhookEventTag && pipeline.Spec.TriggerWebhookTag) ||
(info.Event == utils.WebhookEventPullRequest && pipeline.Spec.TriggerWebhookPr) {
return true
}
return false
}
func validateAndGeneratePipelineExecution(pipelineExecutions v3.PipelineExecutionInterface,
sourceCodeCredentials v3.SourceCodeCredentialInterface,
sourceCodeCredentialLister v3.SourceCodeCredentialLister,
info *model.BuildInfo,
pipeline *v3.Pipeline) (int, error) {
if !isEventActivated(info, pipeline) {
return http.StatusUnavailableForLegalReasons, fmt.Errorf("trigger for event '%s' is disabled", info.Event)
}
pipelineConfig, err := providers.GetPipelineConfigByBranch(sourceCodeCredentials, sourceCodeCredentialLister, pipeline, info.Branch)
if err != nil {
return http.StatusInternalServerError, err
}
if pipelineConfig == nil {
//no pipeline config to run
return http.StatusOK, nil
}
if !utils.Match(pipelineConfig.Branch, info.Branch) {
return http.StatusUnavailableForLegalReasons, fmt.Errorf("skipped branch '%s'", info.Branch)
}
if _, err := utils.GenerateExecution(pipelineExecutions, pipeline, pipelineConfig, info); err != nil {
return http.StatusInternalServerError, err
}
return http.StatusOK, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.2-rc4

搜索帮助

344bd9b3 5694891 D2dac590 5694891