Skip to content

Commit

Permalink
fix review comments constants and logs
Browse files Browse the repository at this point in the history
Signed-off-by: Jalander Ramagiri <[email protected]>
  • Loading branch information
Jalander Ramagiri committed Aug 23, 2024
1 parent 8ca1fb5 commit 91d6a0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
15 changes: 15 additions & 0 deletions pkg/gerrit/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gerrit

const (
ProjectCreatedEventType = "project-created"
RefUpdatedEventType = "ref-updated"
ProjectUpdatedEventType = "project-head-updated"
PatchsetCreatedEventType = "patchset-created"
CommentAddedEventType = "comment-added"
ChangeMergedEventType = "change-merged"
ChangeAbandonedEventType = "change-abandoned"

ZeroedSha = "0000000000000000000000000000000000000000"

PatchSetCreatedNum = 1
)
18 changes: 9 additions & 9 deletions pkg/gerrit/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewGerritEvent(event string, repoURL string) (pEvent *GerritEvent) {
}

func HandleTranslateGerritEvent(event string, header http.Header) (string, error) {
Log().Info("Handle translation into CDEvent from Gerrit event %s\n", event)
Log().Debug("Handle translation into CDEvent from Gerrit event %s\n", event)
repoURL := ""
if header.Get("X-Origin-Url") != "" {
repoURL = header.Get("X-Origin-Url")
Expand All @@ -45,7 +45,7 @@ func HandleTranslateGerritEvent(event string, header http.Header) (string, error
Log().Error("Error translating Gerrit event into CDEvent %s\n", err)
return "", err
}
Log().Info("Gerrit Event translated into CDEvent %s\n", cdEvent)
Log().Debug("Gerrit Event translated into CDEvent %s\n", cdEvent)
return cdEvent, nil
}

Expand All @@ -61,37 +61,37 @@ func (pEvent *GerritEvent) TranslateIntoCDEvent() (string, error) {
Log().Info("handling translating to CDEvent from Gerrit Event type: %s\n", eventType)

switch eventType {
case "project-created":
case ProjectCreatedEventType:
cdEvent, err = pEvent.HandleProjectCreatedEvent()
if err != nil {
return "", err
}
case "ref-updated":
case RefUpdatedEventType:
cdEvent, err = pEvent.HandleRefUpdatedEvent()
if err != nil {
return "", err
}
case "project-head-updated":
case ProjectUpdatedEventType:
cdEvent, err = pEvent.HandleProjectHeadUpdatedEvent()
if err != nil {
return "", err
}
case "patchset-created":
case PatchsetCreatedEventType:
cdEvent, err = pEvent.HandlePatchsetCreatedEvent()
if err != nil {
return "", err
}
case "comment-added":
case CommentAddedEventType:
cdEvent, err = pEvent.HandleCommentAddedEvent()
if err != nil {
return "", err
}
case "change-merged":
case ChangeMergedEventType:
cdEvent, err = pEvent.HandleChangeMergedEvent()
if err != nil {
return "", err
}
case "change-abandoned":
case ChangeAbandonedEventType:
cdEvent, err = pEvent.HandleChangeAbandonedEvent()
if err != nil {
return "", err
Expand Down
24 changes: 12 additions & 12 deletions pkg/gerrit/translate_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (pEvent *GerritEvent) HandleProjectCreatedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into ProjectCreated struct", err)
return "", err
}
Log().Info("ProjectCreated GerritEvent received : ", projectCreated.ProjectName, projectCreated.HeadName, projectCreated.CommonFields.Type)
Log().Debug("ProjectCreated GerritEvent received : ", projectCreated.ProjectName, projectCreated.HeadName, projectCreated.CommonFields.Type)
projectCreated.RepoURL = pEvent.RepoURL
cdEvent, err := projectCreated.RepositoryCreatedCDEvent()
if err != nil {
Expand All @@ -47,7 +47,7 @@ func (pEvent *GerritEvent) HandleProjectHeadUpdatedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into ProjectHeadUpdated struct", err)
return "", err
}
Log().Info("ProjectHeadUpdated GerritEvent received for project : ", projectHeadUpdated.ProjectName)
Log().Debug("ProjectHeadUpdated GerritEvent received for project : ", projectHeadUpdated.ProjectName)
projectHeadUpdated.RepoURL = pEvent.RepoURL
cdEvent, err := projectHeadUpdated.RepositoryModifiedCDEvent()
if err != nil {
Expand All @@ -65,25 +65,25 @@ func (pEvent *GerritEvent) HandleRefUpdatedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into RefUpdated struct", err)
return "", err
}
Log().Info("RefUpdated GerritEvent received : ", refUpdated.RefUpdate.RefName, refUpdated.Submitter.Name, refUpdated.CommonFields.Type)
Log().Debug("RefUpdated GerritEvent received : ", refUpdated.RefUpdate.RefName, refUpdated.Submitter.Name, refUpdated.CommonFields.Type)
refUpdated.RepoURL = pEvent.RepoURL
if strings.Contains(refUpdated.RefUpdate.RefName, "refs/changes") {
Log().Info("Ignoring handling ref-updated gerrit event as this is followed by patchset/change events: ", refUpdated)
Log().Debug("Ignoring handling ref-updated gerrit event as this is followed by patchset/change events: ", refUpdated)
return "", errors.New("ignoring translating ref-updated gerrit event")
} else if refUpdated.RefUpdate.OldRev == "0000000000000000000000000000000000000000" {
} else if refUpdated.RefUpdate.OldRev == ZeroedSha {
cdEvent, err = refUpdated.BranchCreatedCDEvent()
if err != nil {
return "", err
}
Log().Info("Translated ref-updated gerrit event into dev.cdevents.branch.created CDEvent: ", cdEvent)
} else if refUpdated.RefUpdate.NewRev == "0000000000000000000000000000000000000000" {
} else if refUpdated.RefUpdate.NewRev == ZeroedSha {
cdEvent, err = refUpdated.BranchDeletedCDEvent()
if err != nil {
return "", err
}
Log().Info("Translated ref-updated gerrit event into dev.cdevents.branch.deleted CDEvent: ", cdEvent)
} else {
Log().Info("Ignoring handling ref-updated gerrit event for refName : ", refUpdated.RefUpdate.RefName)
Log().Debug("Ignoring handling ref-updated gerrit event for refName : ", refUpdated.RefUpdate.RefName)
return "", errors.New("ignoring translating ref-updated gerrit event")
}

Expand All @@ -98,9 +98,9 @@ func (pEvent *GerritEvent) HandlePatchsetCreatedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into PatchsetCreated struct", err)
return "", err
}
Log().Info("PatchsetCreated GerritEvent received for project : ", patchsetCreated.Project.Name)
Log().Debug("PatchsetCreated GerritEvent received for project : ", patchsetCreated.Project.Name)
patchsetCreated.RepoURL = pEvent.RepoURL
if patchsetCreated.PatchSet.Number == 1 {
if patchsetCreated.PatchSet.Number == PatchSetCreatedNum {
cdEvent, err = patchsetCreated.ChangeCreatedCDEvent()
if err != nil {
return "", err
Expand All @@ -124,7 +124,7 @@ func (pEvent *GerritEvent) HandleCommentAddedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into CommentAdded struct", err)
return "", err
}
Log().Info("CommentAdded GerritEvent received for project : ", commentAdded.Project.Name)
Log().Debug("CommentAdded GerritEvent received for project : ", commentAdded.Project.Name)
commentAdded.RepoURL = pEvent.RepoURL
cdEvent, err := commentAdded.ChangeReviewedCDEvent()
if err != nil {
Expand All @@ -140,7 +140,7 @@ func (pEvent *GerritEvent) HandleChangeMergedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into ChangeMerged struct", err)
return "", err
}
Log().Info("ChangeMerged GerritEvent received for project : ", changeMerged.Project.Name)
Log().Debug("ChangeMerged GerritEvent received for project : ", changeMerged.Project.Name)
changeMerged.RepoURL = pEvent.RepoURL
cdEvent, err := changeMerged.ChangeMergedCDEvent()
if err != nil {
Expand All @@ -157,7 +157,7 @@ func (pEvent *GerritEvent) HandleChangeAbandonedEvent() (string, error) {
Log().Error("Error occurred while Unmarshal GerritEvent into ChangeAbandoned struct", err)
return "", err
}
Log().Info("ChangeAbandoned GerritEvent received for project : ", changeAbandoned.Project.Name)
Log().Debug("ChangeAbandoned GerritEvent received for project : ", changeAbandoned.Project.Name)
changeAbandoned.RepoURL = pEvent.RepoURL
cdEvent, err := changeAbandoned.ChangeAbandonedCDEvent()
if err != nil {
Expand Down

0 comments on commit 91d6a0a

Please sign in to comment.