Skip to content

Commit 65842a2

Browse files
committed
main update
2 parents c92b200 + d479c11 commit 65842a2

28 files changed

+976
-571
lines changed

api/GrpcHandler.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,22 @@ func (impl *GrpcHandlerImpl) GetWebhookData(ctx context.Context, req *pb.Webhook
564564
func (impl *GrpcHandlerImpl) GetAllWebhookEventConfigForHost(ctx context.Context, req *pb.WebhookEventConfigRequest) (
565565
*pb.WebhookEventConfigResponse, error) {
566566

567-
res, err := impl.repositoryManager.GetAllWebhookEventConfigForHost(int(req.GitHostId))
567+
var res []*git.WebhookEventConfig
568+
var err error
569+
reqModel := &git.WebhookEventConfigRequest{
570+
GitHostId: int(req.GitHostId),
571+
GitHostName: req.GitHostName,
572+
EventId: int(req.EventId),
573+
}
574+
res, err = impl.repositoryManager.GetAllWebhookEventConfigForHost(reqModel)
568575
if err != nil {
569576
impl.logger.Errorw("error while fetching webhook event config",
570577
"gitHostId", req.GitHostId,
571578
"err", err)
572579

573580
return nil, err
574581
}
582+
575583
webhookConfig := &pb.WebhookEventConfigResponse{}
576584
if res == nil {
577585
return webhookConfig, nil

api/RestHandler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ func (handler RestHandlerImpl) GetAllWebhookEventConfigForHost(w http.ResponseWr
429429
}
430430
handler.logger.Infow("webhook event config request ", "req", request)
431431

432-
webhookEventConfigArr, err := handler.repositoryManager.GetAllWebhookEventConfigForHost(request.GitHostId)
432+
var webhookEventConfigArr []*git.WebhookEventConfig
433+
webhookEventConfigArr, err = handler.repositoryManager.GetAllWebhookEventConfigForHost(request)
434+
433435
if err != nil {
434436
handler.writeJsonResp(w, err, nil, http.StatusInternalServerError)
435437
} else {

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ toolchain go1.22.4
66

77
require (
88
github.com/caarlos0/env v3.5.0+incompatible
9-
github.com/devtron-labs/common-lib v0.0.25-0.20240719070325-2cb5e69dc592
10-
github.com/devtron-labs/protos v0.0.3-0.20240719073841-1c0c5d2079c6
11-
github.com/gammazero/workerpool v0.0.0-20200206003619-019d125201ab
9+
github.com/devtron-labs/common-lib v0.0.25-0.20240731080454-282e8ce8a2c5
10+
github.com/devtron-labs/protos v0.0.3-0.20240726131238-dff2574e623d
11+
github.com/gammazero/workerpool v1.1.3
1212
github.com/go-git/go-git/v5 v5.11.0
1313
github.com/go-pg/pg v6.15.1+incompatible
1414
github.com/google/wire v0.6.0
@@ -39,7 +39,7 @@ require (
3939
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
4040
github.com/davecgh/go-spew v1.1.1 // indirect
4141
github.com/emirpasic/gods v1.18.1 // indirect
42-
github.com/gammazero/deque v0.0.0-20200124200322-7e84b94275b8 // indirect
42+
github.com/gammazero/deque v0.2.0 // indirect
4343
github.com/gliderlabs/ssh v0.3.6 // indirect
4444
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
4545
github.com/go-git/go-billy/v5 v5.5.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
2929
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3030
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3131
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32-
github.com/devtron-labs/common-lib v0.0.25-0.20240719070325-2cb5e69dc592 h1:b74H3z6+uWAJnmEZ34YoB/bZ3fdTxGxY88W3xF5WWO0=
33-
github.com/devtron-labs/common-lib v0.0.25-0.20240719070325-2cb5e69dc592/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
34-
github.com/devtron-labs/protos v0.0.3-0.20240719073841-1c0c5d2079c6 h1:PC2j0/purK0ICQEQV0bBweap1BW6tFVvYJFy7QOvXNc=
35-
github.com/devtron-labs/protos v0.0.3-0.20240719073841-1c0c5d2079c6/go.mod h1:ypUknVph8Ph4dxSlrFoouf7wLedQxHku2LQwgRrdgS4=
32+
github.com/devtron-labs/common-lib v0.0.25-0.20240731080454-282e8ce8a2c5 h1:R0T3f9/xk6P6V1ncbAaY2EjRkyjl01wslfbOSnBC18Q=
33+
github.com/devtron-labs/common-lib v0.0.25-0.20240731080454-282e8ce8a2c5/go.mod h1:3GN9TABx4D+hVuF69vGYUUx+H8/WelcKw0lUt8aELok=
34+
github.com/devtron-labs/protos v0.0.3-0.20240726131238-dff2574e623d h1:uZk/CLrgRdPvb9/Eaio6+AkrDGdQaibNmD2DSwJZYEg=
35+
github.com/devtron-labs/protos v0.0.3-0.20240726131238-dff2574e623d/go.mod h1:ypUknVph8Ph4dxSlrFoouf7wLedQxHku2LQwgRrdgS4=
3636
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
3737
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
3838
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
3939
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
40-
github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622/go.mod h1:D90+MBHVc9Sk1lJAbEVgws0eYEurY4mv2TDso3Nxh3w=
41-
github.com/gammazero/deque v0.0.0-20200124200322-7e84b94275b8 h1:9eg1l6iiw3aLaU3P8RRoosiYCRoWDg8HzPiy8xzWKgg=
42-
github.com/gammazero/deque v0.0.0-20200124200322-7e84b94275b8/go.mod h1:D90+MBHVc9Sk1lJAbEVgws0eYEurY4mv2TDso3Nxh3w=
43-
github.com/gammazero/workerpool v0.0.0-20200206003619-019d125201ab h1:BLCWHqLiTSzLZriw46b3HJLswyqY0E6B9y9tk4+7eFI=
44-
github.com/gammazero/workerpool v0.0.0-20200206003619-019d125201ab/go.mod h1:ZObaTlXZGgqKXhhlk+zNvSOXT+h6VGThA0ZQxLqn8x0=
40+
github.com/gammazero/deque v0.2.0 h1:SkieyNB4bg2/uZZLxvya0Pq6diUlwx7m2TeT7GAIWaA=
41+
github.com/gammazero/deque v0.2.0/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU=
42+
github.com/gammazero/workerpool v1.1.3 h1:WixN4xzukFoN0XSeXF6puqEqFTl2mECI9S6W44HWy9Q=
43+
github.com/gammazero/workerpool v1.1.3/go.mod h1:wPjyBLDbyKnUn2XwwyD3EEwo9dHutia9/fwNmSHWACc=
4544
github.com/gliderlabs/ssh v0.3.6 h1:ZzjlDa05TcFRICb3anf/dSPN3ewz1Zx6CMLPWgkm3b8=
4645
github.com/gliderlabs/ssh v0.3.6/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
4746
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -163,8 +162,9 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
163162
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
164163
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
165164
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
166-
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
167165
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
166+
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
167+
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
168168
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
169169
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
170170
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=

internals/sql/WebhookEventRepository.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type GitHostWebhookEvent struct {
2626
tableName struct{} `sql:"git_host_webhook_event" pg:",discard_unknown_columns"`
2727
Id int `sql:"id,pk"`
2828
GitHostId int `sql:"git_host_id,notnull"`
29+
GitHostName string `sql:"git_host_name,notnull"`
2930
Name string `sql:"name,notnull"`
3031
EventTypesCsv string `sql:"event_types_csv,notnull"`
3132
ActionType string `sql:"action_type,notnull"`
@@ -54,7 +55,9 @@ type GitHostWebhookEventSelectors struct {
5455

5556
type WebhookEventRepository interface {
5657
GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*GitHostWebhookEvent, error)
58+
GetAllGitHostWebhookEventByGitHostName(gitHostName string) ([]*GitHostWebhookEvent, error)
5759
GetWebhookEventConfigByEventId(eventId int) (*GitHostWebhookEvent, error)
60+
Update(webhookEvent *GitHostWebhookEvent) error
5861
}
5962

6063
type WebhookEventRepositoryImpl struct {
@@ -65,7 +68,7 @@ func NewWebhookEventRepositoryImpl(dbConnection *pg.DB) *WebhookEventRepositoryI
6568
return &WebhookEventRepositoryImpl{dbConnection: dbConnection}
6669
}
6770

68-
func (impl WebhookEventRepositoryImpl) GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*GitHostWebhookEvent, error) {
71+
func (impl *WebhookEventRepositoryImpl) GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*GitHostWebhookEvent, error) {
6972
var gitHostWebhookEvents []*GitHostWebhookEvent
7073
err := impl.dbConnection.Model(&gitHostWebhookEvents).
7174
Column("git_host_webhook_event.*").
@@ -77,8 +80,20 @@ func (impl WebhookEventRepositoryImpl) GetAllGitHostWebhookEventByGitHostId(gitH
7780
Select()
7881
return gitHostWebhookEvents, err
7982
}
83+
func (impl *WebhookEventRepositoryImpl) GetAllGitHostWebhookEventByGitHostName(gitHostName string) ([]*GitHostWebhookEvent, error) {
84+
var gitHostWebhookEvents []*GitHostWebhookEvent
85+
err := impl.dbConnection.Model(&gitHostWebhookEvents).
86+
Column("git_host_webhook_event.*").
87+
Relation("Selectors", func(q *orm.Query) (query *orm.Query, err error) {
88+
return q.Where("is_active IS TRUE"), nil
89+
}).
90+
Where("git_host_name =? ", gitHostName).
91+
Where("is_active = TRUE ").
92+
Select()
93+
return gitHostWebhookEvents, err
94+
}
8095

81-
func (impl WebhookEventRepositoryImpl) GetWebhookEventConfigByEventId(eventId int) (*GitHostWebhookEvent, error) {
96+
func (impl *WebhookEventRepositoryImpl) GetWebhookEventConfigByEventId(eventId int) (*GitHostWebhookEvent, error) {
8297
gitHostWebhookEvent := &GitHostWebhookEvent{}
8398
err := impl.dbConnection.Model(gitHostWebhookEvent).
8499
Column("git_host_webhook_event.*").
@@ -91,3 +106,11 @@ func (impl WebhookEventRepositoryImpl) GetWebhookEventConfigByEventId(eventId in
91106

92107
return gitHostWebhookEvent, err
93108
}
109+
110+
func (impl *WebhookEventRepositoryImpl) Update(webhookEvent *GitHostWebhookEvent) error {
111+
err := impl.dbConnection.Update(webhookEvent)
112+
if err != nil {
113+
return err
114+
}
115+
return nil
116+
}

pkg/RepoManages.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type RepoManager interface {
4747
RefreshGitMaterial(req *git.RefreshGitMaterialRequest) (*git.RefreshGitMaterialResponse, error)
4848

4949
GetWebhookAndCiDataById(id int, ciPipelineMaterialId int) (*git.WebhookAndCiData, error)
50-
GetAllWebhookEventConfigForHost(gitHostId int) ([]*git.WebhookEventConfig, error)
50+
GetAllWebhookEventConfigForHost(req *git.WebhookEventConfigRequest) ([]*git.WebhookEventConfig, error)
5151
GetWebhookEventConfig(eventId int) (*git.WebhookEventConfig, error)
5252
GetWebhookPayloadDataForPipelineMaterialId(request *git.WebhookPayloadDataRequest) (*git.WebhookPayloadDataResponse, error)
5353
GetWebhookPayloadFilterDataForPipelineMaterialId(request *git.WebhookPayloadFilterDataRequest) (*git.WebhookPayloadFilterDataResponse, error)
@@ -860,18 +860,39 @@ func (impl RepoManagerImpl) GetWebhookAndCiDataById(id int, ciPipelineMaterialId
860860
return webhookAndCiData, nil
861861
}
862862

863-
func (impl RepoManagerImpl) GetAllWebhookEventConfigForHost(gitHostId int) ([]*git.WebhookEventConfig, error) {
864-
863+
func (impl RepoManagerImpl) GetAllWebhookEventConfigForHost(req *git.WebhookEventConfigRequest) ([]*git.WebhookEventConfig, error) {
864+
gitHostId := req.GitHostId
865+
gitHostName := req.GitHostName
866+
var webhookEventsFromDb []*sql.GitHostWebhookEvent
867+
var err error
865868
impl.logger.Debugw("Getting All webhook event config ", "gitHostId", gitHostId)
866-
867-
webhookEventsFromDb, err := impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
868-
869-
if err != nil {
870-
impl.logger.Errorw("error in getting webhook events", "gitHostId", gitHostId, "err", err)
871-
return nil, err
869+
if gitHostName != "" {
870+
webhookEventsFromDb, err = impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostName(gitHostName)
871+
if err != nil {
872+
impl.logger.Errorw("error in getting webhook events", "gitHostName", gitHostName, "err", err)
873+
return nil, err
874+
}
875+
if webhookEventsFromDb == nil || len(webhookEventsFromDb) == 0 {
876+
webhookEventsFromDb, err = impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
877+
if err != nil {
878+
impl.logger.Errorw("error in getting webhook events", "gitHostId", gitHostId, "err", err)
879+
return nil, err
880+
}
881+
}
882+
} else {
883+
webhookEventsFromDb, err = impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
884+
if err != nil {
885+
impl.logger.Errorw("error in getting webhook events", "gitHostId", gitHostId, "err", err)
886+
return nil, err
887+
}
872888
}
873889

874890
// build events
891+
return impl.convertSqlBeansToWebhookEventConfig(webhookEventsFromDb)
892+
893+
}
894+
895+
func (impl RepoManagerImpl) convertSqlBeansToWebhookEventConfig(webhookEventsFromDb []*sql.GitHostWebhookEvent) ([]*git.WebhookEventConfig, error) {
875896
var webhookEvents []*git.WebhookEventConfig
876897
for _, webhookEventFromDb := range webhookEventsFromDb {
877898
webhookEvent := impl.webhookEventBeanConverter.ConvertFromWebhookEventSqlBean(webhookEventFromDb)

pkg/git/Bean.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ type WebhookDataRequest struct {
210210
}
211211

212212
type WebhookEventConfigRequest struct {
213-
GitHostId int `json:"gitHostId"`
214-
EventId int `json:"eventId"`
213+
GitHostId int `json:"gitHostId"`
214+
EventId int `json:"eventId"`
215+
GitHostName string `json:"GitHostName"`
215216
}
216217

217218
type RefreshGitMaterialRequest struct {
@@ -227,6 +228,7 @@ type RefreshGitMaterialResponse struct {
227228
type WebhookEvent struct {
228229
PayloadId int `json:"payloadId"`
229230
RequestPayloadJson string `json:"requestPayloadJson"`
231+
GitHostName string `json:"gitHostName"`
230232
GitHostId int `json:"gitHostId"`
231233
EventType string `json:"eventType"`
232234
}

pkg/git/WebhookEventService.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030
)
3131

3232
type WebhookEventService interface {
33-
GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*sql.GitHostWebhookEvent, error)
33+
GetAllGitHostWebhookEventByGitHostId(gitHostId int, gitHostName string) ([]*sql.GitHostWebhookEvent, error)
34+
GetAllGitHostWebhookEventByGitHostName(gitHostName string) ([]*sql.GitHostWebhookEvent, error)
3435
GetWebhookParsedEventDataByEventIdAndUniqueId(eventId int, uniqueId string) (*sql.WebhookEventParsedData, error)
3536
SaveWebhookParsedEventData(webhookEventParsedData *sql.WebhookEventParsedData) error
3637
UpdateWebhookParsedEventData(webhookEventParsedData *sql.WebhookEventParsedData) error
@@ -65,9 +66,30 @@ func NewWebhookEventServiceImpl(
6566
}
6667
}
6768

68-
func (impl WebhookEventServiceImpl) GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*sql.GitHostWebhookEvent, error) {
69+
func (impl WebhookEventServiceImpl) GetAllGitHostWebhookEventByGitHostId(gitHostId int, gitHostName string) ([]*sql.GitHostWebhookEvent, error) {
6970
impl.logger.Debugw("Getting All git host events", "gitHostId", gitHostId)
70-
return impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
71+
events, err := impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
72+
if err != nil {
73+
impl.logger.Errorw("Error in getting all webhook events", "err", err)
74+
return nil, err
75+
}
76+
if events != nil && len(events) > 0 && gitHostName != "" {
77+
//handle older events to update git_host_name
78+
for _, event := range events {
79+
if event.GitHostName == "" {
80+
event.GitHostName = gitHostName
81+
err = impl.webhookEventRepository.Update(event)
82+
if err != nil {
83+
impl.logger.Errorw("Error in updating webhook event with git_host_name", "git_host_name", gitHostName, "err", err)
84+
}
85+
}
86+
}
87+
}
88+
return events, nil
89+
}
90+
func (impl WebhookEventServiceImpl) GetAllGitHostWebhookEventByGitHostName(gitHostName string) ([]*sql.GitHostWebhookEvent, error) {
91+
impl.logger.Debugw("Getting All git host events", "gitHostName", gitHostName)
92+
return impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostName(gitHostName)
7193
}
7294

7395
func (impl WebhookEventServiceImpl) GetWebhookParsedEventDataByEventIdAndUniqueId(eventId int, uniqueId string) (*sql.WebhookEventParsedData, error) {

pkg/git/WebhookHandler.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package git
1818

1919
import (
20+
"github.com/devtron-labs/git-sensor/internals/sql"
2021
"go.uber.org/zap"
2122
"strings"
2223
"time"
@@ -44,22 +45,36 @@ func (impl WebhookHandlerImpl) HandleWebhookEvent(webhookEvent *WebhookEvent) er
4445
impl.logger.Debug("Webhook event came")
4546

4647
gitHostId := webhookEvent.GitHostId
48+
gitHostName := webhookEvent.GitHostName
4749
eventType := webhookEvent.EventType
4850
payloadJson := webhookEvent.RequestPayloadJson
4951
payloadId := webhookEvent.PayloadId
5052

5153
impl.logger.Debugw("webhook event request data", "gitHostId", gitHostId, "eventType", eventType)
5254

53-
// get all configured events from database for given git host Id
54-
events, err := impl.webhookEventService.GetAllGitHostWebhookEventByGitHostId(gitHostId)
55-
if err != nil {
56-
impl.logger.Errorw("error in getting webhook events from db", "err", err, "gitHostId", gitHostId)
57-
return err
55+
var events []*sql.GitHostWebhookEvent
56+
var err error
57+
if gitHostName != "" {
58+
// get all configured events from database for given git host Name
59+
events, err = impl.webhookEventService.GetAllGitHostWebhookEventByGitHostName(gitHostName)
60+
if err != nil {
61+
impl.logger.Errorw("error in getting webhook events from db", "err", err, "gitHostId", gitHostId)
62+
return err
63+
}
5864
}
5965

6066
if len(events) == 0 {
61-
impl.logger.Warnw("webhook events not found for given gitHostId ", "gitHostId", gitHostId)
62-
return nil
67+
// retry with gitHostId and get all configured events from database for given git host Id
68+
events, err = impl.webhookEventService.GetAllGitHostWebhookEventByGitHostId(gitHostId, gitHostName)
69+
if err != nil {
70+
impl.logger.Errorw("error in getting webhook events from db", "err", err, "gitHostId", gitHostId)
71+
return err
72+
}
73+
if len(events) == 0 {
74+
impl.logger.Warnw("webhook events not found for given gitHostId ", "gitHostId", gitHostId)
75+
return nil
76+
}
77+
6378
}
6479

6580
// operate for all matching event (match for eventType)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
DELETE FROM git_host_webhook_event_selectors where event_id in (select id from git_host_webhook_event where git_host_name='Gitlab_Devtron' and name in 'Pull Request', 'Tag Creation')
18+
DELETE FROM git_host_webhook_event where git_host_name='Gitlab_Devtron';
19+
ALTER TABLE git_host_webhook_event DROP COLUMN git_host_name;
20+
ALTER TABLE git_host_webhook_event ALTER COLUMN git_host_id SET NOT NULL;

0 commit comments

Comments
 (0)