model_test.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package model
  2. import (
  3. "encoding/json"
  4. "testing"
  5. )
  6. func TestGitlab(t *testing.T) {
  7. var (
  8. jsonStr = `{
  9. "object_kind": "merge_request",
  10. "user": {
  11. "name": "Administrator",
  12. "username": "root",
  13. "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
  14. },
  15. "object_attributes": {
  16. "id": 99,
  17. "target_branch": "master",
  18. "source_branch": "ms-viewport",
  19. "source_project_id": 14,
  20. "author_id": 51,
  21. "assignee_id": 6,
  22. "title": "MS-Viewport",
  23. "created_at": "2013-12-03T17:23:34Z",
  24. "updated_at": "2013-12-03T17:23:34Z",
  25. "st_commits": null,
  26. "st_diffs": null,
  27. "milestone_id": null,
  28. "state": "opened",
  29. "merge_status": "unchecked",
  30. "target_project_id": 14,
  31. "iid": 1,
  32. "description": "",
  33. "source":{
  34. "name":"Awesome Project",
  35. "description":"Aut reprehenderit ut est.",
  36. "web_url":"http://example.com/awesome_space/awesome_project",
  37. "avatar_url":null,
  38. "git_ssh_url":"git@example.com:awesome_space/awesome_project.git",
  39. "git_http_url":"http://example.com/awesome_space/awesome_project.git",
  40. "namespace":"Awesome Space",
  41. "visibility_level":20,
  42. "path_with_namespace":"awesome_space/awesome_project",
  43. "default_branch":"master",
  44. "homepage":"http://example.com/awesome_space/awesome_project",
  45. "url":"http://example.com/awesome_space/awesome_project.git",
  46. "ssh_url":"git@example.com:awesome_space/awesome_project.git",
  47. "http_url":"http://example.com/awesome_space/awesome_project.git"
  48. },
  49. "target": {
  50. "name":"Awesome Project",
  51. "description":"Aut reprehenderit ut est.",
  52. "web_url":"http://example.com/awesome_space/awesome_project",
  53. "avatar_url":null,
  54. "git_ssh_url":"git@example.com:awesome_space/awesome_project.git",
  55. "git_http_url":"http://example.com/awesome_space/awesome_project.git",
  56. "namespace":"Awesome Space",
  57. "visibility_level":20,
  58. "path_with_namespace":"awesome_space/awesome_project",
  59. "default_branch":"master",
  60. "homepage":"http://example.com/awesome_space/awesome_project",
  61. "url":"http://example.com/awesome_space/awesome_project.git",
  62. "ssh_url":"git@example.com:awesome_space/awesome_project.git",
  63. "http_url":"http://example.com/awesome_space/awesome_project.git"
  64. },
  65. "last_commit": {
  66. "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  67. "message": "fixed readme",
  68. "timestamp": "2012-01-03T23:36:29+02:00",
  69. "url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  70. "author": {
  71. "name": "GitLab dev user",
  72. "email": "gitlabdev@dv6700.(none)"
  73. }
  74. },
  75. "work_in_progress": false,
  76. "url": "http://example.com/diaspora/merge_requests/1",
  77. "action": "open",
  78. "assignee": {
  79. "name": "User1",
  80. "username": "user1",
  81. "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
  82. }
  83. }
  84. }
  85. `
  86. mrHook = &HookMR{}
  87. err error
  88. )
  89. err = json.Unmarshal([]byte(jsonStr), mrHook)
  90. if err != nil {
  91. t.Fatal(err)
  92. }
  93. t.Log(mrHook)
  94. t.Log(mrHook.User)
  95. t.Log(mrHook.ObjectAttributes)
  96. var (
  97. commentJSONStr = `{
  98. "object_kind": "note",
  99. "user": {
  100. "name": "Administrator",
  101. "username": "root",
  102. "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
  103. },
  104. "project_id": 5,
  105. "project":{
  106. "name":"Gitlab Test",
  107. "description":"Aut reprehenderit ut est.",
  108. "web_url":"http://example.com/gitlab-org/gitlab-test",
  109. "avatar_url":null,
  110. "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  111. "git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
  112. "namespace":"Gitlab Org",
  113. "visibility_level":10,
  114. "path_with_namespace":"gitlab-org/gitlab-test",
  115. "default_branch":"master",
  116. "homepage":"http://example.com/gitlab-org/gitlab-test",
  117. "url":"http://example.com/gitlab-org/gitlab-test.git",
  118. "ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  119. "http_url":"http://example.com/gitlab-org/gitlab-test.git"
  120. },
  121. "repository":{
  122. "name": "Gitlab Test",
  123. "url": "http://localhost/gitlab-org/gitlab-test.git",
  124. "description": "Aut reprehenderit ut est.",
  125. "homepage": "http://example.com/gitlab-org/gitlab-test"
  126. },
  127. "object_attributes": {
  128. "id": 1244,
  129. "note": "This MR needs work.",
  130. "noteable_type": "MergeRequest",
  131. "author_id": 1,
  132. "created_at": "2015-05-17 18:21:36 UTC",
  133. "updated_at": "2015-05-17 18:21:36 UTC",
  134. "project_id": 5,
  135. "attachment": null,
  136. "line_code": null,
  137. "commit_id": "",
  138. "noteable_id": 7,
  139. "system": false,
  140. "st_diff": null,
  141. "url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244"
  142. },
  143. "merge_request": {
  144. "id": 7,
  145. "target_branch": "markdown",
  146. "source_branch": "master",
  147. "source_project_id": 5,
  148. "author_id": 8,
  149. "assignee_id": 28,
  150. "title": "Tempora et eos debitis quae laborum et.",
  151. "created_at": "2015-03-01 20:12:53 UTC",
  152. "updated_at": "2015-03-21 18:27:27 UTC",
  153. "milestone_id": 11,
  154. "state": "opened",
  155. "merge_status": "cannot_be_merged",
  156. "target_project_id": 5,
  157. "iid": 1,
  158. "description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.",
  159. "position": 0,
  160. "source":{
  161. "name":"Gitlab Test",
  162. "description":"Aut reprehenderit ut est.",
  163. "web_url":"http://example.com/gitlab-org/gitlab-test",
  164. "avatar_url":null,
  165. "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  166. "git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
  167. "namespace":"Gitlab Org",
  168. "visibility_level":10,
  169. "path_with_namespace":"gitlab-org/gitlab-test",
  170. "default_branch":"master",
  171. "homepage":"http://example.com/gitlab-org/gitlab-test",
  172. "url":"http://example.com/gitlab-org/gitlab-test.git",
  173. "ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  174. "http_url":"http://example.com/gitlab-org/gitlab-test.git"
  175. },
  176. "target": {
  177. "name":"Gitlab Test",
  178. "description":"Aut reprehenderit ut est.",
  179. "web_url":"http://example.com/gitlab-org/gitlab-test",
  180. "avatar_url":null,
  181. "git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  182. "git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
  183. "namespace":"Gitlab Org",
  184. "visibility_level":10,
  185. "path_with_namespace":"gitlab-org/gitlab-test",
  186. "default_branch":"master",
  187. "homepage":"http://example.com/gitlab-org/gitlab-test",
  188. "url":"http://example.com/gitlab-org/gitlab-test.git",
  189. "ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
  190. "http_url":"http://example.com/gitlab-org/gitlab-test.git"
  191. },
  192. "last_commit": {
  193. "id": "562e173be03b8ff2efb05345d12df18815438a4b",
  194. "message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
  195. "timestamp": "2015-04-08T21:00:25-07:00",
  196. "url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
  197. "author": {
  198. "name": "John Smith",
  199. "email": "john@example.com"
  200. }
  201. },
  202. "work_in_progress": false,
  203. "assignee": {
  204. "name": "User1",
  205. "username": "user1",
  206. "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
  207. }
  208. }
  209. }
  210. `
  211. hookComment = &HookComment{}
  212. )
  213. err = json.Unmarshal([]byte(commentJSONStr), hookComment)
  214. if err != nil {
  215. t.Fatal(err)
  216. }
  217. t.Log(hookComment)
  218. t.Log(hookComment.User)
  219. t.Log(hookComment.Project)
  220. t.Log(hookComment.Repository)
  221. t.Log(hookComment.ObjectAttributes)
  222. t.Log(hookComment.MergeRequest)
  223. t.Log(hookComment.Commit)
  224. }