2
2
3
3
import responses
4
4
5
- from sentry .tasks .integrations .github .open_pr_comment import get_pr_filenames , safe_for_comment
5
+ from sentry .tasks .integrations .github .open_pr_comment import (
6
+ get_pr_filenames ,
7
+ get_projects_and_filenames_from_source_file ,
8
+ safe_for_comment ,
9
+ )
6
10
from sentry .testutils .silo import region_silo_test
7
11
from sentry .testutils .skips import requires_snuba
8
12
from tests .sentry .tasks .integrations .github .test_pr_comment import GithubCommentTestCase
@@ -144,7 +148,7 @@ def setUp(self):
144
148
self .gh_client = installation .get_client ()
145
149
146
150
@responses .activate
147
- def test_simple (self ):
151
+ def test_get_pr_filenames (self ):
148
152
responses .add (
149
153
responses .GET ,
150
154
self .gh_path .format (pull_number = self .pr .key ),
@@ -157,3 +161,58 @@ def test_simple(self):
157
161
)
158
162
159
163
assert set (get_pr_filenames (self .gh_client , self .gh_repo , self .pr )) == {"bar.py" , "baz.py" }
164
+
165
+ def test_get_projects_and_filenames_from_source_file (self ):
166
+ projects = [self .create_project () for _ in range (4 )]
167
+
168
+ source_stack_pairs = [
169
+ ("" , "./" ),
170
+ ("src/sentry" , "sentry/" ),
171
+ ("src/" , "" ),
172
+ ("src/sentry/" , "sentry/" ),
173
+ ]
174
+ for i , pair in enumerate (source_stack_pairs ):
175
+ source_root , stack_root = pair
176
+ self .create_code_mapping (
177
+ project = projects [i ],
178
+ repo = self .gh_repo ,
179
+ source_root = source_root ,
180
+ stack_root = stack_root ,
181
+ default_branch = "master" ,
182
+ )
183
+
184
+ # matching code mapping from a different org
185
+ other_org_code_mapping = self .create_code_mapping (
186
+ project = self .another_org_project ,
187
+ repo = self .another_org_repo ,
188
+ source_root = "" ,
189
+ stack_root = "./" ,
190
+ )
191
+ other_org_code_mapping .organization_id = self .another_organization .id
192
+ other_org_code_mapping .save ()
193
+
194
+ source_stack_nonmatches = [
195
+ ("/src/sentry" , "sentry" ),
196
+ ("tests/" , "tests/" ),
197
+ ("app/" , "static/app" ),
198
+ ]
199
+ for source_root , stack_root in source_stack_nonmatches :
200
+ self .create_code_mapping (
201
+ project = self .create_project (),
202
+ repo = self .gh_repo ,
203
+ source_root = source_root ,
204
+ stack_root = stack_root ,
205
+ default_branch = "master" ,
206
+ )
207
+
208
+ filename = "src/sentry/tasks/integrations/github/open_pr_comment.py"
209
+ correct_filenames = [
210
+ filename .replace (source_root , stack_root )
211
+ for source_root , stack_root in source_stack_pairs
212
+ ]
213
+
214
+ project_list , sentry_filenames = get_projects_and_filenames_from_source_file (
215
+ self .organization .id , filename
216
+ )
217
+ assert project_list == set (projects )
218
+ assert sentry_filenames == set (correct_filenames )
0 commit comments