Skip to content

Commit c4fc965

Browse files
authored
feat(autofix): Write access is optional in setup via query (#81101)
Only call seer for the write access check for when Autofix is ready to create a PR
1 parent b3f9987 commit c4fc965

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

src/sentry/api/endpoints/group_autofix_setup_check.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ def get(self, request: Request, group: Group) -> Response:
119119
organization=org, project=group.project
120120
)
121121

122-
repos = get_repos_and_access(group.project)
123-
write_access_ok = len(repos) > 0 and all(repo["ok"] for repo in repos)
122+
write_integration_check = None
123+
if request.query_params.get("check_write_access", False):
124+
repos = get_repos_and_access(group.project)
125+
write_access_ok = len(repos) > 0 and all(repo["ok"] for repo in repos)
126+
write_integration_check = {
127+
"ok": write_access_ok,
128+
"repos": repos,
129+
}
124130

125131
return Response(
126132
{
@@ -132,9 +138,6 @@ def get(self, request: Request, group: Group) -> Response:
132138
"ok": integration_check is None,
133139
"reason": integration_check,
134140
},
135-
"githubWriteIntegration": {
136-
"ok": write_access_ok,
137-
"repos": repos,
138-
},
141+
"githubWriteIntegration": write_integration_check,
139142
}
140143
)

tests/sentry/api/endpoints/test_group_autofix_setup_check.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ def setUp(self):
3232
)
3333
self.organization.update_option("sentry:gen_ai_consent_v2024_11_14", True)
3434

35-
@patch(
36-
"sentry.api.endpoints.group_autofix_setup_check.get_repos_and_access",
37-
return_value=[
38-
{
39-
"provider": "github",
40-
"owner": "getsentry",
41-
"name": "seer",
42-
"external_id": "123",
43-
"ok": True,
44-
}
45-
],
46-
)
47-
def test_successful_setup(self, mock_get_repos_and_access):
35+
def test_successful_setup(self):
4836
"""
4937
Everything is set up correctly, should respond with OKs.
5038
"""
@@ -63,18 +51,7 @@ def test_successful_setup(self, mock_get_repos_and_access):
6351
"ok": True,
6452
"reason": None,
6553
},
66-
"githubWriteIntegration": {
67-
"ok": True,
68-
"repos": [
69-
{
70-
"provider": "github",
71-
"owner": "getsentry",
72-
"name": "seer",
73-
"external_id": "123",
74-
"ok": True,
75-
}
76-
],
77-
},
54+
"githubWriteIntegration": None,
7855
}
7956

8057
@patch(
@@ -89,13 +66,13 @@ def test_successful_setup(self, mock_get_repos_and_access):
8966
}
9067
],
9168
)
92-
def test_successful_with_codebase_indexing_disabled_flag(self, mock_get_repos_and_access):
69+
def test_successful_with_write_access(self, mock_get_repos_and_access):
9370
"""
9471
Everything is set up correctly, should respond with OKs.
9572
"""
9673
group = self.create_group()
9774
self.login_as(user=self.user)
98-
url = f"/api/0/issues/{group.id}/autofix/setup/"
75+
url = f"/api/0/issues/{group.id}/autofix/setup/?check_write_access=true"
9976
response = self.client.get(url, format="json")
10077

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

198175
assert response.status_code == 200
@@ -223,7 +200,7 @@ def test_repo_write_access_not_ready(self, mock_get_repos_and_access):
223200
def test_repo_write_access_no_repos(self, mock_get_repos_and_access):
224201
group = self.create_group()
225202
self.login_as(user=self.user)
226-
url = f"/api/0/issues/{group.id}/autofix/setup/"
203+
url = f"/api/0/issues/{group.id}/autofix/setup/?check_write_access=true"
227204
response = self.client.get(url, format="json")
228205

229206
assert response.status_code == 200

0 commit comments

Comments
 (0)