-
Notifications
You must be signed in to change notification settings - Fork 56
Add GitPullRequestHelpHandler class #2853
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
base: main
Are you sure you want to change the base?
Conversation
|
Build succeeded. ✔️ pre-commit SUCCESS in 1m 57s |
457d872 to
7cb22ab
Compare
|
Build failed. ❌ pre-commit FAILURE in 1m 43s |
|
Build failed. ✔️ pre-commit SUCCESS in 1m 48s |
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR introduces a new handler for the help command in PR comments, which is a great addition for user experience. The implementation is straightforward and follows existing patterns in the codebase. The changes are well-contained and include corresponding tests.
I've left a few comments with suggestions for improvement, mainly around code clarity, maintainability, and a potential thread-safety issue in the planned implementation. Once the dependent PR is merged and the commented-out code is enabled, the suggestion regarding thread-safety will be particularly important to address.
Overall, this is a solid contribution.
|
Build failed. ✔️ pre-commit SUCCESS in 1m 48s |
|
Build failed. ❌ pre-commit FAILURE in 1m 49s |
6e25b11 to
efb691b
Compare
|
Build succeeded. ✔️ pre-commit SUCCESS in 1m 46s |
|
Build succeeded. ✔️ pre-commit SUCCESS in 2m 13s |
|
/gemini review |
There was a problem hiding this 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 a new GitPullRequestHelpHandler to respond to /packit help commands in pull request comments. The implementation is well-structured, adding the necessary handler, task, and event routing. The changes also include integration tests for the new functionality on GitHub and Pagure.
My review focuses on improving the robustness of the command detection logic. I've identified a couple of areas where handling of different command prefixes (especially for staging environments) could be improved to prevent issues in the future. One of these is in the active code and could cause bugs in staging, while the other is in commented-out code that is planned for a future update. Addressing these will make the new feature more reliable across all environments.
packit_service/worker/jobs.py
Outdated
| packit_comment_command_prefix = ( | ||
| "/packit-ci" if comment.startswith("/packit-ci") else "/packit" | ||
| ) | ||
|
|
||
| command = get_packit_commands_from_comment( | ||
| comment, | ||
| packit_comment_command_prefix, | ||
| ) | ||
|
|
||
| return bool(command and command[0] == PACKIT_HELP_COMMAND) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to detect the help command is not robust enough. It doesn't handle staging prefixes like /packit-stg or /packit-ci-stg, and it can fail if the comment has leading whitespace since comment.startswith is used on the raw comment string.
A better approach would be to iterate through all possible prefixes and use get_packit_commands_from_comment to check for the help command. This would also make the logic more resilient to comment formatting.
Consider improving the test cases in tests/integration/test_pr_comment.py to cover staging prefixes to catch such issues in the future.
| packit_comment_command_prefix = ( | |
| "/packit-ci" if comment.startswith("/packit-ci") else "/packit" | |
| ) | |
| command = get_packit_commands_from_comment( | |
| comment, | |
| packit_comment_command_prefix, | |
| ) | |
| return bool(command and command[0] == PACKIT_HELP_COMMAND) | |
| prefixes = ("/packit-ci-stg", "/packit-ci", "/packit-stg", "/packit") | |
| for prefix in prefixes: | |
| command = get_packit_commands_from_comment( | |
| comment, | |
| prefix, | |
| ) | |
| if command and command[0] == PACKIT_HELP_COMMAND: | |
| return True | |
| return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "-stg" suffixes definitely need to be taken into account. However, I don't think I like the trial and error for loop. I'll try a different solution.
Imports are commented-out for now until necessary implementation is available.
The `print_help` method from the `argparse` module was previously used, followed by a thread-unsafe redirect of stdout. This was removed and replaced with the use of the `format_help` method, which outputs a string containing the needed help message in a much better way.
The previously used variable seemed to always be initialized with the "/packit" value, which would result in incorrect behaviour in Fedora CI as the expected value in this case would be "/packit-ci" instead. Correct value should now be in use.
1df9cdb to
a4ae68a
Compare
|
/gemini review |
There was a problem hiding this 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 a new GitPullRequestHelpHandler to respond to /packit help commands in pull request comments across GitHub, GitLab, and Pagure. This is a valuable feature for improving user experience. The implementation is well-structured, adding a new handler, a Celery task, and updating the job processing logic. Integration tests for GitHub and Pagure are included. My review focuses on a minor typo, improving test coverage by adding a GitLab test, and correcting type hints for better code quality.
| package_config: dict, | ||
| job_config: dict, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def test_pr_comment_help_handler_pagure(pagure_pr_comment_added): | ||
| flexmock(Signature).should_receive("apply_async").once() | ||
| pagure_pr_comment_added["pullrequest"]["comments"][0]["comment"] = "/packit help" | ||
|
|
||
| pr = flexmock(target_branch="the_distgit_branch").should_receive("comment").mock() | ||
|
|
||
| comment = flexmock() | ||
| flexmock(pr).should_receive("get_comment").and_return(comment) | ||
| flexmock(comment).should_receive("add_reaction").with_args(COMMENT_REACTION).once() | ||
|
|
||
| flexmock( | ||
| PagureProject, | ||
| full_repo_name="rpms/jouduv-dort", | ||
| get_web_url=lambda: "https://src.fedoraproject.org/rpms/jouduv-dort", | ||
| default_branch="main", | ||
| get_pr=lambda id: pr, | ||
| ) | ||
|
|
||
| processing_results = SteveJobs().process_message(pagure_pr_comment_added) | ||
| event_dict, _, job_config, package_config = get_parameters_from_results( | ||
| processing_results, | ||
| ) | ||
| assert len(processing_results) == 1 | ||
|
|
||
| results = run_pr_help_handler( | ||
| package_config=package_config, | ||
| event=event_dict, | ||
| job_config=job_config, | ||
| ) | ||
|
|
||
| assert first_dict_value(results["job"])["success"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Build succeeded. ✔️ pre-commit SUCCESS in 1m 46s |
|
Build succeeded. ✔️ pre-commit SUCCESS in 1m 41s |
A new job handler has been created so that
packit-servicenow has the ability to respond to thehelpcommand in PR comments. The bot then should automatically generate a comment, which contains a help message that includes the usage, link to documentation and contacts. A test for Github PR was made to test this new functionality.TODO:
packit/packit.dev./packit-ciwhen user uses/packitand the other way around. This is in case the user uses/packitwhen they should be using/packit-ciand vice versa.This PR is a draft at the moment because the help message is going to be generated via
argparse, which is being used in my other PR to define comment parses (these parsers were added in that PR to handle the latest--packageargument). Once that is merged, I will uncomment the code that requires these parsers to generate the help message. At the moment, a placeholder help message is used.Fixes #1668
Related to
Merge after #2850
RELEASE NOTES BEGIN
Packit-service now supports the
helpcommand in PR comments.RELEASE NOTES END