Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part2: gerrit-translator-cdevents : translate patchset and change source code events #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rjalander
Copy link

This PR includes the changes to translate below Patchset and Change related gerrit events into CDEvents, with the mappings as below

CDEvent Type Gerrit Event Type
dev.cdevents.change.created patchset-created
dev.cdevents.change.updated patchset-created
dev.cdevents.change.reviewed comment-added
dev.cdevents.change.merged change-merged
dev.cdevents.change.abandoned change-abandoned

Note: Implementation as per the design RFC: gerrit-translator-cdevents-plugin and mapping events gerrit-cdevents

Signed-off-by: Jalander Ramagiri @rjalander

Jalander Ramagiri added 4 commits March 19, 2024 16:07
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
@rjalander rjalander requested review from xibz and afrittoli July 4, 2024 09:56
Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
@rjalander
Copy link
Author

@afrittoli @xibz could you please review this PR and share your comments.

Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Copy link

@xibz xibz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of my comments are very nit. So this can be a follow up PR to make it more idiomatic to Go

@@ -76,6 +76,26 @@ func (pEvent *GerritEvent) TranslateIntoCDEvent() (string, error) {
if err != nil {
return "", err
}
case "patchset-created":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These event types should probably be constants as that is more idiomatic to go even if they are only used here.

if refUpdated.RefUpdate.OldRev == "0000000000000000000000000000000000000000" {
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)
return "", errors.New("ignoring translating ref-updated gerrit event")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 0000000000000000000000000000000000000000 a zeroe'd SHA?

We should also make this a constant. My guess is this is sent by gerrit?

}
Log().Info("PatchsetCreated GerritEvent received for project : ", patchsetCreated.Project.Name)
patchsetCreated.RepoURL = pEvent.RepoURL
if patchsetCreated.PatchSet.Number == 1 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we have a lot of logs on the info level. I wonder if we should put some of these, if not most, in debugging.

Also this 1 could be a constant like const PatchSetCreatedNum = 1 or something

Signed-off-by: Jalander Ramagiri <jalander.ramagiri@est.tech>
Copy link
Contributor

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR.
The mapping that is documented in the PR description should also go into some docs for this plugin, so that one can know which event is mapped to what without having to parse the code.
Apart from that, I believe the Info logging includes too much info, if this plugin was processing many events it would be too much, but this is something that could be tuned as a follow-up.

@@ -100,3 +100,103 @@ func (refUpdated *RefUpdated) BranchDeletedCDEvent() (string, error) {
}
return cdEventStr, nil
}

func (patchsetCreated *PatchsetCreated) ChangeCreatedCDEvent() (string, error) {
Log().Info("Creating CDEvent ChangeCreatedEvent")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having Info log level for each event created will spam logs without providing much value as the text is fixed. I would make this Debug and provide at least the event ID in there

if err != nil {
return "", err
}
Log().Info("Translated patchset-created gerrit event into dev.cdevents.change.created CDEvent: ", cdEvent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Info is too much here too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants