Skip to content

Conversation

@betulependule
Copy link

@betulependule betulependule commented Oct 6, 2025

A new job handler has been created so that packit-service now has the ability to respond to the help command 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:

  • Update or write new documentation in packit/packit.dev.
  • In the help message, add reference to /packit-ci when user uses /packit and the other way around. This is in case the user uses /packit when they should be using /packit-ci and 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 --package argument). 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 help command in PR comments.

RELEASE NOTES END

@softwarefactory-project-zuul
Copy link
Contributor

@betulependule betulependule force-pushed the help-pr-comment-command branch from 457d872 to 7cb22ab Compare November 26, 2025 10:09
@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@betulependule
Copy link
Author

/gemini review

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 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.

@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@betulependule betulependule force-pushed the help-pr-comment-command branch from 6e25b11 to efb691b Compare November 26, 2025 12:37
@softwarefactory-project-zuul
Copy link
Contributor

@softwarefactory-project-zuul
Copy link
Contributor

@betulependule
Copy link
Author

/gemini review

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 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.

Comment on lines 1142 to 1151
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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

Copy link
Author

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.
@betulependule betulependule force-pushed the help-pr-comment-command branch from 1df9cdb to a4ae68a Compare November 28, 2025 10:50
@betulependule
Copy link
Author

/gemini review

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 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.

Comment on lines +303 to +304
package_config: dict,
job_config: dict,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The package_config and job_config arguments can be None when this task is called for the help command. The type hints should be updated to Optional[dict] to reflect this.

Suggested change
package_config: dict,
job_config: dict,
package_config: Optional[dict],
job_config: Optional[dict],

Comment on lines +266 to +296
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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The GitPullRequestHelpHandler is also registered for GitLab MR comments (gitlab.mr.Comment), but there is no integration test for it. Please consider adding a test case for GitLab to ensure complete coverage of the new functionality.

@softwarefactory-project-zuul
Copy link
Contributor

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

None yet

Development

Successfully merging this pull request may close these issues.

Provide a /packit help comment command

1 participant