Skip to content

Commit 08ef0d8

Browse files
authored
fix(hooks): remove deprecated branch deletion from hooks (#5955)
Signed-off-by: francois samin <[email protected]>
1 parent 48aa23d commit 08ef0d8

File tree

8 files changed

+4
-157
lines changed

8 files changed

+4
-157
lines changed

engine/hooks/bitbucket_cloud.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,13 @@ func (s *Service) generatePayloadFromBitbucketCloudRequest(ctx context.Context,
1717
return nil, sdk.WrapError(err, "unable ro read bitbucket request: %s", string(t.WebHook.RequestBody))
1818
}
1919

20-
projectKey := t.Config["project"].Value
21-
workflowName := t.Config["workflow"].Value
22-
2320
payload := make(map[string]interface{})
2421
payload[GIT_EVENT] = event
2522
getVariableFromBitbucketCloudAuthor(payload, request.Actor)
2623
getVariableFromBitbucketCloudRepository(payload, request.Repository)
2724
getPayloadStringVariable(ctx, payload, request)
2825

2926
for _, pushChange := range request.Push.Changes {
30-
if pushChange.Closed {
31-
if pushChange.Old.Type == "branch" {
32-
if err := s.enqueueBranchDeletion(projectKey, workflowName, strings.TrimPrefix(pushChange.Old.Name, "refs/heads/")); err != nil {
33-
log.Error(ctx, "cannot enqueue branch deletion: %v", err)
34-
}
35-
}
36-
continue
37-
}
38-
39-
if pushChange.New.Type == "branch" {
40-
branch := strings.TrimPrefix(pushChange.New.Name, "refs/heads/")
41-
if err := s.stopBranchDeletionTask(ctx, branch); err != nil {
42-
log.Error(ctx, "cannot stop branch deletion task for branch %s : %v", branch, err)
43-
}
44-
45-
}
46-
4727
payloadChange := make(map[string]interface{})
4828
for k, v := range payload {
4929
payloadChange[k] = v

engine/hooks/bitbucket_server.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/rockbears/log"
9-
108
"github.com/ovh/cds/sdk"
119
)
1210

@@ -43,23 +41,7 @@ func (s *Service) generatePayloadFromBitbucketServerRequest(ctx context.Context,
4341
payloads = append(payloads, payload)
4442
}
4543

46-
projectKey := t.Config["project"].Value
47-
workflowName := t.Config["workflow"].Value
4844
for _, pushChange := range request.Changes {
49-
if pushChange.Type == "DELETE" {
50-
err := s.enqueueBranchDeletion(projectKey, workflowName, strings.TrimPrefix(pushChange.RefID, "refs/heads/"))
51-
if err != nil {
52-
log.Error(ctx, "cannot enqueue branch deletion: %v", err)
53-
}
54-
continue
55-
}
56-
if !strings.HasPrefix(pushChange.RefID, "refs/tags/") {
57-
branch := strings.TrimPrefix(pushChange.RefID, "refs/heads/")
58-
if err := s.stopBranchDeletionTask(ctx, branch); err != nil {
59-
log.Error(ctx, "cannot stop branch deletion task for branch %s : %v", branch, err)
60-
}
61-
}
62-
6345
payloadChanges := make(map[string]interface{})
6446
for k, v := range payload {
6547
payloadChanges[k] = v

engine/hooks/branch_deletion.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

engine/hooks/github.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import (
44
"context"
55
"strings"
66

7-
"github.com/rockbears/log"
8-
97
"github.com/ovh/cds/sdk"
108
)
119

1210
func (s *Service) generatePayloadFromGithubRequest(ctx context.Context, t *sdk.TaskExecution, event string) (map[string]interface{}, error) {
13-
projectKey := t.Config["project"].Value
14-
workflowName := t.Config["workflow"].Value
15-
1611
var request GithubWebHookEvent
1712
if err := sdk.JSONUnmarshal(t.WebHook.RequestBody, &request); err != nil {
1813
return nil, sdk.WrapError(err, "unable ro read github request: %s", string(t.WebHook.RequestBody))
@@ -23,13 +18,6 @@ func (s *Service) generatePayloadFromGithubRequest(ctx context.Context, t *sdk.T
2318

2419
if request.Ref != "" {
2520
branch := strings.TrimPrefix(request.Ref, "refs/heads/")
26-
if request.Deleted {
27-
err := s.enqueueBranchDeletion(projectKey, workflowName, branch)
28-
return nil, sdk.WrapError(err, "cannot enqueue branch deletion")
29-
}
30-
if err := s.stopBranchDeletionTask(ctx, branch); err != nil {
31-
log.Error(ctx, "cannot stop branch deletion task for branch %s : %v", branch, err)
32-
}
3321

3422
if !strings.HasPrefix(request.Ref, "refs/tags/") {
3523
payload[GIT_BRANCH] = branch

engine/hooks/gitlab.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,15 @@ import (
44
"context"
55
"strings"
66

7-
"github.com/rockbears/log"
8-
97
"github.com/ovh/cds/sdk"
108
)
119

1210
func (s *Service) generatePayloadFromGitlabRequest(ctx context.Context, t *sdk.TaskExecution, event string) (map[string]interface{}, error) {
13-
projectKey := t.Config["project"].Value
14-
workflowName := t.Config["workflow"].Value
15-
1611
var request GitlabEvent
1712
if err := sdk.JSONUnmarshal(t.WebHook.RequestBody, &request); err != nil {
1813
return nil, sdk.WrapError(err, "unable ro read gitlab request: %s", string(t.WebHook.RequestBody))
1914
}
2015

21-
// Branch deletion ( gitlab return 0000000000000000000000000000000000000000 as git hash)
22-
if request.After == "0000000000000000000000000000000000000000" {
23-
err := s.enqueueBranchDeletion(projectKey, workflowName, strings.TrimPrefix(request.Ref, "refs/heads/"))
24-
return nil, sdk.WrapError(err, "cannot enqueue branch deletion")
25-
}
26-
2716
payload := make(map[string]interface{})
2817

2918
payload[GIT_EVENT] = event
@@ -38,9 +27,6 @@ func (s *Service) generatePayloadFromGitlabRequest(ctx context.Context, t *sdk.T
3827
if !strings.HasPrefix(request.Ref, "refs/tags/") {
3928
branch := strings.TrimPrefix(request.Ref, "refs/heads/")
4029
payload[GIT_BRANCH] = branch
41-
if err := s.stopBranchDeletionTask(ctx, branch); err != nil {
42-
log.Error(ctx, "cannot stop branch deletion task for branch %s : %v", branch, err)
43-
}
4430
} else {
4531
payload[GIT_TAG] = strings.TrimPrefix(request.Ref, "refs/tags/")
4632
}

engine/hooks/scheduler.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,11 @@ func (s *Service) deleteTaskExecutionsRoutine(ctx context.Context) error {
210210
})
211211

212212
for i, e := range execs {
213-
switch e.Type {
214-
// Delete all branch deletion task execution
215-
case TypeBranchDeletion:
216-
if e.Status == TaskExecutionDone && e.ProcessingTimestamp != 0 {
217-
if err := s.Dao.DeleteTaskExecution(&e); err != nil {
218-
log.Error(ctx, "deleteTaskExecutionsRoutine > error on DeleteTaskExecution: %v", err)
219-
}
220-
taskToDelete = true
221-
}
222-
default:
223-
if i >= s.Cfg.ExecutionHistory && e.ProcessingTimestamp != 0 {
224-
if err := s.Dao.DeleteTaskExecution(&e); err != nil {
225-
log.Error(ctx, "deleteTaskExecutionsRoutine > error on DeleteTaskExecution: %v", err)
226-
}
213+
if i >= s.Cfg.ExecutionHistory && e.ProcessingTimestamp != 0 {
214+
if err := s.Dao.DeleteTaskExecution(&e); err != nil {
215+
log.Error(ctx, "deleteTaskExecutionsRoutine > error on DeleteTaskExecution: %v", err)
227216
}
228217
}
229-
230218
}
231219

232220
if taskToDelete {

engine/hooks/tasks.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const (
2020
TypeWebHook = "Webhook"
2121
TypeScheduler = "Scheduler"
2222
TypeRepoPoller = "RepoPoller"
23-
TypeBranchDeletion = "BranchDeletion"
2423
TypeKafka = "Kafka"
2524
TypeGerrit = "Gerrit"
2625
TypeRabbitMQ = "RabbitMQ"
@@ -287,7 +286,7 @@ func (s *Service) startTask(ctx context.Context, t *sdk.Task) (*sdk.TaskExecutio
287286
switch t.Type {
288287
case TypeWebHook, TypeRepoManagerWebHook, TypeWorkflowHook:
289288
return nil, nil
290-
case TypeScheduler, TypeRepoPoller, TypeBranchDeletion:
289+
case TypeScheduler, TypeRepoPoller:
291290
return nil, s.prepareNextScheduledTaskExecution(ctx, t)
292291
case TypeKafka:
293292
return nil, s.startKafkaHook(ctx, t)
@@ -352,10 +351,6 @@ func (s *Service) prepareNextScheduledTaskExecution(ctx context.Context, t *sdk.
352351
nextSchedule = time.Unix(nextExec, 0)
353352
}
354353
}
355-
356-
case TypeBranchDeletion:
357-
now := time.Now()
358-
nextSchedule = now.Add(24 * time.Hour)
359354
}
360355

361356
//Craft a new execution
@@ -425,8 +420,6 @@ func (s *Service) doTask(ctx context.Context, t *sdk.Task, e *sdk.TaskExecution)
425420
//Populate next execution
426421
hs, err = s.doPollerTaskExecution(ctx, t, e)
427422
doRestart = true
428-
case e.ScheduledTask != nil && e.Type == TypeBranchDeletion:
429-
_, err = s.doBranchDeletionTaskExecution(e)
430423
case e.Kafka != nil && e.Type == TypeKafka:
431424
h, err = s.doKafkaTaskExecution(e)
432425
case e.RabbitMQ != nil && e.Type == TypeRabbitMQ:

engine/hooks/webhook.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -212,35 +212,6 @@ func executeWebHook(t *sdk.TaskExecution) (*sdk.WorkflowNodeRunHookEvent, error)
212212
return &h, nil
213213
}
214214

215-
func (s *Service) enqueueBranchDeletion(projectKey, workflowName, branch string) error {
216-
config := sdk.WorkflowNodeHookConfig{
217-
"project": sdk.WorkflowNodeHookConfigValue{
218-
Configurable: false,
219-
Type: sdk.HookConfigTypeProject,
220-
Value: projectKey,
221-
},
222-
"workflow": sdk.WorkflowNodeHookConfigValue{
223-
Configurable: false,
224-
Type: sdk.HookConfigTypeWorkflow,
225-
Value: workflowName,
226-
},
227-
"branch": sdk.WorkflowNodeHookConfigValue{
228-
Configurable: false,
229-
Type: sdk.HookConfigTypeString,
230-
Value: branch,
231-
},
232-
}
233-
task := sdk.Task{
234-
Config: config,
235-
Type: TypeBranchDeletion,
236-
UUID: branch + "-" + sdk.UUID(),
237-
}
238-
239-
_, err := s.startTask(context.Background(), &task)
240-
241-
return sdk.WrapError(err, "cannot start task")
242-
}
243-
244215
func copyValues(dst, src url.Values) {
245216
for k, vs := range src {
246217
for _, value := range vs {

0 commit comments

Comments
 (0)