Skip to content

Commit

Permalink
Do not load Packit config for non-packit comment commands (packit#2048)
Browse files Browse the repository at this point in the history
Do not load Packit config for non-packit comment commands

If the event we are reacting to is a PR comment, check whether there is a packit command included. If not, do not try to load the config, end directly.
Related to packit#2044

RELEASE NOTES BEGIN

RELEASE NOTES END

Reviewed-by: Matej Focko
  • Loading branch information
softwarefactory-project-zuul[bot] authored May 11, 2023
2 parents 6fb156e + 2e5a19b commit ed1cef1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
13 changes: 13 additions & 0 deletions packit_service/worker/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ def process_jobs(self) -> List[TaskResults]:
Returns:
List of the results of each task.
"""
if isinstance(
self.event, AbstractCommentEvent
) and not get_handlers_for_comment(
self.event.comment,
packit_comment_command_prefix=self.service_config.comment_command_prefix,
):
return [
TaskResults(
success=True,
details={"msg": "No Packit command found in the comment."},
)
]

if not self.is_packit_config_present():
return [
TaskResults.create_from(
Expand Down
38 changes: 25 additions & 13 deletions tests/integration/test_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ def pr_empty_comment_event():


@pytest.fixture(scope="module")
def pr_packit_only_comment_event():
def pr_packit_comment_command_without_argument_event():
return json.loads(
(
DATA_DIR / "webhooks" / "github" / "issue_comment_packit_only.json"
DATA_DIR
/ "webhooks"
/ "github"
/ "issue_comment_packit_command_without_argument.json"
).read_text()
)

Expand Down Expand Up @@ -461,8 +464,9 @@ def test_pr_comment_empty_handler(
pr = flexmock(head_commit="12345")
flexmock(GithubProject).should_receive("get_pr").and_return(pr)

results = SteveJobs().process_message(pr_empty_comment_event)
assert results == []
results = SteveJobs().process_message(pr_empty_comment_event)[0]
assert results["success"]
assert results["details"]["msg"] == "No Packit command found in the comment."


@pytest.mark.parametrize(
Expand All @@ -481,15 +485,18 @@ def test_pr_comment_empty_handler(
indirect=True,
)
def test_pr_comment_packit_only_handler(
mock_pr_comment_functionality, pr_packit_only_comment_event
mock_pr_comment_functionality, pr_packit_comment_command_without_argument_event
):
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("can_merge_pr").and_return(True)
pr = flexmock(head_commit="12345")
flexmock(GithubProject).should_receive("get_pr").and_return(pr)

results = SteveJobs().process_message(pr_packit_only_comment_event)
assert results == []
results = SteveJobs().process_message(
pr_packit_comment_command_without_argument_event
)[0]
assert results["success"]
assert results["details"]["msg"] == "No Packit command found in the comment."


@pytest.mark.parametrize(
Expand Down Expand Up @@ -517,8 +524,9 @@ def test_pr_comment_wrong_packit_command_handler(
pr = flexmock(head_commit="12345")
flexmock(GithubProject).should_receive("get_pr").and_return(pr)

results = SteveJobs().process_message(pr_wrong_packit_comment_event)
assert results == []
results = SteveJobs().process_message(pr_wrong_packit_comment_event)[0]
assert results["success"]
assert results["details"]["msg"] == "No Packit command found in the comment."


def test_pr_test_command_handler(pr_embedded_command_comment_event):
Expand Down Expand Up @@ -2214,8 +2222,13 @@ def test_invalid_packit_command_with_config(
pr = flexmock(head_commit="12345")
flexmock(GithubProject).should_receive("get_pr").and_return(pr)

processing_results = SteveJobs().process_message(pr_embedded_command_comment_event)
assert processing_results == []
processing_result = SteveJobs().process_message(pr_embedded_command_comment_event)[
0
]
assert processing_result["success"]
assert (
processing_result["details"]["msg"] == "No Packit command found in the comment."
)


def test_invalid_packit_command_without_config(
Expand All @@ -2242,8 +2255,7 @@ def test_invalid_packit_command_without_config(
]
assert processing_result["success"]
assert (
processing_result["details"]["msg"]
== "No packit config found in the repository."
processing_result["details"]["msg"] == "No Packit command found in the comment."
)


Expand Down

0 comments on commit ed1cef1

Please sign in to comment.