/engine/hooks/tasks_bitbucket_test.go

https://github.com/ovh/cds · Go · 3079 lines · 3011 code · 68 blank · 0 comment · 14 complexity · 3b58b2a6de972863f5cc2bee8b2df13c MD5 · raw file

Large files are truncated click here to view the full file

  1. package hooks
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/ovh/cds/engine/api/test"
  6. "github.com/ovh/cds/sdk"
  7. "github.com/ovh/cds/sdk/log"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func Test_doWebHookExecutionBitbucket(t *testing.T) {
  11. log.SetLogger(t)
  12. s, cancel := setupTestHookService(t)
  13. defer cancel()
  14. task := &sdk.TaskExecution{
  15. UUID: sdk.RandomString(10),
  16. Type: TypeRepoManagerWebHook,
  17. WebHook: &sdk.WebHookExecution{
  18. RequestBody: []byte(bitbucketPushEvent),
  19. RequestHeader: map[string][]string{
  20. BitbucketHeader: {"repo:refs_changed"},
  21. },
  22. RequestURL: "",
  23. },
  24. }
  25. hs, err := s.doWebHookExecution(context.TODO(), task)
  26. test.NoError(t, err)
  27. assert.Equal(t, 1, len(hs))
  28. assert.Equal(t, "repo:refs_changed", hs[0].Payload["git.hook"])
  29. assert.Equal(t, "name-of-branch", hs[0].Payload["git.branch"])
  30. assert.Equal(t, "steven.guiheux", hs[0].Payload["git.author"])
  31. assert.Equal(t, "9f4fac7ec5642099982a86f584f2c4a362adb670", hs[0].Payload["git.hash"])
  32. }
  33. func Test_doWebHookExecutionBitbucketPRReviewerUpdated(t *testing.T) {
  34. log.SetLogger(t)
  35. s, cancel := setupTestHookService(t)
  36. defer cancel()
  37. task := &sdk.TaskExecution{
  38. UUID: sdk.RandomString(10),
  39. Type: TypeRepoManagerWebHook,
  40. WebHook: &sdk.WebHookExecution{
  41. RequestBody: []byte(bitbucketPrReviewerUpdated),
  42. RequestHeader: map[string][]string{
  43. BitbucketHeader: {"pr:reviewer:updated"},
  44. },
  45. RequestURL: "",
  46. },
  47. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  48. sdk.HookConfigEventFilter: {
  49. Value: "pr:opened;pr:approved;pr:reviewer:updated",
  50. },
  51. },
  52. }
  53. hs, err := s.doWebHookExecution(context.TODO(), task)
  54. test.NoError(t, err)
  55. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  56. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  57. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  58. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  59. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  60. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  61. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  62. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  63. test.Equal(t, "pr:reviewer:updated", hs[0].Payload[GIT_EVENT])
  64. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  65. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  66. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  67. test.Equal(t, "666", hs[0].Payload[PR_ID])
  68. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  69. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  70. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  71. }
  72. func Test_doWebHookExecutionBitbucketPRReviewerApproved(t *testing.T) {
  73. log.SetLogger(t)
  74. s, cancel := setupTestHookService(t)
  75. defer cancel()
  76. task := &sdk.TaskExecution{
  77. UUID: sdk.RandomString(10),
  78. Type: TypeRepoManagerWebHook,
  79. WebHook: &sdk.WebHookExecution{
  80. RequestBody: []byte(bitbucketPrReviewerApproved),
  81. RequestHeader: map[string][]string{
  82. BitbucketHeader: {"pr:reviewer:approved"},
  83. },
  84. RequestURL: "",
  85. },
  86. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  87. sdk.HookConfigEventFilter: {
  88. Value: "pr:opened;pr:approved;pr:reviewer:approved",
  89. },
  90. },
  91. }
  92. hs, err := s.doWebHookExecution(context.TODO(), task)
  93. test.NoError(t, err)
  94. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  95. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  96. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  97. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  98. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  99. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  100. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  101. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  102. test.Equal(t, "pr:reviewer:approved", hs[0].Payload[GIT_EVENT])
  103. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  104. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  105. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  106. test.Equal(t, "666", hs[0].Payload[PR_ID])
  107. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  108. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  109. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  110. test.Equal(t, "francois.samin", hs[0].Payload[PR_REVIEWER])
  111. test.Equal(t, "francois.samin@foo", hs[0].Payload[PR_REVIEWER_EMAIL])
  112. test.Equal(t, "APPROVED", hs[0].Payload[PR_REVIEWER_STATUS])
  113. test.Equal(t, "REVIEWER", hs[0].Payload[PR_REVIEWER_ROLE])
  114. test.Equal(t, "UNAPPROVED", hs[0].Payload[PR_PREVIOUS_STATE])
  115. }
  116. func Test_doWebHookExecutionBitbucketPRReviewerUnapproved(t *testing.T) {
  117. log.SetLogger(t)
  118. s, cancel := setupTestHookService(t)
  119. defer cancel()
  120. task := &sdk.TaskExecution{
  121. UUID: sdk.RandomString(10),
  122. Type: TypeRepoManagerWebHook,
  123. WebHook: &sdk.WebHookExecution{
  124. RequestBody: []byte(bitbucketPrReviewerUnapproved),
  125. RequestHeader: map[string][]string{
  126. BitbucketHeader: {"pr:reviewer:unapproved"},
  127. },
  128. RequestURL: "",
  129. },
  130. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  131. sdk.HookConfigEventFilter: {
  132. Value: "pr:opened;pr:approved;pr:reviewer:unapproved",
  133. },
  134. },
  135. }
  136. hs, err := s.doWebHookExecution(context.TODO(), task)
  137. test.NoError(t, err)
  138. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  139. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  140. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  141. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  142. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  143. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  144. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  145. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  146. test.Equal(t, "pr:reviewer:unapproved", hs[0].Payload[GIT_EVENT])
  147. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  148. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  149. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  150. test.Equal(t, "666", hs[0].Payload[PR_ID])
  151. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  152. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  153. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  154. test.Equal(t, "francois.samin", hs[0].Payload[PR_REVIEWER])
  155. test.Equal(t, "francois.samin@foo", hs[0].Payload[PR_REVIEWER_EMAIL])
  156. test.Equal(t, "UNAPPROVED", hs[0].Payload[PR_REVIEWER_STATUS])
  157. test.Equal(t, "REVIEWER", hs[0].Payload[PR_REVIEWER_ROLE])
  158. test.Equal(t, "APPROVED", hs[0].Payload[PR_PREVIOUS_STATE])
  159. }
  160. func Test_doWebHookExecutionBitbucketPRReviewerNeedsWork(t *testing.T) {
  161. log.SetLogger(t)
  162. s, cancel := setupTestHookService(t)
  163. defer cancel()
  164. task := &sdk.TaskExecution{
  165. UUID: sdk.RandomString(10),
  166. Type: TypeRepoManagerWebHook,
  167. WebHook: &sdk.WebHookExecution{
  168. RequestBody: []byte(bitbucketPrReviewerNeedsWorks),
  169. RequestHeader: map[string][]string{
  170. BitbucketHeader: {"pr:reviewer:needs_work"},
  171. },
  172. RequestURL: "",
  173. },
  174. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  175. sdk.HookConfigEventFilter: {
  176. Value: "pr:opened;pr:approved;pr:reviewer:needs_work",
  177. },
  178. },
  179. }
  180. hs, err := s.doWebHookExecution(context.TODO(), task)
  181. test.NoError(t, err)
  182. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  183. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  184. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  185. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  186. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  187. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  188. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  189. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  190. test.Equal(t, "pr:reviewer:needs_work", hs[0].Payload[GIT_EVENT])
  191. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  192. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  193. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  194. test.Equal(t, "666", hs[0].Payload[PR_ID])
  195. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  196. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  197. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  198. test.Equal(t, "francois.samin", hs[0].Payload[PR_REVIEWER])
  199. test.Equal(t, "francois.samin@foo", hs[0].Payload[PR_REVIEWER_EMAIL])
  200. test.Equal(t, "NEEDS_WORK", hs[0].Payload[PR_REVIEWER_STATUS])
  201. test.Equal(t, "REVIEWER", hs[0].Payload[PR_REVIEWER_ROLE])
  202. test.Equal(t, "UNAPPROVED", hs[0].Payload[PR_PREVIOUS_STATE])
  203. }
  204. func Test_doWebHookExecutionBitbucketPRCommentAdded(t *testing.T) {
  205. log.SetLogger(t)
  206. s, cancel := setupTestHookService(t)
  207. defer cancel()
  208. task := &sdk.TaskExecution{
  209. UUID: sdk.RandomString(10),
  210. Type: TypeRepoManagerWebHook,
  211. WebHook: &sdk.WebHookExecution{
  212. RequestBody: []byte(bitbucketPrCommentAdded),
  213. RequestHeader: map[string][]string{
  214. BitbucketHeader: {"pr:comment:added"},
  215. },
  216. RequestURL: "",
  217. },
  218. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  219. sdk.HookConfigEventFilter: {
  220. Value: "pr:opened;pr:approved;pr:comment:added",
  221. },
  222. },
  223. }
  224. hs, err := s.doWebHookExecution(context.TODO(), task)
  225. test.NoError(t, err)
  226. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  227. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  228. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  229. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  230. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  231. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  232. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  233. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  234. test.Equal(t, "pr:comment:added", hs[0].Payload[GIT_EVENT])
  235. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  236. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  237. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  238. test.Equal(t, "666", hs[0].Payload[PR_ID])
  239. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  240. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  241. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  242. test.Equal(t, "my comment added", hs[0].Payload[PR_COMMENT_TEXT])
  243. test.Equal(t, "steven.guiheux", hs[0].Payload[PR_COMMENT_AUTHOR])
  244. test.Equal(t, "steven.guiheux@foo", hs[0].Payload[PR_COMMENT_AUTHOR_EMAIL])
  245. }
  246. func Test_doWebHookExecutionBitbucketPRCommentDeleted(t *testing.T) {
  247. log.SetLogger(t)
  248. s, cancel := setupTestHookService(t)
  249. defer cancel()
  250. task := &sdk.TaskExecution{
  251. UUID: sdk.RandomString(10),
  252. Type: TypeRepoManagerWebHook,
  253. WebHook: &sdk.WebHookExecution{
  254. RequestBody: []byte(bitbucketPrCommentDeleted),
  255. RequestHeader: map[string][]string{
  256. BitbucketHeader: {"pr:comment:deleted"},
  257. },
  258. RequestURL: "",
  259. },
  260. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  261. sdk.HookConfigEventFilter: {
  262. Value: "pr:opened;pr:approved;pr:comment:deleted",
  263. },
  264. },
  265. }
  266. hs, err := s.doWebHookExecution(context.TODO(), task)
  267. test.NoError(t, err)
  268. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  269. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  270. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  271. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  272. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  273. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  274. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  275. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  276. test.Equal(t, "pr:comment:deleted", hs[0].Payload[GIT_EVENT])
  277. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  278. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  279. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  280. test.Equal(t, "666", hs[0].Payload[PR_ID])
  281. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  282. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  283. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  284. test.Equal(t, "my comment deleted", hs[0].Payload[PR_COMMENT_TEXT])
  285. test.Equal(t, "steven.guiheux", hs[0].Payload[PR_COMMENT_AUTHOR])
  286. test.Equal(t, "steven.guiheux@foo", hs[0].Payload[PR_COMMENT_AUTHOR_EMAIL])
  287. }
  288. func Test_doWebHookExecutionBitbucketPRCommentModified(t *testing.T) {
  289. log.SetLogger(t)
  290. s, cancel := setupTestHookService(t)
  291. defer cancel()
  292. task := &sdk.TaskExecution{
  293. UUID: sdk.RandomString(10),
  294. Type: TypeRepoManagerWebHook,
  295. WebHook: &sdk.WebHookExecution{
  296. RequestBody: []byte(bitbucketPrCommentModified),
  297. RequestHeader: map[string][]string{
  298. BitbucketHeader: {"pr:comment:edited"},
  299. },
  300. RequestURL: "",
  301. },
  302. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  303. sdk.HookConfigEventFilter: {
  304. Value: "pr:opened;pr:approved;pr:comment:edited",
  305. },
  306. },
  307. }
  308. hs, err := s.doWebHookExecution(context.TODO(), task)
  309. test.NoError(t, err)
  310. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  311. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  312. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  313. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  314. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  315. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  316. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  317. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  318. test.Equal(t, "pr:comment:edited", hs[0].Payload[GIT_EVENT])
  319. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  320. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  321. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  322. test.Equal(t, "666", hs[0].Payload[PR_ID])
  323. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  324. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  325. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  326. test.Equal(t, "my comment edited", hs[0].Payload[PR_COMMENT_TEXT])
  327. test.Equal(t, "steven.guiheux", hs[0].Payload[PR_COMMENT_AUTHOR])
  328. test.Equal(t, "steven.guiheux@foo", hs[0].Payload[PR_COMMENT_AUTHOR_EMAIL])
  329. test.Equal(t, "moi aussi", hs[0].Payload[PR_COMMENT_TEXT_PREVIOUS])
  330. }
  331. func Test_doWebHookExecutionBitbucketPROpened(t *testing.T) {
  332. log.SetLogger(t)
  333. s, cancel := setupTestHookService(t)
  334. defer cancel()
  335. task := &sdk.TaskExecution{
  336. UUID: sdk.RandomString(10),
  337. Type: TypeRepoManagerWebHook,
  338. WebHook: &sdk.WebHookExecution{
  339. RequestBody: []byte(bitbucketPrOpened),
  340. RequestHeader: map[string][]string{
  341. BitbucketHeader: {"pr:opened"},
  342. },
  343. RequestURL: "",
  344. },
  345. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  346. sdk.HookConfigEventFilter: {
  347. Value: "pr:opened;pr:approved",
  348. },
  349. },
  350. }
  351. hs, err := s.doWebHookExecution(context.TODO(), task)
  352. test.NoError(t, err)
  353. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  354. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  355. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  356. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  357. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  358. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  359. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  360. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  361. test.Equal(t, "pr:opened", hs[0].Payload[GIT_EVENT])
  362. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  363. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  364. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  365. test.Equal(t, "666", hs[0].Payload[PR_ID])
  366. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  367. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  368. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  369. }
  370. func Test_doWebHookExecutionBitbucketPRModified(t *testing.T) {
  371. log.SetLogger(t)
  372. s, cancel := setupTestHookService(t)
  373. defer cancel()
  374. task := &sdk.TaskExecution{
  375. UUID: sdk.RandomString(10),
  376. Type: TypeRepoManagerWebHook,
  377. WebHook: &sdk.WebHookExecution{
  378. RequestBody: []byte(bitbucketPrModified),
  379. RequestHeader: map[string][]string{
  380. BitbucketHeader: {"pr:modified"},
  381. },
  382. RequestURL: "",
  383. },
  384. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  385. sdk.HookConfigEventFilter: {
  386. Value: "pr:opened;pr:modified",
  387. },
  388. },
  389. }
  390. hs, err := s.doWebHookExecution(context.TODO(), task)
  391. test.NoError(t, err)
  392. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  393. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  394. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  395. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  396. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  397. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  398. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  399. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  400. test.Equal(t, "pr:modified", hs[0].Payload[GIT_EVENT])
  401. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  402. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  403. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  404. test.Equal(t, "666", hs[0].Payload[PR_ID])
  405. test.Equal(t, "OPEN", hs[0].Payload[PR_STATE])
  406. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  407. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  408. test.Equal(t, "Update README.md", hs[0].Payload[PR_PREVIOUS_TITLE])
  409. test.Equal(t, "prev_branch", hs[0].Payload[PR_PREVIOUS_BRANCH])
  410. test.Equal(t, "0987654321", hs[0].Payload[PR_PREVIOUS_HASH])
  411. }
  412. func Test_doWebHookExecutionBitbucketPRMerged(t *testing.T) {
  413. log.SetLogger(t)
  414. s, cancel := setupTestHookService(t)
  415. defer cancel()
  416. task := &sdk.TaskExecution{
  417. UUID: sdk.RandomString(10),
  418. Type: TypeRepoManagerWebHook,
  419. WebHook: &sdk.WebHookExecution{
  420. RequestBody: []byte(bitbucketPrMerged),
  421. RequestHeader: map[string][]string{
  422. BitbucketHeader: {"pr:merged"},
  423. },
  424. RequestURL: "",
  425. },
  426. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  427. sdk.HookConfigEventFilter: {
  428. Value: "pr:opened;pr:merged",
  429. },
  430. },
  431. }
  432. hs, err := s.doWebHookExecution(context.TODO(), task)
  433. test.NoError(t, err)
  434. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  435. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  436. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  437. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  438. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  439. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  440. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  441. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  442. test.Equal(t, "pr:opened", hs[0].Payload[GIT_EVENT])
  443. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  444. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  445. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  446. test.Equal(t, "666", hs[0].Payload[PR_ID])
  447. test.Equal(t, "MERGED", hs[0].Payload[PR_STATE])
  448. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  449. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  450. }
  451. func Test_doWebHookExecutionBitbucketPRDeleted(t *testing.T) {
  452. log.SetLogger(t)
  453. s, cancel := setupTestHookService(t)
  454. defer cancel()
  455. task := &sdk.TaskExecution{
  456. UUID: sdk.RandomString(10),
  457. Type: TypeRepoManagerWebHook,
  458. WebHook: &sdk.WebHookExecution{
  459. RequestBody: []byte(bitbucketPrDeleted),
  460. RequestHeader: map[string][]string{
  461. BitbucketHeader: {"pr:deleted"},
  462. },
  463. RequestURL: "",
  464. },
  465. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  466. sdk.HookConfigEventFilter: {
  467. Value: "pr:deleted;pr:approved",
  468. },
  469. },
  470. }
  471. hs, err := s.doWebHookExecution(context.TODO(), task)
  472. test.NoError(t, err)
  473. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  474. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  475. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  476. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  477. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  478. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  479. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  480. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  481. test.Equal(t, "pr:deleted", hs[0].Payload[GIT_EVENT])
  482. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  483. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  484. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  485. test.Equal(t, "666", hs[0].Payload[PR_ID])
  486. test.Equal(t, "DELETED", hs[0].Payload[PR_STATE])
  487. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  488. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  489. }
  490. func Test_doWebHookExecutionBitbucketPRDeclined(t *testing.T) {
  491. log.SetLogger(t)
  492. s, cancel := setupTestHookService(t)
  493. defer cancel()
  494. task := &sdk.TaskExecution{
  495. UUID: sdk.RandomString(10),
  496. Type: TypeRepoManagerWebHook,
  497. WebHook: &sdk.WebHookExecution{
  498. RequestBody: []byte(bitbucketPrDeclined),
  499. RequestHeader: map[string][]string{
  500. BitbucketHeader: {"pr:declined"},
  501. },
  502. RequestURL: "",
  503. },
  504. Config: map[string]sdk.WorkflowNodeHookConfigValue{
  505. sdk.HookConfigEventFilter: {
  506. Value: "pr:deleted;pr:declined",
  507. },
  508. },
  509. }
  510. hs, err := s.doWebHookExecution(context.TODO(), task)
  511. test.NoError(t, err)
  512. test.Equal(t, "john.doe", hs[0].Payload[CDS_TRIGGERED_BY_USERNAME])
  513. test.Equal(t, "john doe", hs[0].Payload[CDS_TRIGGERED_BY_FULLNAME])
  514. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[CDS_TRIGGERED_BY_EMAIL])
  515. test.Equal(t, "john.doe", hs[0].Payload[GIT_AUTHOR])
  516. test.Equal(t, "john.doe@targate.fr", hs[0].Payload[GIT_AUTHOR_EMAIL])
  517. test.Equal(t, "dest_branch", hs[0].Payload[GIT_BRANCH_DEST])
  518. test.Equal(t, "my/repo", hs[0].Payload[GIT_REPOSITORY_DEST])
  519. test.Equal(t, "654321654321", hs[0].Payload[GIT_HASH_DEST])
  520. test.Equal(t, "pr:declined", hs[0].Payload[GIT_EVENT])
  521. test.Equal(t, "src_branch", hs[0].Payload[GIT_BRANCH])
  522. test.Equal(t, "12345671234567", hs[0].Payload[GIT_HASH])
  523. test.Equal(t, "1234567", hs[0].Payload[GIT_HASH_SHORT])
  524. test.Equal(t, "666", hs[0].Payload[PR_ID])
  525. test.Equal(t, "DECLINED", hs[0].Payload[PR_STATE])
  526. test.Equal(t, "My First PR", hs[0].Payload[PR_TITLE])
  527. test.Equal(t, "fork/repo", hs[0].Payload[GIT_REPOSITORY])
  528. }
  529. func Test_doWebHookExecutionBitbucketMultiple(t *testing.T) {
  530. log.SetLogger(t)
  531. s, cancel := setupTestHookService(t)
  532. defer cancel()
  533. task := &sdk.TaskExecution{
  534. UUID: sdk.RandomString(10),
  535. Type: TypeRepoManagerWebHook,
  536. WebHook: &sdk.WebHookExecution{
  537. RequestBody: []byte(bitbucketMultiplePushEvent),
  538. RequestHeader: map[string][]string{
  539. BitbucketHeader: {"repo:refs_changed"},
  540. },
  541. RequestURL: "",
  542. },
  543. }
  544. hs, err := s.doWebHookExecution(context.TODO(), task)
  545. test.NoError(t, err)
  546. assert.Equal(t, 2, len(hs))
  547. assert.Equal(t, "name-of-branch", hs[0].Payload["git.branch"])
  548. assert.Equal(t, "steven.guiheux", hs[0].Payload["git.author"])
  549. assert.Equal(t, "9f4fac7ec5642099982a86f584f2c4a362adb670", hs[0].Payload["git.hash"])
  550. assert.Equal(t, "name-of-branch-bis", hs[1].Payload["git.branch"])
  551. assert.Equal(t, "steven.guiheux", hs[1].Payload["git.author"])
  552. assert.Equal(t, "9f4fac7ec5642099982a86f584f2c4a362adb670", hs[0].Payload["git.hash"])
  553. }
  554. var bitbucketPrReviewerUpdated = `
  555. {
  556. "eventKey": "pr:reviewer:updated",
  557. "date": "2019-10-15T09:33:38+0200",
  558. "actor": {
  559. "name": "john.doe",
  560. "emailAddress": "john.doe@targate.fr",
  561. "id": 1363,
  562. "displayName": "john doe",
  563. "active": true,
  564. "slug": "foo",
  565. "type": "NORMAL",
  566. "links": {
  567. "self": [
  568. {
  569. "href": "https://bitbucket/users/bar"
  570. }
  571. ]
  572. }
  573. },
  574. "pullRequest": {
  575. "id": 666,
  576. "version": 0,
  577. "title": "My First PR",
  578. "state": "OPEN",
  579. "open": true,
  580. "closed": false,
  581. "createdDate": 1569939813210,
  582. "updatedDate": 1569939813210,
  583. "fromRef": {
  584. "id": "refs/heads/workflowUpdate1",
  585. "displayId": "src_branch",
  586. "latestCommit": "12345671234567",
  587. "repository": {
  588. "slug": "repo",
  589. "id": 11444,
  590. "name": "FOO",
  591. "scmId": "git",
  592. "state": "AVAILABLE",
  593. "statusMessage": "Available",
  594. "forkable": true,
  595. "project": {
  596. "key": "fork",
  597. "id": 112,
  598. "name": "foo",
  599. "type": "PERSONAL",
  600. "owner": {
  601. "name": "foo",
  602. "emailAddress": "foo@bar",
  603. "id": 1363,
  604. "displayName": "foo",
  605. "active": true,
  606. "slug": "foo",
  607. "type": "NORMAL",
  608. "links": {
  609. "self": [
  610. {
  611. "href": "https://bitbucket/users/bar"
  612. }
  613. ]
  614. }
  615. },
  616. "links": {
  617. "self": [
  618. {
  619. "href": "https://bitbucket/users/bar"
  620. }
  621. ]
  622. }
  623. },
  624. "public": false,
  625. "links": {
  626. "clone": [
  627. {
  628. "href": "https://bitbucket/scm/foo/bar.git",
  629. "name": "http"
  630. },
  631. {
  632. "href": "ssh://git@bitbucket:7999/foo/bar.git",
  633. "name": "ssh"
  634. }
  635. ],
  636. "self": [
  637. {
  638. "href": "https://bitbucket/users/foo/repos/bar/browse"
  639. }
  640. ]
  641. }
  642. }
  643. },
  644. "toRef": {
  645. "id": "refs/heads/dest_branch",
  646. "displayId": "dest_branch",
  647. "latestCommit": "654321654321",
  648. "repository": {
  649. "slug": "repo",
  650. "id": 11444,
  651. "name": "bar",
  652. "scmId": "git",
  653. "state": "AVAILABLE",
  654. "statusMessage": "Available",
  655. "forkable": true,
  656. "project": {
  657. "key": "my",
  658. "id": 112,
  659. "name": "my",
  660. "type": "PERSONAL",
  661. "owner": {
  662. "name": "foo",
  663. "emailAddress": "foo@bar",
  664. "id": 1363,
  665. "displayName": "foo",
  666. "active": true,
  667. "slug": "foo",
  668. "type": "NORMAL",
  669. "links": {
  670. "self": [
  671. {
  672. "href": "https://bitbucket/users/bar"
  673. }
  674. ]
  675. }
  676. },
  677. "links": {
  678. "self": [
  679. {
  680. "href": "https://bitbucket/users/bar"
  681. }
  682. ]
  683. }
  684. },
  685. "public": false,
  686. "links": {
  687. "clone": [
  688. {
  689. "href": "https://bitbucket/scm/bar/foo.git",
  690. "name": "http"
  691. },
  692. {
  693. "href": "ssh://git@bitbucket:7999/bar/foo.git",
  694. "name": "ssh"
  695. }
  696. ],
  697. "self": [
  698. {
  699. "href": "https://bitbucket/users/steven.guiheux/repos/ascoderepo/browse"
  700. }
  701. ]
  702. }
  703. }
  704. },
  705. "locked": false,
  706. "author": {
  707. "user": {
  708. "name": "cds",
  709. "emailAddress": "foo@bar.fr",
  710. "id": 7898,
  711. "displayName": "cds",
  712. "active": true,
  713. "slug": "cds",
  714. "type": "NORMAL",
  715. "links": {
  716. "self": [
  717. {
  718. "href": "http//foo/bar"
  719. }
  720. ]
  721. }
  722. },
  723. "role": "AUTHOR",
  724. "approved": false,
  725. "status": "UNAPPROVED"
  726. },
  727. "reviewers": [],
  728. "participants": [],
  729. "links": {
  730. "self": [
  731. {
  732. "href": "fff"
  733. }
  734. ]
  735. }
  736. },
  737. "addedReviewers": [
  738. {
  739. "name": "francois.samin",
  740. "emailAddress": "francois.samin@foo.bar",
  741. "id": 2427,
  742. "displayName": "François Samin",
  743. "active": true,
  744. "slug": "francois.samin",
  745. "type": "NORMAL"
  746. }
  747. ],
  748. "removedReviewers": []
  749. }`
  750. var bitbucketPrReviewerApproved = `
  751. {
  752. "eventKey": "pr:reviewer:approved",
  753. "date": "2019-10-15T09:33:38+0200",
  754. "actor": {
  755. "name": "john.doe",
  756. "emailAddress": "john.doe@targate.fr",
  757. "id": 1363,
  758. "displayName": "john doe",
  759. "active": true,
  760. "slug": "foo",
  761. "type": "NORMAL",
  762. "links": {
  763. "self": [
  764. {
  765. "href": "https://bitbucket/users/bar"
  766. }
  767. ]
  768. }
  769. },
  770. "pullRequest": {
  771. "id": 666,
  772. "version": 0,
  773. "title": "My First PR",
  774. "state": "OPEN",
  775. "open": true,
  776. "closed": false,
  777. "createdDate": 1569939813210,
  778. "updatedDate": 1569939813210,
  779. "fromRef": {
  780. "id": "refs/heads/workflowUpdate1",
  781. "displayId": "src_branch",
  782. "latestCommit": "12345671234567",
  783. "repository": {
  784. "slug": "repo",
  785. "id": 11444,
  786. "name": "FOO",
  787. "scmId": "git",
  788. "state": "AVAILABLE",
  789. "statusMessage": "Available",
  790. "forkable": true,
  791. "project": {
  792. "key": "fork",
  793. "id": 112,
  794. "name": "foo",
  795. "type": "PERSONAL",
  796. "owner": {
  797. "name": "foo",
  798. "emailAddress": "foo@bar",
  799. "id": 1363,
  800. "displayName": "foo",
  801. "active": true,
  802. "slug": "foo",
  803. "type": "NORMAL",
  804. "links": {
  805. "self": [
  806. {
  807. "href": "https://bitbucket/users/bar"
  808. }
  809. ]
  810. }
  811. },
  812. "links": {
  813. "self": [
  814. {
  815. "href": "https://bitbucket/users/bar"
  816. }
  817. ]
  818. }
  819. },
  820. "public": false,
  821. "links": {
  822. "clone": [
  823. {
  824. "href": "https://bitbucket/scm/foo/bar.git",
  825. "name": "http"
  826. },
  827. {
  828. "href": "ssh://git@bitbucket:7999/foo/bar.git",
  829. "name": "ssh"
  830. }
  831. ],
  832. "self": [
  833. {
  834. "href": "https://bitbucket/users/foo/repos/bar/browse"
  835. }
  836. ]
  837. }
  838. }
  839. },
  840. "toRef": {
  841. "id": "refs/heads/dest_branch",
  842. "displayId": "dest_branch",
  843. "latestCommit": "654321654321",
  844. "repository": {
  845. "slug": "repo",
  846. "id": 11444,
  847. "name": "bar",
  848. "scmId": "git",
  849. "state": "AVAILABLE",
  850. "statusMessage": "Available",
  851. "forkable": true,
  852. "project": {
  853. "key": "my",
  854. "id": 112,
  855. "name": "my",
  856. "type": "PERSONAL",
  857. "owner": {
  858. "name": "foo",
  859. "emailAddress": "foo@bar",
  860. "id": 1363,
  861. "displayName": "foo",
  862. "active": true,
  863. "slug": "foo",
  864. "type": "NORMAL",
  865. "links": {
  866. "self": [
  867. {
  868. "href": "https://bitbucket/users/bar"
  869. }
  870. ]
  871. }
  872. },
  873. "links": {
  874. "self": [
  875. {
  876. "href": "https://bitbucket/users/bar"
  877. }
  878. ]
  879. }
  880. },
  881. "public": false,
  882. "links": {
  883. "clone": [
  884. {
  885. "href": "https://bitbucket/scm/bar/foo.git",
  886. "name": "http"
  887. },
  888. {
  889. "href": "ssh://git@bitbucket:7999/bar/foo.git",
  890. "name": "ssh"
  891. }
  892. ],
  893. "self": [
  894. {
  895. "href": "https://bitbucket/users/steven.guiheux/repos/ascoderepo/browse"
  896. }
  897. ]
  898. }
  899. }
  900. },
  901. "locked": false,
  902. "author": {
  903. "user": {
  904. "name": "cds",
  905. "emailAddress": "foo@bar.fr",
  906. "id": 7898,
  907. "displayName": "cds",
  908. "active": true,
  909. "slug": "cds",
  910. "type": "NORMAL",
  911. "links": {
  912. "self": [
  913. {
  914. "href": "http//foo/bar"
  915. }
  916. ]
  917. }
  918. },
  919. "role": "AUTHOR",
  920. "approved": false,
  921. "status": "UNAPPROVED"
  922. },
  923. "reviewers": [],
  924. "participants": [],
  925. "links": {
  926. "self": [
  927. {
  928. "href": "fff"
  929. }
  930. ]
  931. }
  932. },
  933. "participant": {
  934. "user": {
  935. "name": "francois.samin",
  936. "emailAddress": "francois.samin@foo",
  937. "id": 2427,
  938. "displayName": "François Samin",
  939. "active": true,
  940. "slug": "francois.samin",
  941. "type": "NORMAL"
  942. },
  943. "lastReviewedCommit": "80f3f7e9b9da3cb3d7f11145709323d8a65d2922",
  944. "role": "REVIEWER",
  945. "approved": false,
  946. "status": "APPROVED"
  947. },
  948. "previousStatus": "UNAPPROVED"
  949. }`
  950. var bitbucketPrReviewerUnapproved = `
  951. {
  952. "eventKey": "pr:reviewer:unapproved",
  953. "date": "2019-10-15T09:33:38+0200",
  954. "actor": {
  955. "name": "john.doe",
  956. "emailAddress": "john.doe@targate.fr",
  957. "id": 1363,
  958. "displayName": "john doe",
  959. "active": true,
  960. "slug": "foo",
  961. "type": "NORMAL",
  962. "links": {
  963. "self": [
  964. {
  965. "href": "https://bitbucket/users/bar"
  966. }
  967. ]
  968. }
  969. },
  970. "pullRequest": {
  971. "id": 666,
  972. "version": 0,
  973. "title": "My First PR",
  974. "state": "OPEN",
  975. "open": true,
  976. "closed": false,
  977. "createdDate": 1569939813210,
  978. "updatedDate": 1569939813210,
  979. "fromRef": {
  980. "id": "refs/heads/workflowUpdate1",
  981. "displayId": "src_branch",
  982. "latestCommit": "12345671234567",
  983. "repository": {
  984. "slug": "repo",
  985. "id": 11444,
  986. "name": "FOO",
  987. "scmId": "git",
  988. "state": "AVAILABLE",
  989. "statusMessage": "Available",
  990. "forkable": true,
  991. "project": {
  992. "key": "fork",
  993. "id": 112,
  994. "name": "foo",
  995. "type": "PERSONAL",
  996. "owner": {
  997. "name": "foo",
  998. "emailAddress": "foo@bar",
  999. "id": 1363,
  1000. "displayName": "foo",
  1001. "active": true,
  1002. "slug": "foo",
  1003. "type": "NORMAL",
  1004. "links": {
  1005. "self": [
  1006. {
  1007. "href": "https://bitbucket/users/bar"
  1008. }
  1009. ]
  1010. }
  1011. },
  1012. "links": {
  1013. "self": [
  1014. {
  1015. "href": "https://bitbucket/users/bar"
  1016. }
  1017. ]
  1018. }
  1019. },
  1020. "public": false,
  1021. "links": {
  1022. "clone": [
  1023. {
  1024. "href": "https://bitbucket/scm/foo/bar.git",
  1025. "name": "http"
  1026. },
  1027. {
  1028. "href": "ssh://git@bitbucket:7999/foo/bar.git",
  1029. "name": "ssh"
  1030. }
  1031. ],
  1032. "self": [
  1033. {
  1034. "href": "https://bitbucket/users/foo/repos/bar/browse"
  1035. }
  1036. ]
  1037. }
  1038. }
  1039. },
  1040. "toRef": {
  1041. "id": "refs/heads/dest_branch",
  1042. "displayId": "dest_branch",
  1043. "latestCommit": "654321654321",
  1044. "repository": {
  1045. "slug": "repo",
  1046. "id": 11444,
  1047. "name": "bar",
  1048. "scmId": "git",
  1049. "state": "AVAILABLE",
  1050. "statusMessage": "Available",
  1051. "forkable": true,
  1052. "project": {
  1053. "key": "my",
  1054. "id": 112,
  1055. "name": "my",
  1056. "type": "PERSONAL",
  1057. "owner": {
  1058. "name": "foo",
  1059. "emailAddress": "foo@bar",
  1060. "id": 1363,
  1061. "displayName": "foo",
  1062. "active": true,
  1063. "slug": "foo",
  1064. "type": "NORMAL",
  1065. "links": {
  1066. "self": [
  1067. {
  1068. "href": "https://bitbucket/users/bar"
  1069. }
  1070. ]
  1071. }
  1072. },
  1073. "links": {
  1074. "self": [
  1075. {
  1076. "href": "https://bitbucket/users/bar"
  1077. }
  1078. ]
  1079. }
  1080. },
  1081. "public": false,
  1082. "links": {
  1083. "clone": [
  1084. {
  1085. "href": "https://bitbucket/scm/bar/foo.git",
  1086. "name": "http"
  1087. },
  1088. {
  1089. "href": "ssh://git@bitbucket:7999/bar/foo.git",
  1090. "name": "ssh"
  1091. }
  1092. ],
  1093. "self": [
  1094. {
  1095. "href": "https://bitbucket/users/steven.guiheux/repos/ascoderepo/browse"
  1096. }
  1097. ]
  1098. }
  1099. }
  1100. },
  1101. "locked": false,
  1102. "author": {
  1103. "user": {
  1104. "name": "cds",
  1105. "emailAddress": "foo@bar.fr",
  1106. "id": 7898,
  1107. "displayName": "cds",
  1108. "active": true,
  1109. "slug": "cds",
  1110. "type": "NORMAL",
  1111. "links": {
  1112. "self": [
  1113. {
  1114. "href": "http//foo/bar"
  1115. }
  1116. ]
  1117. }
  1118. },
  1119. "role": "AUTHOR",
  1120. "approved": false,
  1121. "status": "UNAPPROVED"
  1122. },
  1123. "reviewers": [],
  1124. "participants": [],
  1125. "links": {
  1126. "self": [
  1127. {
  1128. "href": "fff"
  1129. }
  1130. ]
  1131. }
  1132. },
  1133. "participant": {
  1134. "user": {
  1135. "name": "francois.samin",
  1136. "emailAddress": "francois.samin@foo",
  1137. "id": 2427,
  1138. "displayName": "François Samin",
  1139. "active": true,
  1140. "slug": "francois.samin",
  1141. "type": "NORMAL"
  1142. },
  1143. "lastReviewedCommit": "80f3f7e9b9da3cb3d7f11145709323d8a65d2922",
  1144. "role": "REVIEWER",
  1145. "approved": false,
  1146. "status": "UNAPPROVED"
  1147. },
  1148. "previousStatus": "APPROVED"
  1149. }`
  1150. var bitbucketPrReviewerNeedsWorks = `
  1151. {
  1152. "eventKey": "pr:reviewer:needs_work",
  1153. "date": "2019-10-15T09:33:38+0200",
  1154. "actor": {
  1155. "name": "john.doe",
  1156. "emailAddress": "john.doe@targate.fr",
  1157. "id": 1363,
  1158. "displayName": "john doe",
  1159. "active": true,
  1160. "slug": "foo",
  1161. "type": "NORMAL",
  1162. "links": {
  1163. "self": [
  1164. {
  1165. "href": "https://bitbucket/users/bar"
  1166. }
  1167. ]
  1168. }
  1169. },
  1170. "pullRequest": {
  1171. "id": 666,
  1172. "version": 0,
  1173. "title": "My First PR",
  1174. "state": "OPEN",
  1175. "open": true,
  1176. "closed": false,
  1177. "createdDate": 1569939813210,
  1178. "updatedDate": 1569939813210,
  1179. "fromRef": {
  1180. "id": "refs/heads/workflowUpdate1",
  1181. "displayId": "src_branch",
  1182. "latestCommit": "12345671234567",
  1183. "repository": {
  1184. "slug": "repo",
  1185. "id": 11444,
  1186. "name": "FOO",
  1187. "scmId": "git",
  1188. "state": "AVAILABLE",
  1189. "statusMessage": "Available",
  1190. "forkable": true,
  1191. "project": {
  1192. "key": "fork",
  1193. "id": 112,
  1194. "name": "foo",
  1195. "type": "PERSONAL",
  1196. "owner": {
  1197. "name": "foo",
  1198. "emailAddress": "foo@bar",
  1199. "id": 1363,
  1200. "displayName": "foo",
  1201. "active": true,
  1202. "slug": "foo",
  1203. "type": "NORMAL",
  1204. "links": {
  1205. "self": [
  1206. {
  1207. "href": "https://bitbucket/users/bar"
  1208. }
  1209. ]
  1210. }
  1211. },
  1212. "links": {
  1213. "self": [
  1214. {
  1215. "href": "https://bitbucket/users/bar"
  1216. }
  1217. ]
  1218. }
  1219. },
  1220. "public": false,
  1221. "links": {
  1222. "clone": [
  1223. {
  1224. "href": "https://bitbucket/scm/foo/bar.git",
  1225. "name": "http"
  1226. },
  1227. {
  1228. "href": "ssh://git@bitbucket:7999/foo/bar.git",
  1229. "name": "ssh"
  1230. }
  1231. ],
  1232. "self": [
  1233. {
  1234. "href": "https://bitbucket/users/foo/repos/bar/browse"
  1235. }
  1236. ]
  1237. }
  1238. }
  1239. },
  1240. "toRef": {
  1241. "id": "refs/heads/dest_branch",
  1242. "displayId": "dest_branch",
  1243. "latestCommit": "654321654321",
  1244. "repository": {
  1245. "slug": "repo",
  1246. "id": 11444,
  1247. "name": "bar",
  1248. "scmId": "git",
  1249. "state": "AVAILABLE",
  1250. "statusMessage": "Available",
  1251. "forkable": true,
  1252. "project": {
  1253. "key": "my",
  1254. "id": 112,
  1255. "name": "my",
  1256. "type": "PERSONAL",
  1257. "owner": {
  1258. "name": "foo",
  1259. "emailAddress": "foo@bar",
  1260. "id": 1363,
  1261. "displayName": "foo",
  1262. "active": true,
  1263. "slug": "foo",
  1264. "type": "NORMAL",
  1265. "links": {
  1266. "self": [
  1267. {
  1268. "href": "https://bitbucket/users/bar"
  1269. }
  1270. ]
  1271. }
  1272. },
  1273. "links": {
  1274. "self": [
  1275. {
  1276. "href": "https://bitbucket/users/bar"
  1277. }
  1278. ]
  1279. }
  1280. },
  1281. "public": false,
  1282. "links": {
  1283. "clone": [
  1284. {
  1285. "href": "https://bitbucket/scm/bar/foo.git",
  1286. "name": "http"
  1287. },
  1288. {
  1289. "href": "ssh://git@bitbucket:7999/bar/foo.git",
  1290. "name": "ssh"
  1291. }
  1292. ],
  1293. "self": [
  1294. {
  1295. "href": "https://bitbucket/users/steven.guiheux/repos/ascoderepo/browse"
  1296. }
  1297. ]
  1298. }
  1299. }
  1300. },
  1301. "locked": false,
  1302. "author": {
  1303. "user": {
  1304. "name": "cds",
  1305. "emailAddress": "foo@bar.fr",
  1306. "id": 7898,
  1307. "displayName": "cds",
  1308. "active": true,
  1309. "slug": "cds",
  1310. "type": "NORMAL",
  1311. "links": {
  1312. "self": [
  1313. {
  1314. "href": "http//foo/bar"
  1315. }
  1316. ]
  1317. }
  1318. },
  1319. "role": "AUTHOR",
  1320. "approved": false,
  1321. "status": "UNAPPROVED"
  1322. },
  1323. "reviewers": [],
  1324. "participants": [],
  1325. "links": {
  1326. "self": [
  1327. {
  1328. "href": "fff"
  1329. }
  1330. ]
  1331. }
  1332. },
  1333. "participant": {
  1334. "user": {
  1335. "name": "francois.samin",
  1336. "emailAddress": "francois.samin@foo",
  1337. "id": 2427,
  1338. "displayName": "François Samin",
  1339. "active": true,
  1340. "slug": "francois.samin",
  1341. "type": "NORMAL"
  1342. },
  1343. "lastReviewedCommit": "80f3f7e9b9da3cb3d7f11145709323d8a65d2922",
  1344. "role": "REVIEWER",
  1345. "approved": false,
  1346. "status": "NEEDS_WORK"
  1347. },
  1348. "previousStatus": "UNAPPROVED"
  1349. }`
  1350. var bitbucketPrCommentAdded = `
  1351. {
  1352. "eventKey": "pr:comment:added",
  1353. "date": "2019-10-15T09:33:38+0200",
  1354. "actor": {
  1355. "name": "john.doe",
  1356. "emailAddress": "john.doe@targate.fr",
  1357. "id": 1363,
  1358. "displayName": "john doe",
  1359. "active": true,
  1360. "slug": "foo",
  1361. "type": "NORMAL",
  1362. "links": {
  1363. "self": [
  1364. {
  1365. "href": "https://bitbucket/users/bar"
  1366. }
  1367. ]
  1368. }
  1369. },
  1370. "pullRequest": {
  1371. "id": 666,
  1372. "version": 0,
  1373. "title": "My First PR",
  1374. "state": "OPEN",
  1375. "open": true,
  1376. "closed": false,
  1377. "createdDate": 1569939813210,
  1378. "updatedDate": 1569939813210,
  1379. "fromRef": {
  1380. "id": "refs/heads/workflowUpdate1",
  1381. "displayId": "src_branch",
  1382. "latestCommit": "12345671234567",
  1383. "repository": {
  1384. "slug": "repo",
  1385. "id": 11444,
  1386. "name": "FOO",
  1387. "scmId": "git",
  1388. "state": "AVAILABLE",
  1389. "statusMessage": "Available",
  1390. "forkable": true,
  1391. "project": {
  1392. "key": "fork",
  1393. "id": 112,
  1394. "name": "foo",
  1395. "type": "PE…