Skip to content

Commit c0b2d06

Browse files
authored
Merge pull request #1281 from merico-dev/fix-gitlab-webhook-branch-error
fix: gitlab webhook branch error
2 parents aed9bf9 + b62b7c5 commit c0b2d06

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

internal/pkg/pluginengine/outputs.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func HandleOutputsReferences(smgr statemanager.Manager, options configmanager.Ra
4040
// recursive if the value is a map (which means Tool.Option is a nested map)
4141
log.Debugf("Got nested map: %v", optionValue)
4242
errorsList = append(errorsList, HandleOutputsReferences(smgr, optionValue)...)
43-
default:
44-
log.Warnf("option %+v process output can't get valid type", optionInterface)
4543
}
4644
}
4745

pkg/util/jenkins/tpl/seedjob.tpl.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ gitlabTrigger.setTriggerOnPush(true)
6464
gitlabTrigger.setTriggerOnMergeRequest(true)
6565
gitlabTrigger.setBranchFilterType(BranchFilterType.RegexBasedFilter)
6666
gitlabTrigger.setSourceBranchRegex(".*")
67-
gitlabTrigger.setTargetBranchRegex("master")
67+
gitlabTrigger.setTargetBranchRegex("[[ .Branch ]]")
6868

6969
jobRef.addTrigger(gitlabTrigger)
7070
def gitlabConnection = new GitLabConnectionProperty("[[ .GitlabConnection ]]")

pkg/util/scm/gitlab/repo.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,31 @@ func (c *Client) DescribeRepo() (*git.RepoInfo, error) {
8989
return repoInfo, nil
9090
}
9191

92+
// AddWebhook will update webhook when it exists
93+
// else create a webbhook
9294
func (c *Client) AddWebhook(webhookConfig *git.WebhookConfig) error {
9395
projectHook, err := c.getWebhook(webhookConfig)
9496
if err != nil {
9597
return err
9698
}
9799
if projectHook != nil {
98-
log.Debugf("gitlab AddWebhook already exist")
99-
return nil
100-
}
101-
p := &gitlab.AddProjectHookOptions{
102-
PushEvents: gitlab.Bool(true),
103-
Token: gitlab.String(webhookConfig.SecretToken),
104-
URL: gitlab.String(webhookConfig.Address),
105-
MergeRequestsEvents: gitlab.Bool(true),
100+
log.Debugf("gitlab AddWebhook already exist, update this webhook")
101+
p := &gitlab.EditProjectHookOptions{
102+
PushEvents: gitlab.Bool(true),
103+
Token: gitlab.String(webhookConfig.SecretToken),
104+
URL: gitlab.String(webhookConfig.Address),
105+
MergeRequestsEvents: gitlab.Bool(true),
106+
}
107+
_, _, err = c.Projects.EditProjectHook(c.GetRepoPath(), projectHook.ID, p)
108+
} else {
109+
p := &gitlab.AddProjectHookOptions{
110+
PushEvents: gitlab.Bool(true),
111+
Token: gitlab.String(webhookConfig.SecretToken),
112+
URL: gitlab.String(webhookConfig.Address),
113+
MergeRequestsEvents: gitlab.Bool(true),
114+
}
115+
_, _, err = c.Projects.AddProjectHook(c.GetRepoPath(), p)
106116
}
107-
_, _, err = c.Projects.AddProjectHook(c.GetRepoPath(), p)
108117
if err != nil {
109118
return c.newModuleError(err)
110119
}

0 commit comments

Comments
 (0)