vsts.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. from __future__ import annotations
  2. from typing import Any
  3. from urllib.parse import parse_qs, urlencode, urlparse
  4. import pytest
  5. import responses
  6. from sentry.integrations.models.integration import Integration
  7. from sentry.integrations.vsts import VstsIntegrationProvider
  8. from sentry.integrations.vsts.integration import VstsIntegration
  9. from sentry.silo.base import SiloMode
  10. from sentry.testutils.cases import IntegrationTestCase
  11. from sentry.testutils.helpers.integrations import get_installation_of_type
  12. from sentry.testutils.silo import assume_test_silo_mode
  13. class VstsIntegrationTestCase(IntegrationTestCase):
  14. provider = VstsIntegrationProvider()
  15. def _get_integration_and_install(self) -> tuple[Integration, VstsIntegration]:
  16. integration = Integration.objects.get(provider="vsts")
  17. installation = get_installation_of_type(
  18. VstsIntegration,
  19. integration,
  20. integration.organizationintegration_set.get().organization_id,
  21. )
  22. return integration, installation
  23. @pytest.fixture(autouse=True)
  24. def setup_data(self):
  25. self.access_token = "9d646e20-7a62-4bcc-abc0-cb2d4d075e36"
  26. self.refresh_token = "32004633-a3c0-4616-9aa0-a40632adac77"
  27. self.vsts_account_id = "c8a585ae-b61f-4ba6-833c-9e8d5d1674d8"
  28. self.vsts_account_name = "MyVSTSAccount"
  29. self.vsts_account_uri = "https://MyVSTSAccount.vssps.visualstudio.com:443/"
  30. self.vsts_base_url = "https://MyVSTSAccount.visualstudio.com/"
  31. self.vsts_user_id = "d6245f20-2af8-44f4-9451-8107cb2767db"
  32. self.vsts_user_name = "Foo Bar"
  33. self.vsts_user_email = "foobar@example.com"
  34. self.repo_id = "47166099-3e16-4868-9137-22ac6b05b06e"
  35. self.repo_name = "cool-service"
  36. self.project_a = {"id": "eb6e4656-77fc-42a1-9181-4c6d8e9da5d1", "name": "ProjectA"}
  37. self.project_b = {"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", "name": "ProjectB"}
  38. with responses.mock:
  39. self._stub_vsts()
  40. yield
  41. def _stub_vsts(self):
  42. responses.reset()
  43. responses.add(
  44. responses.POST,
  45. "https://app.vssps.visualstudio.com/oauth2/token",
  46. json={
  47. "access_token": self.access_token,
  48. "token_type": "grant",
  49. "expires_in": 300, # seconds (5 min)
  50. "refresh_token": self.refresh_token,
  51. },
  52. )
  53. responses.add(
  54. responses.GET,
  55. "https://app.vssps.visualstudio.com/_apis/accounts?memberId=%s&api-version=4.1"
  56. % self.vsts_user_id,
  57. json={
  58. "count": 1,
  59. "value": [
  60. {
  61. "accountId": self.vsts_account_id,
  62. "accountUri": self.vsts_account_uri,
  63. "accountName": self.vsts_account_name,
  64. "properties": {},
  65. }
  66. ],
  67. },
  68. )
  69. responses.add(
  70. responses.GET,
  71. "https://app.vssps.visualstudio.com/_apis/resourceareas/79134C72-4A58-4B42-976C-04E7115F32BF?hostId=%s&api-preview=5.0-preview.1"
  72. % self.vsts_account_id,
  73. json={"locationUrl": self.vsts_base_url},
  74. )
  75. responses.add(
  76. responses.GET,
  77. "https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0",
  78. json={
  79. "id": self.vsts_user_id,
  80. "displayName": self.vsts_user_name,
  81. "emailAddress": self.vsts_user_email,
  82. },
  83. )
  84. responses.add(
  85. responses.GET,
  86. "https://app.vssps.visualstudio.com/_apis/connectionData/",
  87. json={"authenticatedUser": {"subjectDescriptor": self.vsts_account_id}},
  88. )
  89. responses.add(
  90. responses.GET,
  91. f"https://{self.vsts_account_name.lower()}.visualstudio.com/_apis/projects",
  92. json={"value": [self.project_a, self.project_b], "count": 2},
  93. )
  94. responses.add(
  95. responses.POST,
  96. f"https://{self.vsts_account_name.lower()}.visualstudio.com/_apis/hooks/subscriptions",
  97. json=CREATE_SUBSCRIPTION,
  98. )
  99. responses.add(
  100. responses.GET,
  101. f"https://{self.vsts_account_name.lower()}.visualstudio.com/_apis/git/repositories",
  102. json={
  103. "value": [
  104. {
  105. "id": self.repo_id,
  106. "name": self.repo_name,
  107. "project": {"name": self.project_a["name"]},
  108. }
  109. ]
  110. },
  111. )
  112. responses.add(
  113. responses.GET,
  114. f"https://{self.vsts_account_name.lower()}.visualstudio.com/ProjectA/_apis/git/repositories/ProjectA",
  115. json={
  116. "repository": {
  117. "id": self.repo_id,
  118. "name": self.repo_name,
  119. "project": {"name": self.project_a["name"]},
  120. }
  121. },
  122. )
  123. for project in [self.project_a, self.project_b]:
  124. responses.add(
  125. responses.GET,
  126. "https://{}.visualstudio.com/{}/_apis/wit/workitemtypes/{}/states".format(
  127. self.vsts_account_name.lower(), project["id"], "Bug"
  128. ),
  129. json={
  130. "count": 6,
  131. "value": [
  132. {"name": "resolve_status"},
  133. {"name": "resolve_when"},
  134. {"name": "regression_status"},
  135. {"name": "sync_comments"},
  136. {"name": "sync_forward_assignment"},
  137. {"name": "sync_reverse_assignment"},
  138. ],
  139. },
  140. )
  141. responses.add(
  142. responses.GET,
  143. "https://{}.visualstudio.com/{}/_apis/wit/workitemtypes/{}/states".format(
  144. self.vsts_account_name.lower(), project["id"], "Issue"
  145. ),
  146. json={
  147. "count": 0,
  148. "value": [],
  149. },
  150. )
  151. responses.add(
  152. responses.GET,
  153. "https://{}.visualstudio.com/{}/_apis/wit/workitemtypes/{}/states".format(
  154. self.vsts_account_name.lower(), project["id"], "Task"
  155. ),
  156. json={
  157. "count": 0,
  158. "value": [],
  159. },
  160. )
  161. def make_init_request(self, path=None, body=None):
  162. return self.client.get(path or self.init_path, body or {})
  163. def make_oauth_redirect_request(self, state):
  164. return self.client.get(
  165. "{}?{}".format(self.setup_path, urlencode({"code": "oauth-code", "state": state}))
  166. )
  167. def assert_vsts_oauth_redirect(self, redirect):
  168. assert redirect.scheme == "https"
  169. assert redirect.netloc == "app.vssps.visualstudio.com"
  170. assert redirect.path == "/oauth2/authorize"
  171. def assert_account_selection(self, response, account_id=None):
  172. account_id = account_id or self.vsts_account_id
  173. assert response.status_code == 200
  174. assert f'<option value="{account_id}"'.encode() in response.content
  175. @assume_test_silo_mode(SiloMode.CONTROL)
  176. def assert_installation(self):
  177. # Initial request to the installation URL for VSTS
  178. resp = self.make_init_request()
  179. redirect = urlparse(resp["Location"])
  180. assert resp.status_code == 302
  181. self.assert_vsts_oauth_redirect(redirect)
  182. query = parse_qs(redirect.query)
  183. # OAuth redirect back to Sentry (identity_pipeline_view)
  184. resp = self.make_oauth_redirect_request(query["state"][0])
  185. self.assert_account_selection(resp)
  186. # User choosing which VSTS Account to use (AccountConfigView)
  187. # Final step.
  188. resp = self.client.post(
  189. self.setup_path, {"account": self.vsts_account_id, "provider": "vsts"}
  190. )
  191. return resp
  192. COMPARE_COMMITS_EXAMPLE = b"""
  193. {
  194. "count": 1,
  195. "value": [
  196. {
  197. "commitId": "6c36052c58bde5e57040ebe6bdb9f6a52c906fff",
  198. "author": {
  199. "name": "max bittker",
  200. "email": "max@sentry.io",
  201. "date": "2018-04-24T00:03:18Z"
  202. },
  203. "committer": {
  204. "name": "max bittker",
  205. "email": "max@sentry.io",
  206. "date": "2018-04-24T00:03:18Z"
  207. },
  208. "comment": "Updated README.md",
  209. "commentTruncated": true,
  210. "changeCounts": {"Add": 0, "Edit": 1, "Delete": 0},
  211. "url":
  212. "https://mbittker.visualstudio.com/_apis/git/repositories/b1e25999-c080-4ea1-8c61-597c4ec41f06/commits/6c36052c58bde5e57040ebe6bdb9f6a52c906fff",
  213. "remoteUrl":
  214. "https://mbittker.visualstudio.com/_git/MyFirstProject/commit/6c36052c58bde5e57040ebe6bdb9f6a52c906fff"
  215. }
  216. ]
  217. }
  218. """
  219. COMMIT_DETAILS_EXAMPLE = r"""
  220. {
  221. "_links": {
  222. "changes": {
  223. "href": "https://mbittker.visualstudio.com/_apis/git/repositories/666ffcce-8ffa-46ec-bccf-b93b55bb2320/commits/6c36052c58bde5e57040ebe6bdb9f6a52c906fff/changes"
  224. },
  225. "repository": {
  226. "href": "https://mbittker.visualstudio.com/_apis/git/repositories/666ffcce-8ffa-46ec-bccf-b93b55bb2320"
  227. },
  228. "self": {
  229. "href": "https://mbittker.visualstudio.com/_apis/git/repositories/666ffcce-8ffa-46ec-bccf-b93b55bb2320/commits/6c36052c58bde5e57040ebe6bdb9f6a52c906fff"
  230. },
  231. "web": {
  232. "href": "https://mbittker.visualstudio.com/_git/MyFirstProject/commit/6c36052c58bde5e57040ebe6bdb9f6a52c906fff"
  233. }
  234. },
  235. "author": {
  236. "date": "2018-11-23T15:59:19Z",
  237. "email": "max@sentry.io",
  238. "imageUrl": "https://www.gravatar.com/avatar/1cee8d752bcad4c172d60e56bb398c11?r=g&d=mm",
  239. "name": "max bitker"
  240. },
  241. "comment": "Updated README.md\n\nSecond line\n\nFixes SENTRY-1",
  242. "commitId": "6c36052c58bde5e57040ebe6bdb9f6a52c906fff",
  243. "committer": {
  244. "date": "2018-11-23T15:59:19Z",
  245. "email": "max@sentry.io",
  246. "imageUrl": "https://www.gravatar.com/avatar/1cee8d752bcad4c172d60e56bb398c11?r=g&d=mm",
  247. "name": "max bittker"
  248. },
  249. "parents": [
  250. "641e82ce0ed14f3cf3670b0bf5f669d7fbd40a68"
  251. ],
  252. "push": {
  253. "date": "2018-11-23T16:01:10.7246278Z",
  254. "pushId": 2,
  255. "pushedBy": {
  256. "_links": {
  257. "avatar": {
  258. "href": "https://mbittker.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.NjI0ZGRhOWMtODgyZC03ZmRhLTk3OWItZTdhMjI5MWMzMzBk"
  259. }
  260. },
  261. "descriptor": "msa.NjI0ZGRhOWMtODgyZC03ZmRhLTk3OWItZTdhMjI5MWMzMzBk",
  262. "displayName": "Mark Story",
  263. "id": "624dda9c-882d-6fda-979b-e7a2291c330d",
  264. "imageUrl": "https://mbittker.visualstudio.com/_api/_common/identityImage?id=624dda9c-882d-6fda-979b-e7a2291c330d",
  265. "uniqueName": "mark@mark-story.com",
  266. "url": "https://mbittker.visualstudio.com/Aa365971d-9897-47eb-becf-c5142d33db08/_apis/Identities/624dda9c-882d-6fda-979b-e7a2291c330d"
  267. }
  268. },
  269. "remoteUrl": "https://mbittker.visualstudio.com/MyFirstProject/_git/box-of-things/commit/6c36052c58bde5e57040ebe6bdb9f6a52c906fff",
  270. "treeId": "026257a5e53eb923497c0217ef76e567f3a60088",
  271. "url": "https://mbittker.visualstudio.com/_apis/git/repositories/666ffcce-8ffa-46ec-bccf-b93b55bb2320/commits/6c36052c58bde5e57040ebe6bdb9f6a52c906fff"
  272. }
  273. """
  274. FILE_CHANGES_EXAMPLE = b"""
  275. {
  276. "changeCounts": {"Edit": 1},
  277. "changes": [
  278. {
  279. "item": {
  280. "objectId": "b48e843656a0a12926a0bcedefe8ef3710fe2867",
  281. "originalObjectId": "270b590a4edf3f19aa7acc7b57379729e34fc681",
  282. "gitObjectType": "blob",
  283. "commitId": "6c36052c58bde5e57040ebe6bdb9f6a52c906fff",
  284. "path": "/README.md",
  285. "url":
  286. "https://mbittker.visualstudio.com/DefaultCollection/_apis/git/repositories/b1e25999-c080-4ea1-8c61-597c4ec41f06/items/README.md?versionType=Commit&version=6c36052c58bde5e57040ebe6bdb9f6a52c906fff"
  287. },
  288. "changeType": "edit"
  289. }
  290. ]
  291. }
  292. """
  293. WORK_ITEM_RESPONSE = """{
  294. "id": 309,
  295. "rev": 1,
  296. "fields": {
  297. "System.AreaPath": "Fabrikam-Fiber-Git",
  298. "System.TeamProject": "Fabrikam-Fiber-Git",
  299. "System.IterationPath": "Fabrikam-Fiber-Git",
  300. "System.WorkItemType": "Product Backlog Item",
  301. "System.State": "New",
  302. "System.Reason": "New backlog item",
  303. "System.CreatedDate": "2015-01-07T18:13:01.807Z",
  304. "System.CreatedBy": "Jamal Hartnett <fabrikamfiber4@hotmail.com>",
  305. "System.ChangedDate": "2015-01-07T18:13:01.807Z",
  306. "System.ChangedBy": "Jamal Hartnett <fabrikamfiber4@hotmail.com>",
  307. "System.Title": "Hello",
  308. "Microsoft.VSTS.Scheduling.Effort": 8,
  309. "WEF_6CB513B6E70E43499D9FC94E5BBFB784_Kanban.Column": "New",
  310. "System.Description": "Fix this."
  311. },
  312. "_links": {
  313. "self": {
  314. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/309"
  315. },
  316. "workItemUpdates": {
  317. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/309/updates"
  318. },
  319. "workItemRevisions": {
  320. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/309/revisions"
  321. },
  322. "workItemHistory": {
  323. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/309/history"
  324. },
  325. "html": {
  326. "href": "https://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=d81542e4-cdfa-4333-b082-1ae2d6c3ad16&id=309"
  327. },
  328. "workItemType": {
  329. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c/_apis/wit/workItemTypes/Product%20Backlog%20Item"
  330. },
  331. "fields": {
  332. "href": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields"
  333. }
  334. },
  335. "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/309"
  336. }"""
  337. GET_USERS_RESPONSE = b"""{
  338. "count": 4,
  339. "value": [
  340. {
  341. "subjectKind": "user",
  342. "cuid": "ec09a4d8-d914-4f28-9e39-23d52b683f90",
  343. "domain": "Build",
  344. "principalName": "51ac8d19-6694-459f-a65e-bec30e9e2e33",
  345. "mailAddress": "",
  346. "origin": "vsts",
  347. "originId": "ec09a4d8-d914-4f28-9e39-23d52b683f90",
  348. "displayName": "Project Collection Build Service (Ftottentest2)",
  349. "_links": {
  350. "self": {
  351. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlNlcnZpY2VJZGVudGl0eTtmMzViOTAxNS1jZGU4LTQ4MzQtYTFkNS0wOWU4ZjM1OWNiODU6QnVpbGQ6NTFhYzhkMTktNjY5NC00NTlmLWE2NWUtYmVjMzBlOWUyZTMz"
  352. },
  353. "memberships": {
  354. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/memberships/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlNlcnZpY2VJZGVudGl0eTtmMzViOTAxNS1jZGU4LTQ4MzQtYTFkNS0wOWU4ZjM1OWNiODU6QnVpbGQ6NTFhYzhkMTktNjY5NC00NTlmLWE2NWUtYmVjMzBlOWUyZTMz"
  355. }
  356. },
  357. "url": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlNlcnZpY2VJZGVudGl0eTtmMzViOTAxNS1jZGU4LTQ4MzQtYTFkNS0wOWU4ZjM1OWNiODU6QnVpbGQ6NTFhYzhkMTktNjY5NC00NTlmLWE2NWUtYmVjMzBlOWUyZTMz",
  358. "descriptor": "TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlNlcnZpY2VJZGVudGl0eTtmMzViOTAxNS1jZGU4LTQ4MzQtYTFkNS0wOWU4ZjM1OWNiODU6QnVpbGQ6NTFhYzhkMTktNjY5NC00NTlmLWE2NWUtYmVjMzBlOWUyZTMz"
  359. },
  360. {
  361. "subjectKind": "user",
  362. "metaType": "member",
  363. "cuid": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc",
  364. "domain": "LOCAL AUTHORITY",
  365. "principalName": "TeamFoundationService (TEAM FOUNDATION)",
  366. "mailAddress": "",
  367. "origin": "vsts",
  368. "originId": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc",
  369. "displayName": "TeamFoundationService (TEAM FOUNDATION)",
  370. "_links": {
  371. "self": {
  372. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5Ozc3ODlmMDlkLWUwNTMtNGYyZS1iZGVlLTBjOGY4NDc2YTRiYw"
  373. },
  374. "memberships": {
  375. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/memberships/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5Ozc3ODlmMDlkLWUwNTMtNGYyZS1iZGVlLTBjOGY4NDc2YTRiYw"
  376. }
  377. },
  378. "url": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5Ozc3ODlmMDlkLWUwNTMtNGYyZS1iZGVlLTBjOGY4NDc2YTRiYw",
  379. "descriptor": "TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5Ozc3ODlmMDlkLWUwNTMtNGYyZS1iZGVlLTBjOGY4NDc2YTRiYw"
  380. },
  381. {
  382. "subjectKind": "user",
  383. "metaType": "member",
  384. "cuid": "ddd94918-1fc8-459b-994a-cca86c4fbe95",
  385. "domain": "TEAM FOUNDATION",
  386. "principalName": "Anonymous",
  387. "mailAddress": "",
  388. "origin": "vsts",
  389. "originId": "ddd94918-1fc8-459b-994a-cca86c4fbe95",
  390. "displayName": "Anonymous",
  391. "_links": {
  392. "self": {
  393. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlVuYXV0aGVudGljYXRlZElkZW50aXR5O1MtMS0wLTA"
  394. },
  395. "memberships": {
  396. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/memberships/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlVuYXV0aGVudGljYXRlZElkZW50aXR5O1MtMS0wLTA"
  397. }
  398. },
  399. "url": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlVuYXV0aGVudGljYXRlZElkZW50aXR5O1MtMS0wLTA",
  400. "descriptor": "TWljcm9zb2Z0LlRlYW1Gb3VuZGF0aW9uLlVuYXV0aGVudGljYXRlZElkZW50aXR5O1MtMS0wLTA"
  401. },
  402. {
  403. "subjectKind": "user",
  404. "metaType": "member",
  405. "cuid": "65903f92-53dc-61b3-bb0e-e69cfa1cb719",
  406. "domain": "45aa3d2d-7442-473d-b4d3-3c670da9dd96",
  407. "principalName": "ftotten@vscsi.us",
  408. "mailAddress": "ftotten@vscsi.us",
  409. "origin": "aad",
  410. "originId": "4be8f294-000d-4431-8506-57420b88e204",
  411. "displayName": "Francis Totten",
  412. "_links": {
  413. "self": {
  414. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5OzQ1YWEzZDJkLTc0NDItNDczZC1iNGQzLTNjNjcwZGE5ZGQ5NlxmdG90dGVuQHZzY3NpLnVz"
  415. },
  416. "memberships": {
  417. "href": "https://fabrikam.vssps.visualstudio.com/_apis/graph/memberships/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5OzQ1YWEzZDJkLTc0NDItNDczZC1iNGQzLTNjNjcwZGE5ZGQ5NlxmdG90dGVuQHZzY3NpLnVz"
  418. }
  419. },
  420. "url": "https://fabrikam.vssps.visualstudio.com/_apis/graph/users/TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5OzQ1YWEzZDJkLTc0NDItNDczZC1iNGQzLTNjNjcwZGE5ZGQ5NlxmdG90dGVuQHZzY3NpLnVz",
  421. "descriptor": "TWljcm9zb2Z0LklkZW50aXR5TW9kZWwuQ2xhaW1zLkNsYWltc0lkZW50aXR5OzQ1YWEzZDJkLTc0NDItNDczZC1iNGQzLTNjNjcwZGE5ZGQ5NlxmdG90dGVuQHZzY3NpLnVz"
  422. }
  423. ]
  424. }
  425. """
  426. CREATE_SUBSCRIPTION = {
  427. "id": "fd672255-8b6b-4769-9260-beea83d752ce",
  428. "url": "https://fabrikam.visualstudio.com/_apis/hooks/subscriptions/fd672255-8b6b-4769-9260-beea83d752ce",
  429. "publisherId": "tfs",
  430. "eventType": "workitem.update",
  431. "resourceVersion": "1.0-preview.1",
  432. "eventDescription": "WorkItem Updated",
  433. "consumerId": "webHooks",
  434. "consumerActionId": "httpRequest",
  435. "actionDescription": "To host myservice",
  436. "createdBy": {"id": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc"},
  437. "createdDate": "2014-10-27T15:37:24.873Z",
  438. "modifiedBy": {"id": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc"},
  439. "modifiedDate": "2014-10-27T15:37:26.23Z",
  440. "publisherInputs": {
  441. "buildStatus": "Failed",
  442. "definitionName": "MyWebSite CI",
  443. "hostId": "d81542e4-cdfa-4333-b082-1ae2d6c3ad16",
  444. "projectId": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
  445. "tfsSubscriptionId": "3e8b33e7-426d-4c92-9bf9-58e163dd7dd5",
  446. },
  447. "consumerInputs": {"url": "https://myservice/newreceiver"},
  448. }
  449. WORK_ITEM_UPDATED: dict[str, Any] = {
  450. "resourceContainers": {
  451. "project": {
  452. "id": "c0bf429a-c03c-4a99-9336-d45be74db5a6",
  453. "baseUrl": "https://laurynsentry.visualstudio.com/",
  454. },
  455. "account": {
  456. "id": "90e9a854-eb98-4c56-ae1a-035a0f331dd6",
  457. "baseUrl": "https://laurynsentry.visualstudio.com/",
  458. },
  459. "collection": {
  460. "id": "80ded3e8-3cd3-43b1-9f96-52032624aa3a",
  461. "baseUrl": "https://laurynsentry.visualstudio.com/",
  462. },
  463. },
  464. "resource": {
  465. "revisedBy": {
  466. "displayName": "lauryn",
  467. "name": "lauryn <lauryn@sentry.io>",
  468. "url": "https://app.vssps.visualstudio.com/A90e9a854-eb98-4c56-ae1a-035a0f331dd6/_apis/Identities/21354f98-ab06-67d9-b974-5a54d992082e",
  469. "imageUrl": "https://laurynsentry.visualstudio.com/_api/_common/identityImage?id=21354f98-ab06-67d9-b974-5a54d992082e",
  470. "descriptor": "msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl",
  471. "_links": {
  472. "avatar": {
  473. "href": "https://laurynsentry.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl"
  474. }
  475. },
  476. "uniqueName": "lauryn@sentry.io",
  477. "id": "21354f98-ab06-67d9-b974-5a54d992082e",
  478. },
  479. "revisedDate": "9999-01-01T00:00:00Z",
  480. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/updates/2",
  481. "fields": {
  482. "System.AuthorizedDate": {
  483. "newValue": "2018-07-05T20:52:14.777Z",
  484. "oldValue": "2018-07-05T20:51:58.927Z",
  485. },
  486. "System.AssignedTo": {
  487. "newValue": "lauryn <lauryn@sentry.io>",
  488. "oldValue": "lauryn2 <lauryn2@sentry.io>",
  489. },
  490. "System.Watermark": {"newValue": 78, "oldValue": 77},
  491. "System.Rev": {"newValue": 2, "oldValue": 1},
  492. "System.RevisedDate": {
  493. "newValue": "9999-01-01T00:00:00Z",
  494. "oldValue": "2018-07-05T20:52:14.777Z",
  495. },
  496. "System.ChangedDate": {
  497. "newValue": "2018-07-05T20:52:14.777Z",
  498. "oldValue": "2018-07-05T20:51:58.927Z",
  499. },
  500. },
  501. "workItemId": 31,
  502. "rev": 2,
  503. "_links": {
  504. "self": {
  505. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/updates/2"
  506. },
  507. "workItemUpdates": {
  508. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/updates"
  509. },
  510. "html": {
  511. "href": "https://laurynsentry.visualstudio.com/web/wi.aspx?pcguid=80ded3e8-3cd3-43b1-9f96-52032624aa3a&id=31"
  512. },
  513. "parent": {
  514. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31"
  515. },
  516. },
  517. "id": 2,
  518. "revision": {
  519. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/revisions/2",
  520. "fields": {
  521. "System.AreaPath": "MyFirstProject",
  522. "System.WorkItemType": "Bug",
  523. "System.Reason": "New",
  524. "System.Title": "NameError: global name 'BitbucketRepositoryProvider' is not defined",
  525. "Microsoft.VSTS.Common.Priority": 2,
  526. "System.CreatedBy": "lauryn <lauryn@sentry.io>",
  527. "System.AssignedTo": "lauryn <lauryn@sentry.io>",
  528. "System.CreatedDate": "2018-07-05T20:51:58.927Z",
  529. "System.TeamProject": "MyFirstProject",
  530. "Microsoft.VSTS.Common.Severity": "3 - Medium",
  531. "Microsoft.VSTS.Common.ValueArea": "Business",
  532. "System.State": "New",
  533. "System.Description": "<p><a href=\"https://lauryn.ngrok.io/sentry/internal/issues/55/\">https://lauryn.ngrok.io/sentry/internal/issues/55/</a></p>\n<pre><code>NameError: global name 'BitbucketRepositoryProvider' is not defined\n(1 additional frame(s) were not displayed)\n...\n File &quot;sentry/runner/__init__.py&quot;, line 125, in configure\n configure(ctx, py, yaml, skip_service_validation)\n File &quot;sentry/runner/settings.py&quot;, line 152, in configure\n skip_service_validation=skip_service_validation\n File &quot;sentry/runner/initializer.py&quot;, line 315, in initialize_app\n register_plugins(settings)\n File &quot;sentry/runner/initializer.py&quot;, line 60, in register_plugins\n integration.setup()\n File &quot;sentry/integrations/bitbucket/integration.py&quot;, line 78, in setup\n BitbucketRepositoryProvider,\n\nNameError: global name 'BitbucketRepositoryProvider' is not defined\n</code></pre>\n",
  534. "System.ChangedBy": "lauryn <lauryn@sentry.io>",
  535. "System.ChangedDate": "2018-07-05T20:52:14.777Z",
  536. "Microsoft.VSTS.Common.StateChangeDate": "2018-07-05T20:51:58.927Z",
  537. "System.IterationPath": "MyFirstProject",
  538. },
  539. "rev": 2,
  540. "id": 31,
  541. "_links": {
  542. "self": {
  543. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/revisions/2"
  544. },
  545. "workItemRevisions": {
  546. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31/revisions"
  547. },
  548. "parent": {
  549. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/31"
  550. },
  551. },
  552. },
  553. },
  554. "eventType": "workitem.updated",
  555. "detailedMessage": None,
  556. "createdDate": "2018-07-05T20:52:16.3051288Z",
  557. "id": "18f51331-2640-4bce-9ebd-c59c855956a2",
  558. "resourceVersion": "1.0",
  559. "notificationId": 1,
  560. "subscriptionId": "7bf628eb-b3a7-4fb2-ab4d-8b60f2e8cb9b",
  561. "publisherId": "tfs",
  562. "message": None,
  563. }
  564. WORK_ITEM_UNASSIGNED: dict[str, Any] = {
  565. "resourceContainers": {
  566. "project": {
  567. "id": "c0bf429a-c03c-4a99-9336-d45be74db5a6",
  568. "baseUrl": "https://laurynsentry.visualstudio.com/",
  569. },
  570. "account": {
  571. "id": "90e9a854-eb98-4c56-ae1a-035a0f331dd6",
  572. "baseUrl": "https://laurynsentry.visualstudio.com/",
  573. },
  574. "collection": {
  575. "id": "80ded3e8-3cd3-43b1-9f96-52032624aa3a",
  576. "baseUrl": "https://laurynsentry.visualstudio.com/",
  577. },
  578. },
  579. "resource": {
  580. "revisedBy": {
  581. "displayName": "lauryn",
  582. "name": "lauryn <lauryn@sentry.io>",
  583. "url": "https://app.vssps.visualstudio.com/A90e9a854-eb98-4c56-ae1a-035a0f331dd6/_apis/Identities/21354f98-ab06-67d9-b974-5a54d992082e",
  584. "imageUrl": "https://laurynsentry.visualstudio.com/_api/_common/identityImage?id=21354f98-ab06-67d9-b974-5a54d992082e",
  585. "descriptor": "msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl",
  586. "_links": {
  587. "avatar": {
  588. "href": "https://laurynsentry.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl"
  589. }
  590. },
  591. "uniqueName": "lauryn@sentry.io",
  592. "id": "21354f98-ab06-67d9-b974-5a54d992082e",
  593. },
  594. "revisedDate": "9999-01-01T00:00:00 Z",
  595. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates/3",
  596. "fields": {
  597. "System.AuthorizedDate": {
  598. "newValue": "2018-07-05T23:23:09.493 Z",
  599. "oldValue": "2018-07-05T23:21:38.243 Z",
  600. },
  601. "System.AssignedTo": {"oldValue": "lauryn <lauryn@sentry.io>"},
  602. "System.Watermark": {"newValue": 83, "oldValue": 82},
  603. "System.Rev": {"newValue": 3, "oldValue": 2},
  604. "System.RevisedDate": {
  605. "newValue": "9999-01-01T00:00:00 Z",
  606. "oldValue": "2018-07-05T23:23:09.493 Z",
  607. },
  608. "System.ChangedDate": {
  609. "newValue": "2018-07-05T23:23:09.493 Z",
  610. "oldValue": "2018-07-05T23:21:38.243 Z",
  611. },
  612. },
  613. "workItemId": 33,
  614. "rev": 3,
  615. "_links": {
  616. "self": {
  617. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates/3"
  618. },
  619. "workItemUpdates": {
  620. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates"
  621. },
  622. "html": {
  623. "href": "https://laurynsentry.visualstudio.com/web/wi.aspx?pcguid=80ded3e8-3cd3-43b1-9f96-52032624aa3a&id=33"
  624. },
  625. "parent": {
  626. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33"
  627. },
  628. },
  629. "id": 3,
  630. "revision": {
  631. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions/3",
  632. "fields": {
  633. "System.AreaPath": "MyFirstProject",
  634. "System.WorkItemType": "Bug",
  635. "System.Reason": "New",
  636. "System.Title": "NotImplementedError:Visual Studio Team Services requires an organization_id",
  637. "Microsoft.VSTS.Common.Priority": 2,
  638. "System.CreatedBy": "lauryn <lauryn@sentry.io>",
  639. "Microsoft.VSTS.Common.StateChangeDate": "2018-07-05T23:21:25.847 Z",
  640. "System.CreatedDate": "2018-07-05T23:21:25.847 Z",
  641. "System.TeamProject": "MyFirstProject",
  642. "Microsoft.VSTS.Common.ValueArea": "Business",
  643. "System.State": "New",
  644. "System.Description": '<p><a href="https: //lauryn.ngrok.io/sentry/internal/issues/196/">https: //lauryn.ngrok.io/sentry/internal/issues/196/</a></p>\n<pre><code>NotImplementedError:Visual Studio Team Services requires an organization_id\n(57 additional frame(s) were not displayed)\n...\n File &quot;sentry/tasks/base.py&quot;',
  645. "System.ChangedBy": "lauryn <lauryn@sentry.io>",
  646. "System.ChangedDate": "2018-07-05T23:23:09.493 Z",
  647. "Microsoft.VSTS.Common.Severity": "3 - Medium",
  648. "System.IterationPath": "MyFirstProject",
  649. },
  650. "rev": 3,
  651. "id": 33,
  652. "_links": {
  653. "self": {
  654. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions/3"
  655. },
  656. "workItemRevisions": {
  657. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions"
  658. },
  659. "parent": {
  660. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33"
  661. },
  662. },
  663. },
  664. },
  665. "eventType": "workitem.updated",
  666. "detailedMessage": None,
  667. "createdDate": "2018-07-05T23:23:11.1935112 Z",
  668. "id": "cc349c85-6595-4939-9b69-f89480be6a26",
  669. "resourceVersion": "1.0",
  670. "notificationId": 2,
  671. "subscriptionId": "7405a600-6a25-48e6-81b6-1dde044783ad",
  672. "publisherId": "tfs",
  673. "message": None,
  674. }
  675. WORK_ITEM_UPDATED_STATUS: dict[str, Any] = {
  676. "resourceContainers": {
  677. "project": {
  678. "id": "c0bf429a-c03c-4a99-9336-d45be74db5a6",
  679. "baseUrl": "https://laurynsentry.visualstudio.com/",
  680. },
  681. "account": {
  682. "id": "90e9a854-eb98-4c56-ae1a-035a0f331dd6",
  683. "baseUrl": "https://laurynsentry.visualstudio.com/",
  684. },
  685. "collection": {
  686. "id": "80ded3e8-3cd3-43b1-9f96-52032624aa3a",
  687. "baseUrl": "https://laurynsentry.visualstudio.com/",
  688. },
  689. },
  690. "resource": {
  691. "revisedBy": {
  692. "displayName": "lauryn",
  693. "name": "lauryn <lauryn@sentry.io>",
  694. "url": "https://app.vssps.visualstudio.com/A90e9a854-eb98-4c56-ae1a-035a0f331dd6/_apis/Identities/21354f98-ab06-67d9-b974-5a54d992082e",
  695. "imageUrl": "https://laurynsentry.visualstudio.com/_api/_common/identityImage?id=21354f98-ab06-67d9-b974-5a54d992082e",
  696. "descriptor": "msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl",
  697. "_links": {
  698. "avatar": {
  699. "href": "https://laurynsentry.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.MjEzNTRmOTgtYWIwNi03N2Q5LWI5NzQtNWE1NGQ5OTIwODJl"
  700. }
  701. },
  702. "uniqueName": "lauryn@sentry.io",
  703. "id": "21354f98-ab06-67d9-b974-5a54d992082e",
  704. },
  705. "revisedDate": "9999-01-01T00:00:00 Z",
  706. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates/3",
  707. "fields": {
  708. "System.AuthorizedDate": {
  709. "newValue": "2018-07-05T23:23:09.493 Z",
  710. "oldValue": "2018-07-05T23:21:38.243 Z",
  711. },
  712. "System.State": {"oldValue": "New", "newValue": "Resolved"},
  713. "System.Watermark": {"newValue": 83, "oldValue": 82},
  714. "System.Rev": {"newValue": 3, "oldValue": 2},
  715. "System.RevisedDate": {
  716. "newValue": "9999-01-01T00:00:00 Z",
  717. "oldValue": "2018-07-05T23:23:09.493 Z",
  718. },
  719. "System.ChangedDate": {
  720. "newValue": "2018-07-05T23:23:09.493 Z",
  721. "oldValue": "2018-07-05T23:21:38.243 Z",
  722. },
  723. },
  724. "workItemId": 33,
  725. "rev": 3,
  726. "_links": {
  727. "self": {
  728. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates/3"
  729. },
  730. "workItemUpdates": {
  731. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/updates"
  732. },
  733. "html": {
  734. "href": "https://laurynsentry.visualstudio.com/web/wi.aspx?pcguid=80ded3e8-3cd3-43b1-9f96-52032624aa3a&id=33"
  735. },
  736. "parent": {
  737. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33"
  738. },
  739. },
  740. "id": 3,
  741. "revision": {
  742. "url": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions/3",
  743. "fields": {
  744. "System.AreaPath": "MyFirstProject",
  745. "System.WorkItemType": "Bug",
  746. "System.Reason": "New",
  747. "System.Title": "NotImplementedError:Visual Studio Team Services requires an organization_id",
  748. "Microsoft.VSTS.Common.Priority": 2,
  749. "System.CreatedBy": "lauryn <lauryn@sentry.io>",
  750. "Microsoft.VSTS.Common.StateChangeDate": "2018-07-05T23:21:25.847 Z",
  751. "System.CreatedDate": "2018-07-05T23:21:25.847 Z",
  752. "System.TeamProject": "MyFirstProject",
  753. "Microsoft.VSTS.Common.ValueArea": "Business",
  754. "System.State": "New",
  755. "System.Description": '<p><a href="https: //lauryn.ngrok.io/sentry/internal/issues/196/">https: //lauryn.ngrok.io/sentry/internal/issues/196/</a></p>\n<pre><code>NotImplementedError:Visual Studio Team Services requires an organization_id\n(57 additional frame(s) were not displayed)\n...\n File &quot;sentry/tasks/base.py&quot;',
  756. "System.ChangedBy": "lauryn <lauryn@sentry.io>",
  757. "System.ChangedDate": "2018-07-05T23:23:09.493 Z",
  758. "Microsoft.VSTS.Common.Severity": "3 - Medium",
  759. "System.IterationPath": "MyFirstProject",
  760. },
  761. "rev": 3,
  762. "id": 33,
  763. "_links": {
  764. "self": {
  765. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions/3"
  766. },
  767. "workItemRevisions": {
  768. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33/revisions"
  769. },
  770. "parent": {
  771. "href": "https://laurynsentry.visualstudio.com/c0bf429a-c03c-4a99-9336-d45be74db5a6/_apis/wit/workItems/33"
  772. },
  773. },
  774. },
  775. },
  776. "eventType": "workitem.updated",
  777. "detailedMessage": None,
  778. "createdDate": "2018-07-05T23:23:11.1935112 Z",
  779. "id": "cc349c85-6595-4939-9b69-f89480be6a26",
  780. "resourceVersion": "1.0",
  781. "notificationId": 2,
  782. "subscriptionId": "7405a600-6a25-48e6-81b6-1dde044783ad",
  783. "publisherId": "tfs",
  784. "message": None,
  785. }
  786. WORK_ITEM_STATES = {
  787. "count": 5,
  788. "value": [
  789. {"name": "New", "color": "b2b2b2", "category": "Proposed"},
  790. {"name": "Active", "color": "007acc", "category": "InProgress"},
  791. {"name": "CustomState", "color": "5688E0", "category": "InProgress"},
  792. {"name": "Resolved", "color": "ff9d00", "category": "Resolved"},
  793. {"name": "Closed", "color": "339933", "category": "Completed"},
  794. ],
  795. }
  796. GET_PROJECTS_RESPONSE = """{
  797. "count": 1,
  798. "value": [{
  799. "id": "ac7c05bb-7f8e-4880-85a6-e08f37fd4a10",
  800. "name": "Fabrikam-Fiber-Git",
  801. "url": "https://jess-dev.visualstudio.com/_apis/projects/ac7c05bb-7f8e-4880-85a6-e08f37fd4a10",
  802. "state": "wellFormed",
  803. "revision": 16,
  804. "visibility": "private"
  805. }]
  806. }"""