Skip to content

Conversation

@mynk8
Copy link

@mynk8 mynk8 commented Sep 24, 2025

TODO:

  • Write new tests or update the old ones to cover new functionality.
  • Update doc-strings where appropriate.

Merge before/after

  • Fedora 43 release

RELEASE NOTES BEGIN

  • Add forgejo event support pr.Action, pr.Comment, issue.Comment, push.Commit in `events.

RELEASE NOTES END

@mynk8 mynk8 requested a review from a team as a code owner September 24, 2025 13:42
@mynk8 mynk8 changed the title Rebase/forgejo Implement events support for Forgejo Sep 24, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mynk8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the service's compatibility by adding full support for Forgejo, a self-hosted Git service. It enables the system to receive, parse, and react to various Forgejo events, such as pull request actions, issue comments, and code pushes, and to report statuses back to Forgejo repositories. This integration broadens the range of Git platforms the service can interact with.

Highlights

  • Forgejo Event Support: Introduced comprehensive support for Forgejo events, including pr.Action, pr.Comment, issue.Comment, and push.Commit.
  • New Webhook Endpoint: Added a dedicated /forgejo webhook endpoint to process incoming Forgejo events, complete with signature validation.
  • Event Parsing and Handling: Implemented new event classes and parsing logic specifically for Forgejo pull requests, issue comments, and push events, ensuring proper discrimination from GitHub events.
  • Status Reporting Integration: Integrated Forgejo into the status reporting mechanism, allowing the service to set commit statuses on Forgejo projects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mynk8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the platform's compatibility by adding full event support for Forgejo, a free, open-source, community-driven forge. It introduces the necessary infrastructure to listen for, parse, and react to various events from Forgejo repositories, including pull request activities, issue comments, and code pushes. This integration allows the system to seamlessly interact with projects hosted on Forgejo, mirroring the functionality already available for other Git platforms.

Highlights

  • Forgejo Event Support: Introduced comprehensive support for Forgejo events, enabling the system to process pull request actions, pull request comments, issue comments, and push events from Forgejo repositories.
  • New Webhook Endpoint: Added a dedicated /forgejo webhook endpoint to receive and process events originating from Forgejo instances, including signature validation.
  • Event Parsing Logic: Implemented new parser methods (parse_forgejo_push_event, parse_forgejo_pr_event, parse_forgejo_comment_event) to correctly interpret Forgejo webhook payloads and convert them into internal event objects.
  • Status Reporting Integration: Integrated Forgejo into the status reporting mechanism, allowing the system to set commit statuses on Forgejo pull requests and commits, and handle API exceptions gracefully by adding comments.
  • Abstract Event Classes: Created Forgejo-specific event classes (ForgejoEvent, pr.Action, pr.Comment, issue.Comment, push.Commit) to encapsulate the structure and data of various Forgejo events.
  • GitHub Event Parser Refinement: Modified existing GitHub event parsers to explicitly skip events originating from Forgejo, preventing misinterpretation and ensuring proper event routing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Forgejo events, including a new webhook endpoint, event classes, and parsing logic. The implementation is comprehensive, covering PR actions, comments, and pushes. I've identified a couple of critical issues that will cause runtime errors, related to undefined variables in the new webhook endpoint. Additionally, there are opportunities to improve performance by passing more data during event instantiation to avoid later API calls, and to enhance robustness by using a more reliable method for distinguishing Forgejo events. I've also included some minor suggestions for code style and consistency.

@mynk8
Copy link
Author

mynk8 commented Sep 24, 2025

Would like to ask, Is there an alternative to mocking the Project object from ServiceConfig?

@softwarefactory-project-zuul
Copy link
Contributor

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Forgejo events, including pull requests, issue comments, and pushes. It adds new event classes, a webhook endpoint, and parsers for Forgejo payloads. The implementation is comprehensive, with new logic for handling Forgejo's specific event structure and new tests to cover the functionality. My review focuses on a few critical issues, such as missing variable definitions that would cause runtime errors, and some suggestions for improving the robustness and maintainability of the event parsing logic.

@softwarefactory-project-zuul
Copy link
Contributor

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Forgejo webhooks, including events for pull requests, issues, and pushes. The implementation includes new event classes, a webhook endpoint, and parsing logic. The changes are well-structured and include comprehensive tests.

I've found a critical security vulnerability where the Forgejo webhook signature is not being validated, and another high-severity issue with incomplete validation logic. I've also pointed out a medium-severity issue regarding redundant code in the event parser.

My review comments provide suggestions to fix these issues. Once addressed, this will be a great addition.

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@betulependule
Copy link

This is probably just a nitpick, but this docstring should probably be edited to mention Forgejo webhooks, not just GitHub and GitLab. I would just add Forgejo inside the brackets so that it says: (GitHub/GitLab/Forgejo webhook).

class Parser:
"""
Once we receive a new event (GitHub/GitLab webhook) for every event
we need to have method inside the `Parser` class to create objects defined in `event.py`.
"""

@gotmax23 gotmax23 mentioned this pull request Oct 10, 2025
5 tasks
Copy link
Member

@mfocko mfocko left a comment

Choose a reason for hiding this comment

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

Apart from the commit history and some minor issues, looks OK to me :)

tag_name: str = "",
comment_object: Optional[Comment] = None,
dist_git_project_url=None,
commit_sha: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

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

How come this got in:

include unit tests for forgejo event; fixes

😄

class ForgejoEvent(ForgeIndependent):
def __init__(self, project_url: str, pr_id: Optional[int] = None, **kwargs):
super().__init__(pr_id=pr_id)
super().__init__(pr_id=pr_id, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Why? Just an FYI, this can cause issues.

Copy link
Author

Choose a reason for hiding this comment

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

that was so that I could pass actor and other parameters into the event, not anymore. corrected it.

Comment on lines 40 to 44
self.commit_sha_before = commit_sha_before
self.actor = actor
self.identifier = str(pr_id)
self._pr_id = pr_id
self.git_ref = None # use pr_id for checkout
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure about removing all of these? You left the arguments in the constructor, but you do not use them.

"description", "visibility", "followers_count",
"following_count", "starred_repos_count", "username"
}
return any(field in user_obj for field in forgejo_fields)
Copy link
Member

Choose a reason for hiding this comment

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

Since you're using any, I assume those are the Forgejo-unique fields?

logger.warning("No event to process!")
return None

# Check if this is a Forgejo event and prioritize Forgejo parsers
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this… This would make sense, if majority of the events would come from Forgejo instances; this way you are basically putting Forgejo at the top1, so it gets prioritised overall…

The best way would be for us to collect metrics on what we parse and sort it from most frequent to least frequent events… I'll probably open up a follow-up issue for this, it could definitely help with SLO1 and responsiveness issues we've been having recently.

Cc @packit/the-packit-team
Related to #2854

Footnotes

  1. at least there's that one helper _is_forgejo_event(), but when you get bunch of events, it will add up…

Choose a reason for hiding this comment

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

Yes, I am also confused by the need to prioritise Forgejo parsers in particular.

Copy link
Author

@mynk8 mynk8 Oct 16, 2025

Choose a reason for hiding this comment

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

The structure of webhook payload was similar to that of github, some events would mistakenly get passed as github objects, in tests as well. I think the logic is wrong to fix that and maybe determine the type of forge from the HTTP headers at service level instead? but that would break tests and I think not the best way out.

Choose a reason for hiding this comment

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

I see. If we don't find a better way to solve this, there should probably be a comment added to explain why the Forgejo parsers are being prioritized so that it's clear in the future. @mfocko, what do you think?

Copy link

@betulependule betulependule left a comment

Choose a reason for hiding this comment

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

Overall, it looks good to me so far. I didn't find any other issues other than what @mfocko has pointed out already. Just regarding the tests, it would be good for consistency to add ForgejoService in this conftest.py file.

@pytest.fixture(autouse=True)
def global_service_config():
"""
This config will be used instead of the one loaded from the local config file.
You can still mock/overwrite the service config content in your tests
but this one will be used by default.
You can also (re)define some values like this:
ServiceConfig.get_service_config().attribute = "value"
"""
service_config = ServiceConfig()
service_config.fas_user = "packit"
service_config.services = {
GithubService(token="token"),
GitlabService(token="token"),
PagureService(instance_url="https://src.fedoraproject.org", token="token"),
PagureService(instance_url="https://git.stg.centos.org", token="6789"),
}

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@mynk8
Copy link
Author

mynk8 commented Oct 21, 2025

my bad. rebasing...

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

Update packit_service/worker/reporting/reporters/base.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

Update packit_service/service/api/webhooks.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

Update packit_service/worker/parser.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

Update packit_service/events/forgejo/pr.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

pre-commit and mypy fixes

test(data): add Forgejo webhooks for tests

include unit tests for forgejo event; fixes

add check for prioritising Forgejo before parsing events; fixes

pre-commit

remove redundant entries in parser list; fix bug

Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

implement validate_token for ForgejoWebhooks; correct the pr.Action impl for Forgejo; fix a problem in parser that could have caused keynotfound errors.

implement validate_token for ForgejoWebhooks; correct the pr.Action impl for Forgejo; fix a problem in parser that could have caused keynotfound errors.

Implement Forgejo event handling in Packit Service.
@softwarefactory-project-zuul
Copy link
Contributor

@mynk8
Copy link
Author

mynk8 commented Oct 21, 2025

pre-commit tests failing due to:

An unexpected error has occurred: CalledProcessError: command: ('/home/zuul-worker/.cache/pre-commit/repo5ifl3exm/node_env-default/bin/node', '/home/zuul-worker/.cache/pre-commit/repo5ifl3exm/node_env-default/bin/npm', 'install', '--include=dev', '--include=prod', '--ignore-prepublish', '--no-progress', '--no-save')
return code: 127
stdout: (none)
stderr:
    /home/zuul-worker/.cache/pre-commit/repo5ifl3exm/node_env-default/bin/node: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory
Check the log at /home/zuul-worker/.cache/pre-commit/pre-commit.log

and tests due to problem communicating with pagure. for

FAILED tests/unit/events/test_koji.py::test_parse_koji_build_event_start_old_format
FAILED tests/integration/test_dg_commit.py::test_precheck_koji_build_push_pr[packit-allowed_pr_authors0-True]

@majamassarini
Copy link
Member

recheck

@softwarefactory-project-zuul
Copy link
Contributor

@mynk8
Copy link
Author

mynk8 commented Oct 30, 2025

recheck

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@mynk8
Copy link
Author

mynk8 commented Oct 30, 2025

recheck

@mynk8
Copy link
Author

mynk8 commented Oct 30, 2025

wait, didn't notice till now but some tests are randomly failing due to Pagure returning a 503

FAILED tests/unit/test_checkers.py::test_run_condition[JobType.koji_build-JobConfigTriggerType.commit-koji_build_retrigger_pr_comment-None-True-False]
FAILED tests/unit/test_checkers.py::test_run_condition[JobType.koji_build-JobConfigTriggerType.commit-koji_build_retrigger_pr_comment-None-True-True]

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: new

Development

Successfully merging this pull request may close these issues.

4 participants