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

GitLab events / parsing refactoring #2590

Merged
merged 31 commits into from
Jan 29, 2025

Conversation

mfocko
Copy link
Member

@mfocko mfocko commented Oct 21, 2024

TODO

  • Write new tests or update the old ones to cover new functionality.
  • Update doc-strings where appropriate.
  • Open up follow-up issues.
  • We create instances of abstract classes in tests… I have implemented .event_type() for those with an assertion to check that the tests are actually running…

Comments / questions from the commits

  • Manual caching of the db_project_object, db_project_event and project (currently unimplemented method in superclasses, property that caches to an attribute)
    Comment from the review:
    Are these supposed to be abstract methods?
    Also, if they're abstract (and cached, based on the commits from blame),
    why don't we just use cachedproperty after abstractmethod? Having these
    return ‹None› by default »can« result in unimplemented override somewhere
    down the chain.
    
    • Leaving as is for now, both project_object and project_event are constructed at the same time via one helper function, therefore the caching can't be simply wrapped with a cached_property
    • Ideally drop explicit getters and implement cached abstract properties (even though I recall some issues with type checking that, or it's not very bulletproof…)
  • Event.pre_check returns True by default…
    • after a discussion with @lbarcziova just adding a note why we have chose the specific default there
    • log a warning
    • default to False

Reconsider structuring

  • forge.push.Push (respectively gitlab.push.TagPush) → forge.push.Commit or forge.push.Tag
  • anitya.baseanitya.events (not used directly though, events are exposed via __init__.py as it doesn't make much sense to structure them further)
  • forge.pr.Synchronize doesn't make sense, it is “some kind of an action” on the PR/MR, but Synchronize has been inspired by the GitHub itself (and it's an example of an action on the PR), but I don't have a better name… maybe even forge.pr.Change / forge.pr.Action?
  • Enumerations: there are some enums in events.enums for PR/MRs, comments and FedMsg…
    • Combination of both… as for the PR and comment actions they are shared by GitHub and Pagure, therefore I kept those shared actions in the events.enums, while moving the GitLab enum that's also shared by GitLab-only events to events.gitlab.enums and as for the OpenScanHub, the least disruptive change (since the enum is tied only to the task) to events.openscanhub.task.Status

    • Follow OpenScanHub implementation by Maja: nests the enumerations into the event type itself, which is a possible way, but it looks a bit weird used in code

    • Have a separate module (e.g. openscanhub.enum) for all of them consistently

    • Going from the current change:

      -        if self.event.status == OpenScanHubTaskFinishedEvent.Status.success:
      +        if self.event.status == openscanhub.task.Finished.Status.success:

      I'd probably prefer openscanhub.task.Status.success 👀

Fixes

Supersedes #2586 (cause GitHub is a 🫓)

Merge before/after

@mfocko mfocko self-assigned this Oct 21, 2024
@mfocko mfocko requested a review from a team as a code owner October 21, 2024 12:44
@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from feb7e0e to 9a8f285 Compare October 21, 2024 12:45
Copy link
Contributor

@mfocko
Copy link
Member Author

mfocko commented Oct 21, 2024

@majamassarini @lbarcziova WDYT? At the moment it's broken everywhere possible :D it looks like we have also some pretty intrusive mocking in place, so this reshuffle opened the can of worms…

I still haven't made up my mind about the usage of the events, cause they can be imported as

from packit_service.worker.events.github.pr import Synchronize

but at the same time I have a feeling that it won't look very good once it gets mixed up with the other forges, for now I replaced the imports with as ‹original_name›, so that it breaks as least stuff as possible, but going forward it doesn't feel very feasible… it probably needs a better hierarchy 🤔

@mfocko
Copy link
Member Author

mfocko commented Oct 21, 2024

Tip

I had a feeling something will crawl out, when I make Event an abstract class

packit_service/worker/events/github/installation.py:41: error: Cannot instantiate abstract class "Installation" with abstract attributes "base_project" and "get_packages_config"  [abstract]

Copy link
Contributor

Copy link
Contributor

Copy link
Member

@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

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

the structure looks good to me 🚀

for now I replaced the imports with as ‹original_name›, so that it breaks as least stuff as possible, but going forward it doesn't feel very feasible

agreed it may be a good middle step

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from 97853c1 to 1cd634b Compare October 25, 2024 12:42
Copy link
Contributor

@majamassarini
Copy link
Member

@majamassarini @lbarcziova WDYT? At the moment it's broken everywhere possible :D it looks like we have also some pretty intrusive mocking in place, so this reshuffle opened the can of worms…

I still haven't made up my mind about the usage of the events, cause they can be imported as

from packit_service.worker.events.github.pr import Synchronize

but at the same time I have a feeling that it won't look very good once it gets mixed up with the other forges, for now I replaced the imports with as ‹original_name›, so that it breaks as least stuff as possible, but going forward it doesn't feel very feasible… it probably needs a better hierarchy 🤔

Thanks for starting this big refactoring, to me it looks good!
If I understand your concern, I think in future we should avoid import like this

from packit_service.worker.events.github.pr import Synchronize

and use instead the namespaces we have created

from packit_service.worker.events import github, gitlab, pagure
[...]
github.pr.Synchronize
[...]
gitlab.pr.Synchronize

So I think the hierarchy is fine 🤔

@mfocko
Copy link
Member Author

mfocko commented Oct 28, 2024

Thanks for starting this big refactoring, to me it looks good! If I understand your concern, I think in future we should avoid import like this

from packit_service.worker.events.github.pr import Synchronize

and use instead the namespaces we have created

from packit_service.worker.events import github, gitlab, pagure
[...]
github.pr.Synchronize
[...]
gitlab.pr.Synchronize

So I think the hierarchy is fine 🤔

oh i see, so you really wanna use it like that 😁 I was a bit worried how explicit it will be, but I guess it's better

edit: BTW I managed to break the mypy locally, it crashes :D but passes in Zuul…

Copy link
Contributor

@mfocko mfocko linked an issue Nov 18, 2024 that may be closed by this pull request
8 tasks
@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from 7f6c114 to 3fa459b Compare November 25, 2024 12:51
Copy link
Contributor

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from 3fa459b to f9e813c Compare November 25, 2024 13:06
Copy link
Contributor

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from f9e813c to fee2a38 Compare November 26, 2024 15:53
Copy link
Contributor

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from fee2a38 to e115f0c Compare December 3, 2024 14:07
Copy link
Contributor

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from e115f0c to c0c227d Compare January 6, 2025 11:32
Copy link
Contributor

Copy link
Member

@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

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

I really like how you broke this up into smaller pieces, this is so much more readable, good job!

packit_service/worker/events/event.py Outdated Show resolved Hide resolved
packit_service/worker/events/event.py Outdated Show resolved Hide resolved
packit_service/worker/events/github/installation.py Outdated Show resolved Hide resolved
packit_service/worker/events/koji.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from 8e6af25 to 8346172 Compare January 15, 2025 12:44
Copy link
Contributor

mfocko added 21 commits January 29, 2025 13:43
Signed-off-by: Matej Focko <mfocko@redhat.com>
Add empty lines in between license and the imports to have a consistent
style.

Signed-off-by: Matej Focko <mfocko@redhat.com>
To be consistent with the naming from other modules.

Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Till now we have used ‹.__name__› on the event classes for serialization
for the Celery, but after the refactor the ‹.__name__› contains just the
last name in the whole path (i.e., only the class name is included,
modules are lost) which creates conflicts and also breaks the matching
of serialized ‹event_type› to the respective classes.

Therefore implement a new abstract class method that returns the whole
event type (including the source and any additional subtyping).

Also implement the ‹event_type()› for some of the abstract classes that
are used in the tests, with a check that the tests are running to ensure
that abstract classes are not constructed during the runtime.

Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
When running the tests ‹__class__› resolves to the mock class which
doesn't have correct value, therefore use ‹.event_type()› on the object
itself.

Signed-off-by: Matej Focko <mfocko@redhat.com>
Sign up for the pain and suffering since I refactored it.

Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
As discussed in the PR introducing this refactor, switch from not very
descriptive ‹push.Push› to ‹push.Commit› and in case of GitLab events
also ‹push.TagPush› to ‹push.Tag›.

Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from 620fce8 to 6c6fe8e Compare January 29, 2025 12:44
Copy link
Contributor

Suggested-by: Laura Barcziová <lbarczio@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Copy link
Contributor

Co-authored-by: Laura Barcziová <lbarczio@redhat.com>
Signed-off-by: Matej Focko <mfocko@redhat.com>
Copy link
Contributor

@mfocko mfocko added the mergeit When set, zuul wil gate and merge the PR. label Jan 29, 2025
Copy link
Contributor

Build succeeded (gate pipeline).
https://softwarefactory-project.io/zuul/t/packit-service/buildset/c87cdcd5a3814b269ee3a1d131443b9b

✔️ pre-commit SUCCESS in 1m 48s

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit bcaa612 into packit:main Jan 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit When set, zuul wil gate and merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prepare and refactor events/parsers for CentOS Stream dist-git comments
3 participants