vsts.py 36 KB

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