bitbucket.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. from collections import OrderedDict
  2. COMPARE_COMMITS_EXAMPLE = b"""{
  3. "pagelen": 30,
  4. "values":
  5. [{"hash": "e18e4e72de0d824edfbe0d73efe34cbd0d01d301",
  6. "repository": {"links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs"}, "avatar": {"href": "https://bitbucket.org/sentryuser/newsdiffs/avatar/32/"}}, "type": "repository", "name": "newsdiffs", "full_name": "sentryuser/newsdiffs", "uuid": "{c78dfb25-7882-4550-97b1-4e0d38f32859}"}, "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "comments": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/comments"}, "patch": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/patch/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs/commits/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "diff": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/diff/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "approve": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/approve"}, "statuses": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/statuses"}},
  7. "author": {
  8. "raw": "Sentry User <sentryuser@getsentry.com>",
  9. "type": "author"
  10. },
  11. "parents": [{"hash": "26de9b63d09aa9c787e899f149c672023e292925", "type": "commit", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/26de9b63d09aa9c787e899f149c672023e292925"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs/commits/26de9b63d09aa9c787e899f149c672023e292925"}}}], "date": "2017-05-16T23:21:40+00:00", "message": "README.md edited online with Bitbucket", "type": "commit"}],
  12. "next": "https://api.bitbucket.org/2.0/repositories/sentryuser/sentryrepo/commits/e18e4e72de0d824edfbe0d73efe34cbd0d01d301?page=2"
  13. }
  14. """
  15. GET_LAST_COMMITS_EXAMPLE = b"""{
  16. "pagelen": 30,
  17. "values":
  18. [{"hash": "e18e4e72de0d824edfbe0d73efe34cbd0d01d301",
  19. "repository": {"links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs"}, "avatar": {"href": "https://bitbucket.org/sentryuser/newsdiffs/avatar/32/"}}, "type": "repository", "name": "newsdiffs", "full_name": "sentryuser/newsdiffs", "uuid": "{c78dfb25-7882-4550-97b1-4e0d38f32859}"}, "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "comments": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/comments"}, "patch": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/patch/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs/commits/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "diff": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/diff/e18e4e72de0d824edfbe0d73efe34cbd0d01d301"}, "approve": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/approve"}, "statuses": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/e18e4e72de0d824edfbe0d73efe34cbd0d01d301/statuses"}}, "author": {"raw": "Sentry User <sentryuser@getsentry.com>", "type": "author", "user": {"username": "sentryuser", "display_name": "Sentry User", "type": "user", "uuid": "{b128e0f6-196a-4dde-b72d-f42abc6dc239}", "links": {"self": {"href": "https://api.bitbucket.org/2.0/users/sentryuser"}, "html": {"href": "https://bitbucket.org/sentryuser/"}, "avatar": {"href": "https://bitbucket.org/account/sentryuser/avatar/32/"}}}}, "parents": [{"hash": "26de9b63d09aa9c787e899f149c672023e292925", "type": "commit", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commit/26de9b63d09aa9c787e899f149c672023e292925"}, "html": {"href": "https://bitbucket.org/sentryuser/newsdiffs/commits/26de9b63d09aa9c787e899f149c672023e292925"}}}], "date": "2017-05-16T23:21:40+00:00", "message": "README.md edited online with Bitbucket", "type": "commit"}],
  20. "next": "https://api.bitbucket.org/2.0/repositories/sentryuser/newsdiffs/commits/e18e4e72de0d824edfbe0d73efe34cbd0d01d301?page=2"
  21. }
  22. """
  23. COMMIT_DIFF_PATCH = rb"""diff --git a/README.md b/README.md
  24. index 89821ce..9e09a8a 100644
  25. --- a/README.md
  26. +++ b/README.md
  27. @@ -1 +1 @@
  28. -A twitter bot to when words are said by the NYT for the first time.
  29. \ No newline at end of file
  30. +A twitter bot to when words are said by the NYT for the first time.sdfsdf
  31. \ No newline at end of file"""
  32. PUSH_EVENT_EXAMPLE = b"""{
  33. "push": {
  34. "changes": [
  35. {
  36. "links": {
  37. "html": {
  38. "href": "https://bitbucket.org/maxbittker/newsdiffs/branches/compare/e0e377d186e4f0e937bdb487a23384fe002df649..8f5952f4dcffd7b311181d48eb0394b0cca21410"
  39. },
  40. "commits": {
  41. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commits?include=e0e377d186e4f0e937bdb487a23384fe002df649&exclude=8f5952f4dcffd7b311181d48eb0394b0cca21410"
  42. },
  43. "diff": {
  44. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/diff/e0e377d186e4f0e937bdb487a23384fe002df649..8f5952f4dcffd7b311181d48eb0394b0cca21410"
  45. }
  46. },
  47. "commits": [
  48. {
  49. "links": {
  50. "approve": {
  51. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/e0e377d186e4f0e937bdb487a23384fe002df649/approve"
  52. },
  53. "statuses": {
  54. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/e0e377d186e4f0e937bdb487a23384fe002df649/statuses"
  55. },
  56. "comments": {
  57. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/e0e377d186e4f0e937bdb487a23384fe002df649/comments"
  58. },
  59. "self": {
  60. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/e0e377d186e4f0e937bdb487a23384fe002df649"
  61. },
  62. "patch": {
  63. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/patch/e0e377d186e4f0e937bdb487a23384fe002df649"
  64. },
  65. "html": {
  66. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/e0e377d186e4f0e937bdb487a23384fe002df649"
  67. },
  68. "diff": {
  69. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/diff/e0e377d186e4f0e937bdb487a23384fe002df649"
  70. }
  71. },
  72. "date": "2017-05-24T01:05:47+00:00",
  73. "hash": "e0e377d186e4f0e937bdb487a23384fe002df649",
  74. "parents": [
  75. {
  76. "type": "commit",
  77. "links": {
  78. "html": {
  79. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  80. },
  81. "self": {
  82. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  83. }
  84. },
  85. "hash": "8f5952f4dcffd7b311181d48eb0394b0cca21410"
  86. }
  87. ],
  88. "type": "commit",
  89. "message": "README.md edited online with Bitbucket",
  90. "author": {
  91. "type": "author",
  92. "user": {
  93. "type": "user",
  94. "display_name": "Max Bittker",
  95. "uuid": "{b128e0f6-196a-4dde-b72d-f42abc6dc239}",
  96. "username": "maxbittker",
  97. "links": {
  98. "html": {
  99. "href": "https://bitbucket.org/maxbittker/"
  100. },
  101. "avatar": {
  102. "href": "https://bitbucket.org/account/maxbittker/avatar/32/"
  103. },
  104. "self": {
  105. "href": "https://api.bitbucket.org/2.0/users/maxbittker"
  106. }
  107. }
  108. },
  109. "raw": "Max Bittker <max@getsentry.com>"
  110. }
  111. }
  112. ],
  113. "old": {
  114. "type": "branch",
  115. "links": {
  116. "html": {
  117. "href": "https://bitbucket.org/maxbittker/newsdiffs/branch/master"
  118. },
  119. "commits": {
  120. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commits/master"
  121. },
  122. "self": {
  123. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/refs/branches/master"
  124. }
  125. },
  126. "target": {
  127. "links": {
  128. "html": {
  129. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  130. },
  131. "self": {
  132. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  133. }
  134. },
  135. "date": "2017-05-19T22:53:22+00:00",
  136. "hash": "8f5952f4dcffd7b311181d48eb0394b0cca21410",
  137. "parents": [
  138. {
  139. "type": "commit",
  140. "links": {
  141. "html": {
  142. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/1cdfa36e62e615cdc73a1d5fcff1c706965b186d"
  143. },
  144. "self": {
  145. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/1cdfa36e62e615cdc73a1d5fcff1c706965b186d"
  146. }
  147. },
  148. "hash": "1cdfa36e62e615cdc73a1d5fcff1c706965b186d"
  149. }
  150. ],
  151. "type": "commit",
  152. "message": "README.md edited online with Bitbucket",
  153. "author": {
  154. "type": "author",
  155. "raw": "Max Bittker <max@getsentry.com>"
  156. }
  157. },
  158. "name": "master"
  159. },
  160. "truncated": false,
  161. "new": {
  162. "type": "branch",
  163. "links": {
  164. "html": {
  165. "href": "https://bitbucket.org/maxbittker/newsdiffs/branch/master"
  166. },
  167. "commits": {
  168. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commits/master"
  169. },
  170. "self": {
  171. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/refs/branches/master"
  172. }
  173. },
  174. "target": {
  175. "links": {
  176. "html": {
  177. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/e0e377d186e4f0e937bdb487a23384fe002df649"
  178. },
  179. "self": {
  180. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/e0e377d186e4f0e937bdb487a23384fe002df649"
  181. }
  182. },
  183. "date": "2017-05-24T01:05:47+00:00",
  184. "hash": "e0e377d186e4f0e937bdb487a23384fe002df649",
  185. "parents": [
  186. {
  187. "type": "commit",
  188. "links": {
  189. "html": {
  190. "href": "https://bitbucket.org/maxbittker/newsdiffs/commits/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  191. },
  192. "self": {
  193. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commit/8f5952f4dcffd7b311181d48eb0394b0cca21410"
  194. }
  195. },
  196. "hash": "8f5952f4dcffd7b311181d48eb0394b0cca21410"
  197. }
  198. ],
  199. "type": "commit",
  200. "message": "README.md edited online with Bitbucket",
  201. "author": {
  202. "type": "author",
  203. "raw": "Max Bittker <max@getsentry.com>"
  204. }
  205. },
  206. "name": "master"
  207. },
  208. "created": false,
  209. "forced": false,
  210. "closed": false
  211. }
  212. ]
  213. },
  214. "repository": {
  215. "links": {
  216. "html": {
  217. "href": "https://bitbucket.org/maxbittker/newsdiffs"
  218. },
  219. "avatar": {
  220. "href": "https://bitbucket.org/maxbittker/newsdiffs/avatar/32/"
  221. },
  222. "self": {
  223. "href": "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs"
  224. }
  225. },
  226. "full_name": "maxbittker/newsdiffs",
  227. "scm": "git",
  228. "uuid": "{c78dfb25-7882-4550-97b1-4e0d38f32859}",
  229. "type": "repository",
  230. "is_private": false,
  231. "owner": {
  232. "type": "user",
  233. "display_name": "Max Bittker",
  234. "uuid": "{b128e0f6-196a-4dde-b72d-f42abc6dc239}",
  235. "username": "maxbittker",
  236. "links": {
  237. "html": {
  238. "href": "https://bitbucket.org/maxbittker/"
  239. },
  240. "avatar": {
  241. "href": "https://bitbucket.org/account/maxbittker/avatar/32/"
  242. },
  243. "self": {
  244. "href": "https://api.bitbucket.org/2.0/users/maxbittker"
  245. }
  246. }
  247. },
  248. "name": "newsdiffs",
  249. "website": ""
  250. },
  251. "actor": {
  252. "type": "user",
  253. "display_name": "Max Bittker",
  254. "uuid": "{b128e0f6-196a-4dde-b72d-f42abc6dc239}",
  255. "username": "maxbittker",
  256. "links": {
  257. "html": {
  258. "href": "https://bitbucket.org/maxbittker/"
  259. },
  260. "avatar": {
  261. "href": "https://bitbucket.org/account/maxbittker/avatar/32/"
  262. },
  263. "self": {
  264. "href": "https://api.bitbucket.org/2.0/users/maxbittker"
  265. }
  266. }
  267. }
  268. }
  269. """
  270. REPO = {
  271. "scm": "git",
  272. "website": "",
  273. "has_wiki": True,
  274. "description": "",
  275. "links": OrderedDict(
  276. [
  277. (
  278. "watchers",
  279. OrderedDict(
  280. [
  281. (
  282. "href",
  283. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/watchers",
  284. )
  285. ]
  286. ),
  287. ),
  288. (
  289. "branches",
  290. OrderedDict(
  291. [
  292. (
  293. "href",
  294. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/branches",
  295. )
  296. ]
  297. ),
  298. ),
  299. (
  300. "tags",
  301. OrderedDict(
  302. [
  303. (
  304. "href",
  305. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/tags",
  306. )
  307. ]
  308. ),
  309. ),
  310. (
  311. "commits",
  312. OrderedDict(
  313. [
  314. (
  315. "href",
  316. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/commits",
  317. )
  318. ]
  319. ),
  320. ),
  321. (
  322. "clone",
  323. [
  324. OrderedDict(
  325. [
  326. (
  327. "href",
  328. "https://laurynsentry@bitbucket.org/laurynsentry/helloworld.git",
  329. ),
  330. ("name", "https"),
  331. ]
  332. ),
  333. OrderedDict(
  334. [
  335. ("href", "git@bitbucket.org:laurynsentry/helloworld.git"),
  336. ("name", "ssh"),
  337. ]
  338. ),
  339. ],
  340. ),
  341. (
  342. "self",
  343. OrderedDict(
  344. [
  345. (
  346. "href",
  347. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld",
  348. )
  349. ]
  350. ),
  351. ),
  352. (
  353. "source",
  354. OrderedDict(
  355. [
  356. (
  357. "href",
  358. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/src",
  359. )
  360. ]
  361. ),
  362. ),
  363. ("html", OrderedDict([("href", "https://bitbucket.org/laurynsentry/helloworld")])),
  364. (
  365. "avatar",
  366. OrderedDict(
  367. [
  368. (
  369. "href",
  370. "https://bytebucket.org/ravatar/%7B2a47ac11-098a-4054-8496-193754cae14b%7D?ts=default",
  371. )
  372. ]
  373. ),
  374. ),
  375. (
  376. "hooks",
  377. OrderedDict(
  378. [
  379. (
  380. "href",
  381. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/hooks",
  382. )
  383. ]
  384. ),
  385. ),
  386. (
  387. "forks",
  388. OrderedDict(
  389. [
  390. (
  391. "href",
  392. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/forks",
  393. )
  394. ]
  395. ),
  396. ),
  397. (
  398. "downloads",
  399. OrderedDict(
  400. [
  401. (
  402. "href",
  403. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/downloads",
  404. )
  405. ]
  406. ),
  407. ),
  408. (
  409. "issues",
  410. OrderedDict(
  411. [
  412. (
  413. "href",
  414. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/issues",
  415. )
  416. ]
  417. ),
  418. ),
  419. (
  420. "pullrequests",
  421. OrderedDict(
  422. [
  423. (
  424. "href",
  425. "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/pullrequests",
  426. )
  427. ]
  428. ),
  429. ),
  430. ]
  431. ),
  432. "created_on": "2018-05-14T23:53:37.377674+00:00",
  433. "full_name": "laurynsentry/helloworld",
  434. "owner": OrderedDict(
  435. [
  436. ("username", "laurynsentry"),
  437. ("display_name", "Lauryn Brown"),
  438. ("account_id", "5a00066393915e620920e0ae"),
  439. (
  440. "links",
  441. OrderedDict(
  442. [
  443. (
  444. "self",
  445. OrderedDict(
  446. [("href", "https://api.bitbucket.org/2.0/users/laurynsentry")]
  447. ),
  448. ),
  449. ("html", OrderedDict([("href", "https://bitbucket.org/laurynsentry/")])),
  450. (
  451. "avatar",
  452. OrderedDict(
  453. [("href", "https://bitbucket.org/account/laurynsentry/avatar/")]
  454. ),
  455. ),
  456. ]
  457. ),
  458. ),
  459. ("type", "user"),
  460. ("uuid", "{e50a27fe-0686-4d75-ba44-d27608bbb718}"),
  461. ]
  462. ),
  463. "has_issues": True,
  464. "slug": "helloworld",
  465. "is_private": False,
  466. "size": 221349,
  467. "name": "HelloWorld",
  468. "language": "",
  469. "fork_policy": "allow_forks",
  470. "uuid": "{2a47ac11-098a-4054-8496-193754cae14b}",
  471. "mainbranch": OrderedDict([("type", "branch"), ("name", "master")]),
  472. "updated_on": "2018-05-30T18:21:08.780363+00:00",
  473. "type": "repository",
  474. }