Skip to content

Commit

Permalink
Merge pull request #1281 from merico-dev/fix-gitlab-webhook-branch-error
Browse files Browse the repository at this point in the history
fix: gitlab webhook branch error
  • Loading branch information
daniel-hutao authored Dec 1, 2022
2 parents aed9bf9 + b62b7c5 commit c0b2d06
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 0 additions & 2 deletions internal/pkg/pluginengine/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func HandleOutputsReferences(smgr statemanager.Manager, options configmanager.Ra
// recursive if the value is a map (which means Tool.Option is a nested map)
log.Debugf("Got nested map: %v", optionValue)
errorsList = append(errorsList, HandleOutputsReferences(smgr, optionValue)...)
default:
log.Warnf("option %+v process output can't get valid type", optionInterface)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/jenkins/tpl/seedjob.tpl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ gitlabTrigger.setTriggerOnPush(true)
gitlabTrigger.setTriggerOnMergeRequest(true)
gitlabTrigger.setBranchFilterType(BranchFilterType.RegexBasedFilter)
gitlabTrigger.setSourceBranchRegex(".*")
gitlabTrigger.setTargetBranchRegex("master")
gitlabTrigger.setTargetBranchRegex("[[ .Branch ]]")

jobRef.addTrigger(gitlabTrigger)
def gitlabConnection = new GitLabConnectionProperty("[[ .GitlabConnection ]]")
Expand Down
27 changes: 18 additions & 9 deletions pkg/util/scm/gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,31 @@ func (c *Client) DescribeRepo() (*git.RepoInfo, error) {
return repoInfo, nil
}

// AddWebhook will update webhook when it exists
// else create a webbhook
func (c *Client) AddWebhook(webhookConfig *git.WebhookConfig) error {
projectHook, err := c.getWebhook(webhookConfig)
if err != nil {
return err
}
if projectHook != nil {
log.Debugf("gitlab AddWebhook already exist")
return nil
}
p := &gitlab.AddProjectHookOptions{
PushEvents: gitlab.Bool(true),
Token: gitlab.String(webhookConfig.SecretToken),
URL: gitlab.String(webhookConfig.Address),
MergeRequestsEvents: gitlab.Bool(true),
log.Debugf("gitlab AddWebhook already exist, update this webhook")
p := &gitlab.EditProjectHookOptions{
PushEvents: gitlab.Bool(true),
Token: gitlab.String(webhookConfig.SecretToken),
URL: gitlab.String(webhookConfig.Address),
MergeRequestsEvents: gitlab.Bool(true),
}
_, _, err = c.Projects.EditProjectHook(c.GetRepoPath(), projectHook.ID, p)
} else {
p := &gitlab.AddProjectHookOptions{
PushEvents: gitlab.Bool(true),
Token: gitlab.String(webhookConfig.SecretToken),
URL: gitlab.String(webhookConfig.Address),
MergeRequestsEvents: gitlab.Bool(true),
}
_, _, err = c.Projects.AddProjectHook(c.GetRepoPath(), p)
}
_, _, err = c.Projects.AddProjectHook(c.GetRepoPath(), p)
if err != nil {
return c.newModuleError(err)
}
Expand Down

0 comments on commit c0b2d06

Please sign in to comment.