core: ruff format

This commit is contained in:
RhodeCode Admin 2025-11-28 11:35:34 +01:00
parent b452f0598e
commit 9780721347
6 changed files with 43 additions and 62 deletions

View file

@ -17,34 +17,28 @@ class TestAiCodeReview:
route_path(
"pullrequest_start_ai_code_review",
repo_name=pull_request.target_repo.repo_name,
pull_request_id=pull_request.pull_request_id
pull_request_id=pull_request.pull_request_id,
)
)
session = response.get_session_from_response()
err_msg = session.peek_flash('error')
err_msg = session.peek_flash("error")
assert response.status_code == 200
assert response.json_body == {'response': True, 'redirect_url': None}
assert response.json_body == {"response": True, "redirect_url": None}
assert len(err_msg) == 1
assert err_msg[0] == "Cannot start review for closed pull requests."
assert run_task_mock.call_count == 0
def test_ai_review_finished(self, backend, pr_util):
pull_request = pr_util.create_pull_request()
pull_request.ai_code_review_state = {
"review_state": "finished"
}
pull_request.ai_code_review_state = {"review_state": "finished"}
repo_name = pull_request.target_repo.repo_name
pull_request_id = pull_request.pull_request_id
with patch("rhodecode.apps.repository.views.repo_pull_requests.run_task") as run_task_mock:
response = self.app.post(
route_path(
"pullrequest_start_ai_code_review",
repo_name=repo_name,
pull_request_id=pull_request_id
)
route_path("pullrequest_start_ai_code_review", repo_name=repo_name, pull_request_id=pull_request_id)
)
redirect_url = route_path(
"pullrequest_show",
@ -53,11 +47,11 @@ class TestAiCodeReview:
)
session = response.get_session_from_response()
err_msg = session.peek_flash('error')
success_message = session.peek_flash('success')
err_msg = session.peek_flash("error")
success_message = session.peek_flash("success")
assert response.status_code == 200
assert response.json_body == {'response': True, 'redirect_url': redirect_url}
assert response.json_body == {"response": True, "redirect_url": redirect_url}
assert len(err_msg) == 0
assert len(success_message) == 0
assert run_task_mock.call_count == 0
@ -71,7 +65,7 @@ class TestAiCodeReview:
route_path(
"pullrequest_start_ai_code_review",
repo_name=pull_request.target_repo.repo_name,
pull_request_id=pr_id
pull_request_id=pr_id,
)
)
@ -82,7 +76,7 @@ class TestAiCodeReview:
ai_user = User.get_ai_user()
session = response.get_session_from_response()
success_message = session.peek_flash('success')
success_message = session.peek_flash("success")
assert response.status_code == 200
assert run_task_mock.call_count == 1

View file

@ -1318,9 +1318,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
ai_state = deepcopy(pull_request.ai_code_review_state)
if not ai_state:
ai_state = {
"review_state": "pending"
}
ai_state = {"review_state": "pending"}
else:
ai_state["review_state"] = "pending"
@ -1335,7 +1333,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
already_finished = ai_state.get("review_state") in ["pending", "finished"]
if already_finished:
log.warning(f"Code review already finished.")
log.warning("Code review already finished.")
return False
admin_permissions = (
@ -1373,13 +1371,11 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
["adds system ai user for review"],
False,
PullRequestReviewers.ROLE_REVIEWER,
pull_request.reviewer_data
pull_request.reviewer_data,
)
)
PullRequestModel().update_reviewers(
pull_request, reviewers_data, self._rhodecode_db_user
)
PullRequestModel().update_reviewers(pull_request, reviewers_data, self._rhodecode_db_user)
Session().commit()
@ -1390,9 +1386,7 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
h.flash(msg, category="success")
else:
log.debug("AI code review canceled, only admin can initiate AI code review.")
msg = _(
"AI code review is not available. This feature is in BETA and can only be initiated by an admin."
)
msg = _("AI code review is not available. This feature is in BETA and can only be initiated by an admin.")
h.flash(
msg,
category="warning",