Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/sentry/api/endpoints/group_autofix_setup_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ def get(self, request: Request, group: Group) -> Response:
organization=org, project=group.project
)

repos = get_repos_and_access(group.project)
write_access_ok = len(repos) > 0 and all(repo["ok"] for repo in repos)
write_integration_check = None
if request.query_params.get("check_write_access", False):
repos = get_repos_and_access(group.project)
write_access_ok = len(repos) > 0 and all(repo["ok"] for repo in repos)
write_integration_check = {
"ok": write_access_ok,
"repos": repos,
}

return Response(
{
Expand All @@ -132,9 +138,6 @@ def get(self, request: Request, group: Group) -> Response:
"ok": integration_check is None,
"reason": integration_check,
},
"githubWriteIntegration": {
"ok": write_access_ok,
"repos": repos,
},
"githubWriteIntegration": write_integration_check,
}
)
35 changes: 6 additions & 29 deletions tests/sentry/api/endpoints/test_group_autofix_setup_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,7 @@ def setUp(self):
)
self.organization.update_option("sentry:gen_ai_consent_v2024_11_14", True)

@patch(
"sentry.api.endpoints.group_autofix_setup_check.get_repos_and_access",
return_value=[
{
"provider": "github",
"owner": "getsentry",
"name": "seer",
"external_id": "123",
"ok": True,
}
],
)
def test_successful_setup(self, mock_get_repos_and_access):
def test_successful_setup(self):
"""
Everything is set up correctly, should respond with OKs.
"""
Expand All @@ -63,18 +51,7 @@ def test_successful_setup(self, mock_get_repos_and_access):
"ok": True,
"reason": None,
},
"githubWriteIntegration": {
"ok": True,
"repos": [
{
"provider": "github",
"owner": "getsentry",
"name": "seer",
"external_id": "123",
"ok": True,
}
],
},
"githubWriteIntegration": None,
}

@patch(
Expand All @@ -89,13 +66,13 @@ def test_successful_setup(self, mock_get_repos_and_access):
}
],
)
def test_successful_with_codebase_indexing_disabled_flag(self, mock_get_repos_and_access):
def test_successful_with_write_access(self, mock_get_repos_and_access):
"""
Everything is set up correctly, should respond with OKs.
"""
group = self.create_group()
self.login_as(user=self.user)
url = f"/api/0/issues/{group.id}/autofix/setup/"
url = f"/api/0/issues/{group.id}/autofix/setup/?check_write_access=true"
response = self.client.get(url, format="json")

assert response.status_code == 200
Expand Down Expand Up @@ -192,7 +169,7 @@ def test_missing_integration(self):
def test_repo_write_access_not_ready(self, mock_get_repos_and_access):
group = self.create_group()
self.login_as(user=self.user)
url = f"/api/0/issues/{group.id}/autofix/setup/"
url = f"/api/0/issues/{group.id}/autofix/setup/?check_write_access=true"
response = self.client.get(url, format="json")

assert response.status_code == 200
Expand Down Expand Up @@ -223,7 +200,7 @@ def test_repo_write_access_not_ready(self, mock_get_repos_and_access):
def test_repo_write_access_no_repos(self, mock_get_repos_and_access):
group = self.create_group()
self.login_as(user=self.user)
url = f"/api/0/issues/{group.id}/autofix/setup/"
url = f"/api/0/issues/{group.id}/autofix/setup/?check_write_access=true"
Copy link
Member

Choose a reason for hiding this comment

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

Should we also have a test where check_write_access = false?

Copy link
Member Author

Choose a reason for hiding this comment

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

already tested for the empty condition at test_successful_setup which is equivalent to false

response = self.client.get(url, format="json")

assert response.status_code == 200
Expand Down
Loading