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

Draft: GitLab events / parsing refactoring #2586

Closed
wants to merge 0 commits into from

Conversation

mfocko
Copy link
Member

@mfocko mfocko commented Oct 17, 2024

TODO:

  • Write new tests or update the old ones to cover new functionality.
  • Update doc-strings where appropriate.
  • Update or write new documentation in packit/packit.dev.
  • ‹fill in›

Fixes #2471

Related to

Merge before/after

RELEASE NOTES BEGIN

Packit now supports automatic ordering of ☕ after all checks pass.

RELEASE NOTES END

@mfocko mfocko requested a review from a team as a code owner October 17, 2024 09:47
@mfocko mfocko marked this pull request as draft October 17, 2024 09:47
Copy link
Contributor

majamassarini
majamassarini previously approved these changes Oct 17, 2024
Copy link
Member

@majamassarini majamassarini left a comment

Choose a reason for hiding this comment

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

Thank you 🙏🏻
Looking at this I think I would like to have more namespaces in our code. I would like to have github.PullRequestEvent or even better event.github.PullRequest instead of GithubPullRequestEvent. I don't know what others think about it and I don't know if this could be the right moment for such a big refactoring... but still I think it would be nicer 🙂

@majamassarini majamassarini self-requested a review October 17, 2024 10:13
@majamassarini majamassarini dismissed their stale review October 17, 2024 10:14

Sorry I didn't realize it was still a draft.

@majamassarini majamassarini removed their request for review October 17, 2024 10:15
@mfocko
Copy link
Member Author

mfocko commented Oct 17, 2024

Thank you 🙏🏻 Looking at this I think I would like to have more namespaces in our code. I would like to have github.PullRequestEvent or even better event.github.PullRequest instead of GithubPullRequestEvent. I don't know what others think about it and I don't know if this could be the right moment for such a big refactoring... but still I think it would be nicer 🙂

I'm thinking about it too :D and I will need to do some changes around anyways, so… the biggest issue is fixing the imports afterwards :D

@mfocko
Copy link
Member Author

mfocko commented Oct 17, 2024

I'm thinking about it too :D and I will need to do some changes around anyways, so… the biggest issue is fixing the imports afterwards :D

I think it will break everything, so… let's do it \o/

@mfocko
Copy link
Member Author

mfocko commented Oct 17, 2024

How about…

packit_service.worker.events
|- abstract
|  |- AbstractForgeIndependentEvent
|  `- AbstractResultEvent
|- github
|  |- abstract
|  |  `- AbstractGithubEvent
|  |- pull_request
|  |  |- Comment
|  |  `- Update # ← not sure here, right now it's just PullRequestGithubEvent, covers create and push
…

@lbarcziova @majamassarini @packit/the-packit-team

The bigger issue how to fit the downstream events in there… Do they even count as downstream-only if they come from both GitLab and Pagure? It almost feels like there should be two parsers (parsing Fedora Messaging event) returning the same type (downstream event) regardless of whether it's from GitLab or Pagure. We shouldn't even care about this…

I don't want to add another layer of events.upstream.github.… (#матрёшка) :/

@lbarcziova
Copy link
Member

It almost feels like there should be two parsers (parsing Fedora Messaging event) returning the same type (downstream event) regardless of whether it's from GitLab or Pagure.

you are right, this is probably how it should be done the most correctly

but otherwise the proposal looks good to me! Is it manageable to have it like that considering your note about upstream vs downstream? @mfocko

@mfocko
Copy link
Member Author

mfocko commented Oct 18, 2024

you are right, this is probably how it should be done the most correctly

but otherwise the proposal looks good to me! Is it manageable to have it like that considering your note about upstream vs downstream? @mfocko

maybe

• packit_service.worker.events
  • copr
  • openscanhub
  • downstream
  • github
  • gitlab

?

I think that for the beginning I could just rename Pagure to downstream (hide the fact it's pagure) and try to make it more abstract for supporting GitLab (or potentially Forgejo too, if and when Fedora migrates)

@mfocko mfocko closed this Oct 18, 2024
@mfocko mfocko force-pushed the fix/gitlab-dg-events branch from a472ed8 to 89c111a Compare October 18, 2024 12:59
Copy link
Contributor

@mfocko
Copy link
Member Author

mfocko commented Oct 18, 2024

GitHub PLEASE /o

@mfocko mfocko mentioned this pull request Oct 21, 2024
19 tasks
softwarefactory-project-zuul bot added a commit that referenced this pull request Jan 29, 2025
GitLab events / parsing refactoring

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.base → anitya.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

Reviewed-by: Laura Barcziová
Reviewed-by: Maja Massarini
Reviewed-by: Matej Focko
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.

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