Skip to content

Commit 8fc0bb1

Browse files
Manish AgrawalManish Agrawal
Manish Agrawal
authored and
Manish Agrawal
committed
removing saving webhook data from git-sensor
some selector change fix value
1 parent 9a3b65c commit 8fc0bb1

12 files changed

+65
-80
lines changed

internal/sql/WebhookEventDataRepository.go

-47
This file was deleted.

internal/sql/WebhookEventParsedDataRepository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (impl WebhookEventParsedDataRepositoryImpl) GetWebhookEventParsedDataByIds(
7575
var webhookEventParsedData []*WebhookEventParsedData
7676
err := impl.dbConnection.Model(&webhookEventParsedData).
7777
Where("id in (?) ", pg.In(ids)).
78-
Order("updated_on Desc").
78+
Order("created_on Desc").
7979
Limit(limit).
8080
Select()
8181
return webhookEventParsedData, err

internal/sql/WebhookEventRepository.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type GitHostWebhookEventSelectors struct {
4444
Selector string `sql:"selector,notnull"`
4545
ToShow bool `sql:"to_show,notnull"`
4646
ToShowInCiFilter bool `sql:"to_show_in_ci_filter,notnull"`
47+
FixValue string `sql:"fix_value"`
4748
PossibleValues string `sql:"possible_values"`
4849
IsActive bool `sql:"is_active,notnull"`
4950
CreatedOn time.Time `sql:"created_on,notnull"`

pkg/RepoManages.go

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ func (impl RepoManagerImpl) FetchGitCommitsForBranchFixPipeline(pipelineMaterial
416416
func (impl RepoManagerImpl) FetchGitCommitsForWebhookTypePipeline(pipelineMaterial *sql.CiPipelineMaterial, gitMaterial *sql.GitMaterial) (*git.MaterialChangeResp, error) {
417417
response := &git.MaterialChangeResp{}
418418
response.LastFetchTime = gitMaterial.LastFetchTime
419+
if pipelineMaterial.Errored && !gitMaterial.CheckoutStatus {
420+
response.IsRepoError = true
421+
response.RepoErrorMsg = gitMaterial.FetchErrorMessage
422+
return response, nil
423+
}
419424

420425
pipelineMaterialId := pipelineMaterial.Id
421426
webhookMappings, err := impl.webhookEventDataMappingRepository.GetCiPipelineMaterialWebhookDataMappingForPipelineMaterial(pipelineMaterialId)

pkg/git/Bean.go

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type WebhookEventSelectors struct {
123123
Selector string `json:"selector"`
124124
ToShow bool `json:"toShow"`
125125
ToShowInCiFilter bool `json:"toShowInCiFilter"`
126+
FixValue string `json:"fixValue"`
126127
PossibleValues string `json:"possibleValues"`
127128
IsActive bool `json:"isActive"`
128129
CreatedOn time.Time `json:"createdOn"`

pkg/git/WebhookEventBeanConverter.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (impl WebhookEventBeanConverterImpl) ConvertFromWebhookEventSqlBean(webhook
6565
Selector: selectorFromDb.Selector,
6666
ToShow: selectorFromDb.ToShow,
6767
ToShowInCiFilter: selectorFromDb.ToShowInCiFilter,
68+
FixValue: selectorFromDb.FixValue,
6869
PossibleValues: selectorFromDb.PossibleValues,
6970
IsActive: selectorFromDb.IsActive,
7071
CreatedOn: selectorFromDb.CreatedOn,

pkg/git/WebhookEventService.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030

3131
type WebhookEventService interface {
3232
GetAllGitHostWebhookEventByGitHostId(gitHostId int) ([]*sql.GitHostWebhookEvent, error)
33-
SaveWebhookEventData(webhookEventData *sql.WebhookEventData) error
3433
GetWebhookParsedEventDataByEventIdAndUniqueId(eventId int, uniqueId string) (*sql.WebhookEventParsedData, error)
3534
SaveWebhookParsedEventData(webhookEventParsedData *sql.WebhookEventParsedData) error
3635
UpdateWebhookParsedEventData(webhookEventParsedData *sql.WebhookEventParsedData) error
@@ -40,7 +39,6 @@ type WebhookEventService interface {
4039
type WebhookEventServiceImpl struct {
4140
logger *zap.SugaredLogger
4241
webhookEventRepository sql.WebhookEventRepository
43-
webhookEventDataRepository sql.WebhookEventDataRepository
4442
webhookEventParsedDataRepository sql.WebhookEventParsedDataRepository
4543
webhookEventDataMappingRepository sql.WebhookEventDataMappingRepository
4644
materialRepository sql.MaterialRepository
@@ -49,13 +47,12 @@ type WebhookEventServiceImpl struct {
4947
}
5048

5149
func NewWebhookEventServiceImpl(
52-
logger *zap.SugaredLogger, webhookEventRepository sql.WebhookEventRepository, webhookEventDataRepository sql.WebhookEventDataRepository, webhookEventParsedDataRepository sql.WebhookEventParsedDataRepository,
50+
logger *zap.SugaredLogger, webhookEventRepository sql.WebhookEventRepository, webhookEventParsedDataRepository sql.WebhookEventParsedDataRepository,
5351
webhookEventDataMappingRepository sql.WebhookEventDataMappingRepository, materialRepository sql.MaterialRepository, nats stan.Conn, webhookEventBeanConverter WebhookEventBeanConverter,
5452
) *WebhookEventServiceImpl {
5553
return &WebhookEventServiceImpl{
5654
logger: logger,
5755
webhookEventRepository: webhookEventRepository,
58-
webhookEventDataRepository: webhookEventDataRepository,
5956
webhookEventParsedDataRepository: webhookEventParsedDataRepository,
6057
webhookEventDataMappingRepository: webhookEventDataMappingRepository,
6158
materialRepository: materialRepository,
@@ -69,16 +66,6 @@ func (impl WebhookEventServiceImpl) GetAllGitHostWebhookEventByGitHostId(gitHost
6966
return impl.webhookEventRepository.GetAllGitHostWebhookEventByGitHostId(gitHostId)
7067
}
7168

72-
func (impl WebhookEventServiceImpl) SaveWebhookEventData(webhookEventData *sql.WebhookEventData) error {
73-
impl.logger.Debug("Saving webhook event data")
74-
err := impl.webhookEventDataRepository.SaveWebhookEventData(webhookEventData)
75-
if err != nil {
76-
impl.logger.Errorw("error in saving webhook event data in db", "err", err)
77-
return err
78-
}
79-
return nil
80-
}
81-
8269
func (impl WebhookEventServiceImpl) GetWebhookParsedEventDataByEventIdAndUniqueId(eventId int, uniqueId string) (*sql.WebhookEventParsedData, error) {
8370
impl.logger.Debugw("fetching webhook event parsed data for ", "eventId", eventId, "uniqueId", uniqueId)
8471

pkg/git/WebhookHandler.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package git
1919

2020
import (
21-
"github.com/devtron-labs/git-sensor/internal/sql"
2221
"go.uber.org/zap"
2322
"strings"
2423
"time"
@@ -72,19 +71,7 @@ func (impl WebhookHandlerImpl) HandleWebhookEvent(webhookEvent *WebhookEvent) er
7271
}
7372

7473
eventId := event.Id
75-
76-
// store in audit json table
77-
webhookEventData := &sql.WebhookEventData{
78-
EventId: eventId,
79-
PayloadJson: payloadJson,
80-
CreatedOn: time.Now(),
81-
}
82-
err := impl.webhookEventService.SaveWebhookEventData(webhookEventData)
83-
if err != nil {
84-
impl.logger.Errorw("error in saving webhook event data in db", "err", err)
85-
return err
86-
}
87-
74+
8875
// parse event data using selectors
8976
webhookEventParsedData, fullDataMap, err := impl.webhookEventParser.ParseEvent(event.Selectors, payloadJson)
9077
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--- drop column fix_value in git_host_webhook_event_selectors table
2+
alter table git_host_webhook_event_selectors
3+
drop column fix_value;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- add column fix_value in git_host_webhook_event_selectors table
2+
alter table git_host_webhook_event_selectors
3+
add column fix_value character varying(1000);
4+
5+
--- set fix_value for github pull_request state
6+
update git_host_webhook_event_selectors
7+
set fix_value = '^open$'
8+
where event_id = 1
9+
and name = 'state';
10+
11+
12+
--- set fix_value for bitbucket pull_request state
13+
update git_host_webhook_event_selectors
14+
set fix_value = '^OPEN$'
15+
where event_id = 2
16+
and name = 'state';
17+
18+
19+
--- set fix_value for github tag creation identifier ref_type
20+
update git_host_webhook_event_selectors
21+
set fix_value = '^tag$'
22+
where event_id = 3
23+
and name = 'tag creation identifier';
24+
25+
26+
--- set fix_value for bitbucket tag creation identifier ref_type
27+
update git_host_webhook_event_selectors
28+
set fix_value = '^tag$'
29+
where event_id = 4
30+
and name = 'tag creation identifier';
31+
32+
33+
--- set selector created_at instead of updated_at for date for PR github
34+
update git_host_webhook_event_selectors
35+
set selector = 'pull_request.created_at'
36+
where event_id = 1
37+
and name = 'date';
38+
39+
40+
--- set selector created_at instead of updated_at for date for PR bitbucket
41+
update git_host_webhook_event_selectors
42+
set selector = 'pullrequest.created_on'
43+
where event_id = 2
44+
and name = 'date';
45+
46+
---- drop table webhook_event_data as moved to orchestrator
47+
DROP TABLE IF EXISTS public.webhook_event_data;
48+
49+
---- DROP sequence as moved to orchestrator
50+
DROP SEQUENCE IF EXISTS public.webhook_event_data_id_seq;

wire.go

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ func InitializeApp() (*App, error) {
5555
git.NewGitUtil,
5656
sql.NewWebhookEventRepositoryImpl,
5757
wire.Bind(new(sql.WebhookEventRepository), new(*sql.WebhookEventRepositoryImpl)),
58-
sql.NewWebhookEventDataRepositoryImpl,
59-
wire.Bind(new(sql.WebhookEventDataRepository), new(*sql.WebhookEventDataRepositoryImpl)),
6058
sql.NewWebhookEventParsedDataRepositoryImpl,
6159
wire.Bind(new(sql.WebhookEventParsedDataRepository), new(*sql.WebhookEventParsedDataRepositoryImpl)),
6260
sql.NewWebhookEventDataMappingRepositoryImpl,

wire_gen.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)