vsts.py 37 KB

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