shipit-engine 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/magic-solid.svg +1 -0
  3. data/app/assets/javascripts/shipit/repositories_search.js.coffee +60 -0
  4. data/app/assets/javascripts/shipit/{search.js.coffee → stack_search.js.coffee} +0 -0
  5. data/app/assets/stylesheets/_pages/_repositories.scss +148 -0
  6. data/app/assets/stylesheets/_pages/_stacks.scss +19 -0
  7. data/app/assets/stylesheets/shipit.scss +1 -0
  8. data/app/controllers/shipit/api/{pull_requests_controller.rb → merge_requests_controller.rb} +8 -8
  9. data/app/controllers/shipit/api/stacks_controller.rb +14 -1
  10. data/app/controllers/shipit/deploys_controller.rb +2 -2
  11. data/app/controllers/shipit/merge_requests_controller.rb +31 -0
  12. data/app/controllers/shipit/merge_status_controller.rb +15 -15
  13. data/app/controllers/shipit/repositories_controller.rb +74 -0
  14. data/app/controllers/shipit/tasks_controller.rb +4 -4
  15. data/app/helpers/shipit/chunks_helper.rb +2 -2
  16. data/app/helpers/shipit/github_url_helper.rb +8 -0
  17. data/app/helpers/shipit/stacks_helper.rb +4 -0
  18. data/app/jobs/shipit/create_on_github_job.rb +1 -0
  19. data/app/jobs/shipit/destroy_repository_job.rb +24 -0
  20. data/app/jobs/shipit/destroy_stack_job.rb +2 -2
  21. data/app/jobs/shipit/perform_task_job.rb +4 -98
  22. data/app/jobs/shipit/process_merge_requests_job.rb +32 -0
  23. data/app/jobs/shipit/refresh_merge_request_job.rb +11 -0
  24. data/app/models/shipit/anonymous_user.rb +4 -0
  25. data/app/models/shipit/check_run.rb +2 -2
  26. data/app/models/shipit/command_line_user.rb +4 -0
  27. data/app/models/shipit/commit.rb +11 -11
  28. data/app/models/shipit/commit_checks.rb +1 -0
  29. data/app/models/shipit/deploy.rb +1 -0
  30. data/app/models/shipit/deploy_spec.rb +16 -4
  31. data/app/models/shipit/deploy_spec/file_system.rb +11 -5
  32. data/app/models/shipit/hook.rb +2 -0
  33. data/app/models/shipit/merge_request.rb +302 -0
  34. data/app/models/shipit/provisioning_handler.rb +32 -0
  35. data/app/models/shipit/provisioning_handler/base.rb +30 -0
  36. data/app/models/shipit/provisioning_handler/unregistered_provisioning_handler.rb +35 -0
  37. data/app/models/shipit/pull_request.rb +25 -264
  38. data/app/models/shipit/pull_request_assignment.rb +10 -0
  39. data/app/models/shipit/repository.rb +54 -0
  40. data/app/models/shipit/review_stack.rb +116 -0
  41. data/app/models/shipit/review_stack_provisioning_queue.rb +39 -0
  42. data/app/models/shipit/stack.rb +22 -8
  43. data/app/models/shipit/task.rb +56 -7
  44. data/app/models/shipit/task_execution_strategy/base.rb +20 -0
  45. data/app/models/shipit/task_execution_strategy/default.rb +110 -0
  46. data/app/models/shipit/user.rb +6 -1
  47. data/app/models/shipit/webhooks.rb +10 -0
  48. data/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb +74 -0
  49. data/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb +68 -0
  50. data/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb +74 -0
  51. data/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb +127 -0
  52. data/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb +106 -0
  53. data/app/models/shipit/webhooks/handlers/pull_request/opened_handler.rb +83 -0
  54. data/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb +88 -0
  55. data/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb +103 -0
  56. data/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb +107 -0
  57. data/app/serializers/shipit/deploy_serializer.rb +6 -0
  58. data/app/serializers/shipit/merge_request_serializer.rb +21 -0
  59. data/app/serializers/shipit/pull_request_serializer.rb +5 -8
  60. data/app/serializers/shipit/review_stack_serializer.rb +7 -0
  61. data/app/serializers/shipit/stack_serializer.rb +7 -6
  62. data/app/serializers/shipit/tail_task_serializer.rb +10 -2
  63. data/app/serializers/shipit/task_serializer.rb +1 -1
  64. data/app/views/shipit/merge_requests/_merge_request.html.erb +29 -0
  65. data/app/views/shipit/{pull_requests → merge_requests}/index.html.erb +2 -2
  66. data/app/views/shipit/merge_requests/merge_requests/_pull_request.html.erb +29 -0
  67. data/app/views/shipit/merge_requests/merge_requests/index.html.erb +20 -0
  68. data/app/views/shipit/merge_status/_merge_queue_button.html.erb +3 -3
  69. data/app/views/shipit/merge_status/backlogged.html.erb +1 -1
  70. data/app/views/shipit/merge_status/failure.html.erb +1 -1
  71. data/app/views/shipit/merge_status/locked.html.erb +1 -1
  72. data/app/views/shipit/merge_status/success.html.erb +2 -2
  73. data/app/views/shipit/repositories/_header.html.erb +19 -0
  74. data/app/views/shipit/repositories/index.html.erb +31 -0
  75. data/app/views/shipit/repositories/new.html.erb +23 -0
  76. data/app/views/shipit/repositories/settings.html.erb +53 -0
  77. data/app/views/shipit/repositories/show.html.erb +30 -0
  78. data/app/views/shipit/stacks/_banners.html.erb +13 -0
  79. data/app/views/shipit/stacks/_header.html.erb +5 -2
  80. data/app/views/shipit/stacks/_stack.html.erb +8 -0
  81. data/app/views/shipit/stacks/index.html.erb +2 -1
  82. data/app/views/shipit/stacks/settings.html.erb +5 -5
  83. data/app/views/shipit/stacks/show.html.erb +1 -1
  84. data/app/views/shipit/tasks/_task_output.html.erb +1 -1
  85. data/config/routes.rb +15 -5
  86. data/db/migrate/20200706145406_add_review_stacks.rb +12 -0
  87. data/db/migrate/20200804144639_rename_pull_request_to_merge_request.rb +7 -0
  88. data/db/migrate/20200804161512_rename_commits_pull_request_id_to_merge_request_id.rb +5 -0
  89. data/db/migrate/20200813134712_recreate_shipit_pull_requests.rb +22 -0
  90. data/db/migrate/20200813194056_create_pull_request_assignments.rb +8 -0
  91. data/db/migrate/20201001125502_add_provision_pr_stacks_flag_to_repositories.rb +7 -0
  92. data/db/migrate/20201008145809_add_retry_attempt_to_tasks.rb +5 -0
  93. data/db/migrate/20201008152744_add_max_retries_to_tasks.rb +5 -0
  94. data/lib/shipit.rb +11 -1
  95. data/lib/shipit/github_app.rb +1 -1
  96. data/lib/shipit/review_stack_commands.rb +8 -0
  97. data/lib/shipit/stack_commands.rb +6 -1
  98. data/lib/shipit/task_commands.rb +1 -0
  99. data/lib/shipit/version.rb +1 -1
  100. data/lib/tasks/cron.rake +11 -2
  101. data/test/controllers/api/{pull_requests_controller_test.rb → merge_requests_controller_test.rb} +12 -12
  102. data/test/controllers/api/outputs_controller_test.rb +1 -0
  103. data/test/controllers/api/rollback_controller_test.rb +1 -1
  104. data/test/controllers/api/stacks_controller_test.rb +21 -1
  105. data/test/controllers/{pull_requests_controller_test.rb → merge_requests_controller_test.rb} +6 -6
  106. data/test/controllers/repositories_controller_test.rb +71 -0
  107. data/test/controllers/stacks_controller_test.rb +9 -1
  108. data/test/controllers/tasks_controller_test.rb +14 -2
  109. data/test/controllers/webhooks_controller_test.rb +1 -1
  110. data/test/dummy/config/application.rb +6 -1
  111. data/test/dummy/config/environments/development.rb +0 -3
  112. data/test/dummy/config/environments/test.rb +0 -5
  113. data/test/dummy/db/schema.rb +52 -14
  114. data/test/dummy/db/seeds.rb +1 -1
  115. data/test/fixtures/payloads/check_suite_master.json +2 -2
  116. data/test/fixtures/payloads/invalid_pull_request.json +117 -0
  117. data/test/fixtures/payloads/provision_disabled_pull_request.json +454 -0
  118. data/test/fixtures/payloads/pull_request_assigned.json +480 -0
  119. data/test/fixtures/payloads/pull_request_closed.json +454 -0
  120. data/test/fixtures/payloads/pull_request_labeled.json +461 -0
  121. data/test/fixtures/payloads/pull_request_opened.json +454 -0
  122. data/test/fixtures/payloads/pull_request_reopened.json +454 -0
  123. data/test/fixtures/payloads/pull_request_unlabeled.json +454 -0
  124. data/test/fixtures/payloads/pull_request_with_no_repo.json +454 -0
  125. data/test/fixtures/shipit/commits.yml +15 -2
  126. data/test/fixtures/shipit/merge_requests.yml +141 -0
  127. data/test/fixtures/shipit/pull_request_assignments.yml +3 -0
  128. data/test/fixtures/shipit/pull_requests.yml +10 -131
  129. data/test/fixtures/shipit/repositories.yml +1 -0
  130. data/test/fixtures/shipit/stacks.yml +145 -0
  131. data/test/fixtures/shipit/statuses.yml +9 -0
  132. data/test/fixtures/shipit/tasks.yml +3 -0
  133. data/test/fixtures/shipit/users.yml +7 -0
  134. data/test/helpers/payloads_helper.rb +4 -0
  135. data/test/jobs/chunk_rollup_job_test.rb +15 -1
  136. data/test/jobs/destroy_repository_job_test.rb +27 -0
  137. data/test/jobs/perform_task_job_test.rb +8 -8
  138. data/test/jobs/{merge_pull_requests_job_test.rb → process_merge_requests_job_test.rb} +18 -18
  139. data/test/lib/shipit/deploy_commands_test.rb +16 -0
  140. data/test/lib/shipit/task_commands_test.rb +17 -0
  141. data/test/models/commits_test.rb +22 -13
  142. data/test/models/deploy_spec_test.rb +57 -24
  143. data/test/models/deploys_test.rb +148 -14
  144. data/test/models/{pull_request_test.rb → merge_request_test.rb} +30 -30
  145. data/test/models/pull_request_assignment_test.rb +16 -0
  146. data/test/models/shipit/provisioning_handler/base_test.rb +33 -0
  147. data/test/models/shipit/provisioning_handler/unregistered_provisioning_handler_test.rb +49 -0
  148. data/test/models/shipit/provisioning_handler_test.rb +64 -0
  149. data/test/models/shipit/pull_request_test.rb +52 -0
  150. data/test/models/shipit/repository_test.rb +5 -1
  151. data/test/models/shipit/review_stack_provision_status_test.rb +77 -0
  152. data/test/models/shipit/review_stack_provisioning_queue_test.rb +63 -0
  153. data/test/models/shipit/review_stack_test.rb +59 -0
  154. data/test/models/{stacks_test.rb → shipit/stacks_test.rb} +10 -4
  155. data/test/models/shipit/webhooks/handlers/pull_request/assigned_handler_test.rb +45 -0
  156. data/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb +192 -0
  157. data/test/models/shipit/webhooks/handlers/pull_request/edited_handler_test.rb +47 -0
  158. data/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb +209 -0
  159. data/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb +332 -0
  160. data/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb +238 -0
  161. data/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb +282 -0
  162. data/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb +83 -0
  163. data/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb +324 -0
  164. data/test/models/shipit/{wehbooks → webhooks}/handlers_test.rb +0 -0
  165. data/test/models/tasks_test.rb +44 -3
  166. data/test/serializers/shipit/pull_request_serializer_test.rb +29 -0
  167. data/test/unit/command_test.rb +3 -3
  168. data/test/unit/github_url_helper_test.rb +5 -0
  169. data/test/unit/shipit_task_execution_strategy_test.rb +47 -0
  170. metadata +260 -154
  171. data/app/controllers/shipit/pull_requests_controller.rb +0 -31
  172. data/app/jobs/shipit/merge_pull_requests_job.rb +0 -32
  173. data/app/jobs/shipit/refresh_pull_request_job.rb +0 -11
  174. data/app/views/shipit/pull_requests/_pull_request.html.erb +0 -29
  175. data/test/fixtures/shipit/output_chunks.yml +0 -47
  176. data/test/models/output_chunk_test.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98113cef0ad013fa29cb11fea22f09547c191310a601eb788a53fdc5fb3c7e40
4
- data.tar.gz: 39c68de0e6356e1daab40942a817af86258ea8219726c1e4276a42bba5d79315
3
+ metadata.gz: 47bb069ae71eaf994a57ee8dbe3a409adf62ede12fbb010b18ffb9056cee9e0e
4
+ data.tar.gz: 2e8399c7f72ed1308de6b0be4715579bb6732f3759b22eb38e2e750bb84439de
5
5
  SHA512:
6
- metadata.gz: 29504e17c71d378485e8610edea95e25e215f5c391478244e609a95a847e3022b508bda95713db97e1f1de22f67c8eed310a562f82cf737e1425803e958341ce
7
- data.tar.gz: a7ea41b8ddcf21803a1279cd74d53231c9e030165c06b2ff835f31db55b0cf2240ca802626fba50abaec6b0e5c09e1439900de22c9d3b7719f53b6e2fe524da8
6
+ metadata.gz: a0a8986aae58f932aca14da3213df881dabfa1017aa844bfe3f5a61afcabc2f09032eafe4342d8acdb7d4fc50cfe4ec9ad1f05dba9209757ef95cc6aa8c8a142
7
+ data.tar.gz: 0722dfd987d98c176b4625e23921c5576b1a40e85ed6e4d18208c4a4eff4b8c45ba314055dee3255feb576748431be638e6eb97fda6935c6953b70bfe6f14048
@@ -0,0 +1 @@
1
+ <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="magic" class="svg-inline--fa fa-magic fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M224 96l16-32 32-16-32-16-16-32-16 32-32 16 32 16 16 32zM80 160l26.66-53.33L160 80l-53.34-26.67L80 0 53.34 53.33 0 80l53.34 26.67L80 160zm352 128l-26.66 53.33L352 368l53.34 26.67L432 448l26.66-53.33L512 368l-53.34-26.67L432 288zm70.62-193.77L417.77 9.38C411.53 3.12 403.34 0 395.15 0c-8.19 0-16.38 3.12-22.63 9.38L9.38 372.52c-12.5 12.5-12.5 32.76 0 45.25l84.85 84.85c6.25 6.25 14.44 9.37 22.62 9.37 8.19 0 16.38-3.12 22.63-9.37l363.14-363.15c12.5-12.48 12.5-32.75 0-45.24zM359.45 203.46l-50.91-50.91 86.6-86.6 50.91 50.91-86.6 86.6z"></path></svg>
@@ -0,0 +1,60 @@
1
+ KEY =
2
+ UP: 38
3
+ DOWN: 40
4
+ ENTER: 13
5
+
6
+ class RepositorySearch
7
+
8
+ constructor: (root) ->
9
+ @$root = $(root)
10
+ @$root.on('keyup', '.repository-search', @onKeyUp)
11
+ @$root.on('click', '.show-all-repositories', (event) =>
12
+ @$root.find('.not-matching').removeClass('not-matching')
13
+ event.preventDefault()
14
+ )
15
+
16
+ onKeyUp: (event) =>
17
+ @$items = @$root.find('[data-search]')
18
+ switch event.keyCode
19
+ when KEY.ENTER
20
+ event.preventDefault()
21
+ @goToSelectedRepository()
22
+ when KEY.UP
23
+ event.preventDefault()
24
+ @selectPrevious()
25
+ when KEY.DOWN
26
+ event.preventDefault()
27
+ @selectNext()
28
+ else
29
+ @filterResults($.trim($(event.target).val()).toLowerCase())
30
+
31
+ filterResults: (query) ->
32
+ if query
33
+ for item in @$items
34
+ $item = $(item)
35
+ $item.toggleClass('not-matching', query not in $item.attr('data-search').toLowerCase())
36
+ @selectFirst()
37
+ else
38
+ @$items.removeClass('not-matching')
39
+
40
+ selectFirst: ->
41
+ @$items.removeClass('selected').first(':not(.not-matching)').addClass('selected')
42
+
43
+ selectNext: ->
44
+ $next = @$items.filter('.selected').removeClass('selected').nextAll(':not(.not-matching)').first()
45
+ $next = @$items.filter(':not(.not-matching)').first() unless $next.length
46
+ $next.addClass('selected')
47
+
48
+ selectPrevious: ->
49
+ $previous = @$items.filter('.selected').removeClass('selected').prevAll(':not(.not-matching)').first()
50
+ $previous = @$items.filter(':not(.not-matching)').last() unless $previous.length
51
+ $previous.addClass('selected')
52
+
53
+ goToSelectedRepository: ->
54
+ if repository = @$items.filter('.selected').filter(':not(.not-matching)').find('.commits-path').attr('href')
55
+ window.location = repository
56
+
57
+ search = new RepositorySearch(document)
58
+
59
+ jQuery ->
60
+ $('.repository-search').focus()
@@ -0,0 +1,148 @@
1
+ .repository-search {
2
+ -webkit-appearance: none;
3
+ width: 100%;
4
+ @extend h1;
5
+ border: none;
6
+ font-family: "Helvetica Neue", sans-serif;
7
+ font-weight: 200;
8
+ background: asset-data-url('search.svg') no-repeat center right;
9
+ &::-webkit-input-placeholder {
10
+ color: #B5C0CA;
11
+ }
12
+ &:focus {
13
+ outline: none;
14
+ background-image: asset-data-url('search-active.svg');
15
+ }
16
+ }
17
+
18
+ .repository-table-header {
19
+ @include clearfix;
20
+ margin: 0; padding: 1.25rem 0 1rem;
21
+ .col {
22
+ width: 25%;
23
+ float: left;
24
+ }
25
+ li {
26
+ list-style-type: none;
27
+ font-size: .875em;
28
+ color: #BAC5D1;
29
+ }
30
+ }
31
+
32
+ .repository-lst {
33
+ list-style-type: none;
34
+ margin: 0; padding: 0; margin-bottom: 1.5rem;
35
+ .col {
36
+ width: 25%;
37
+ float: left;
38
+ text-overflow: ellipsis;
39
+ white-space: nowrap;
40
+ overflow: hidden;
41
+ padding-right: .5rem;
42
+ box-sizing: border-box;
43
+ }
44
+ .undeployed {
45
+ background-image: asset-data-url('ship.png');
46
+ background-repeat: no-repeat;
47
+ background-size: 22px 22px;
48
+ background-position: 0px center;
49
+ padding-left: 30px;
50
+ margin-left: -30px;
51
+ }
52
+ .archived {
53
+ // From FontAwesome, license @ https://fontawesome.com/license/free
54
+ background-image: asset-data-url('archive-solid.svg');
55
+ background-repeat: no-repeat;
56
+ background-size: 22px 22px;
57
+ background-position: 0px center;
58
+ padding-left: 30px;
59
+ margin-left: -30px;
60
+ }
61
+ .auto-provisioned {
62
+ // From FontAwesome, license @ https://fontawesome.com/license/free
63
+ background-image: asset-data-url('magic-solid.svg');
64
+ background-repeat: no-repeat;
65
+ background-size: 22px 22px;
66
+ background-position: 0px center;
67
+ padding-left: 30px;
68
+ margin-left: -30px;
69
+ }
70
+ }
71
+
72
+ .repository-lst:empty:before {
73
+ content: "No environment to deploy to, Shipit Squirrel is displeased";
74
+ }
75
+
76
+ .repository-lst li {
77
+ &:nth-child(even) a {
78
+ background-color: lighten(#EDF1F3, 3.5%);
79
+ }
80
+
81
+ &.selected a {
82
+ background-color: $blue;
83
+ outline: none;
84
+ span { color: #fff; }
85
+ small { color: rgba(#fff, .8); }
86
+ }
87
+
88
+ a {
89
+ padding: .35rem;
90
+ margin-left: -0.35rem; margin-right: -0.35rem;
91
+ @include clearfix;
92
+ border-radius: 4px;
93
+ display: block;
94
+ &:hover, &:focus {
95
+ background-color: $blue;
96
+ outline: none;
97
+ span { color: #fff; }
98
+ small { color: rgba(#fff, .8); }
99
+ }
100
+ }
101
+ }
102
+
103
+ .repository-search input {
104
+ margin-left: 4%;
105
+ width: 92%;
106
+ padding: 6px;
107
+ font-size: larger;
108
+ -moz-border-radius: 8px;
109
+ -webkit-border-radius: 8px;
110
+ border-radius: 8px;
111
+ outline: 0;
112
+ border: 1px #a0a0a0 solid;
113
+ }
114
+
115
+ .repository-search-header {
116
+ display: none;
117
+ }
118
+
119
+ .show-all-repositories {
120
+ display: none;
121
+ }
122
+
123
+ .filtering-enabled {
124
+ .show-all-repositories {
125
+ display: inline-block;
126
+ }
127
+
128
+ .repository-search-header {
129
+ display: block;
130
+ }
131
+ .search-item.not-matching {
132
+ display: none;
133
+ }
134
+ }
135
+
136
+ .new_repository {
137
+ input.repo {
138
+ width: 200px;
139
+ display: inline;
140
+
141
+ &:focus {
142
+ padding-right: 30px !important;
143
+ }
144
+ }
145
+ input:focus {
146
+ border-color: $blue;
147
+ }
148
+ }
@@ -58,6 +58,15 @@
58
58
  padding-left: 30px;
59
59
  margin-left: -30px;
60
60
  }
61
+ .auto-provisioned {
62
+ // From FontAwesome, license @ https://fontawesome.com/license/free
63
+ background-image: asset-data-url('magic-solid.svg');
64
+ background-repeat: no-repeat;
65
+ background-size: 22px 22px;
66
+ background-position: 0px center;
67
+ padding-left: 30px;
68
+ margin-left: -30px;
69
+ }
61
70
  }
62
71
 
63
72
  .stack-lst:empty:before {
@@ -193,6 +202,16 @@
193
202
  @include clearfix;
194
203
  }
195
204
 
205
+ .auto-provisioned {
206
+ // From FontAwesome, license @ https://fontawesome.com/license/free
207
+ background-image: asset-data-url('magic-solid.svg');
208
+ background-repeat: no-repeat;
209
+ background-size: 22px 22px;
210
+ background-position: 0px center;
211
+ padding-left: 30px;
212
+ margin-left: 5px;
213
+ }
214
+
196
215
  /* STATS */
197
216
 
198
217
  .stats {
@@ -17,4 +17,5 @@
17
17
  @import "_pages/_commits";
18
18
  @import "_pages/_settings";
19
19
  @import "_pages/_stacks";
20
+ @import "_pages/_repositories";
20
21
  @import "_pages/_deploy";
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
  module Shipit
3
3
  module Api
4
- class PullRequestsController < BaseController
4
+ class MergeRequestsController < BaseController
5
5
  require_permission :read, :stack
6
6
  require_permission :deploy, :stack, only: %i(update destroy)
7
7
 
8
8
  def index
9
- render_resources(stack.pull_requests.includes(:head).order(id: :desc))
9
+ render_resources(stack.merge_requests.includes(:head).order(id: :desc))
10
10
  end
11
11
 
12
12
  def show
13
- render_resource(stack.pull_requests.find_by!(number: params[:id]))
13
+ render_resource(stack.merge_requests.find_by!(number: params[:id]))
14
14
  end
15
15
 
16
16
  def update
17
- pull_request = PullRequest.request_merge!(stack, params[:id], current_user)
18
- if pull_request.waiting?
17
+ merge_request = MergeRequest.request_merge!(stack, params[:id], current_user)
18
+ if merge_request.waiting?
19
19
  head(:accepted)
20
- elsif pull_request.merged?
20
+ elsif merge_request.merged?
21
21
  render(status: :method_not_allowed, json: {
22
22
  message: "This pull request was already merged.",
23
23
  })
@@ -27,8 +27,8 @@ module Shipit
27
27
  end
28
28
 
29
29
  def destroy
30
- if pull_request = stack.pull_requests.where(number: params[:id]).first
31
- pull_request.cancel! if pull_request.waiting?
30
+ if merge_request = stack.merge_requests.where(number: params[:id]).first
31
+ merge_request.cancel! if merge_request.waiting?
32
32
  end
33
33
  head(:no_content)
34
34
  end
@@ -5,8 +5,21 @@ module Shipit
5
5
  require_permission :read, :stack, only: %i(index show)
6
6
  require_permission :write, :stack, only: %i(create update destroy)
7
7
 
8
+ params do
9
+ accepts :repo_owner, String
10
+ accepts :repo_name, String
11
+ end
8
12
  def index
9
- render_resources(stacks)
13
+ @stacks = stacks
14
+ if params[:repo_owner] && params[:repo_name]
15
+ full_repo_name = [repo_owner, repo_name].join('/')
16
+ @stacks = if (repository = Repository.from_github_repo_name(full_repo_name))
17
+ stacks.where(repository: repository)
18
+ else
19
+ Stack.none
20
+ end
21
+ end
22
+ render_resources(@stacks)
10
23
  end
11
24
 
12
25
  params do
@@ -17,7 +17,7 @@ module Shipit
17
17
  def show
18
18
  respond_to do |format|
19
19
  format.html
20
- format.text { render plain: @deploy.chunk_output }
20
+ format.text { render(plain: @deploy.chunk_output) }
21
21
  end
22
22
  end
23
23
 
@@ -55,7 +55,7 @@ module Shipit
55
55
  end
56
56
 
57
57
  def load_stack
58
- @stack ||= Stack.from_param!(params[:stack_id])
58
+ @stack ||= Stack.from_param!(params[:stack_id]).becomes(Stack)
59
59
  end
60
60
 
61
61
  def load_until_commit
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Shipit
3
+ class MergeRequestsController < ShipitController
4
+ def index
5
+ @merge_requests = stack.merge_requests.queued
6
+ end
7
+
8
+ def create
9
+ if pr_number = MergeRequest.extract_number(stack, params[:number_or_url])
10
+ merge_request = MergeRequest.request_merge!(stack, pr_number, current_user)
11
+ flash[:success] = "Pull request ##{merge_request.number} added to the queue."
12
+ else
13
+ flash[:warning] = "Invalid or missing pull request number."
14
+ end
15
+ redirect_to(stack_merge_requests_path)
16
+ end
17
+
18
+ def destroy
19
+ merge_request = stack.merge_requests.find(params[:id])
20
+ merge_request.cancel!
21
+ flash[:success] = 'Merge canceled'
22
+ redirect_to(stack_merge_requests_path)
23
+ end
24
+
25
+ private
26
+
27
+ def stack
28
+ @stack ||= Stack.from_param!(params[:stack_id])
29
+ end
30
+ end
31
+ end
@@ -12,7 +12,7 @@ module Shipit
12
12
 
13
13
  if stack
14
14
  return render('logged_out') unless current_user.logged_in?
15
- if stale?(last_modified: [stack.updated_at, pull_request.updated_at].max, template: false)
15
+ if stale?(last_modified: [stack.updated_at, merge_request.updated_at].max, template: false)
16
16
  render(stack_status, layout: !request.xhr?)
17
17
  end
18
18
  else
@@ -23,13 +23,13 @@ module Shipit
23
23
  end
24
24
 
25
25
  def enqueue
26
- PullRequest.request_merge!(stack, params[:number], current_user)
26
+ MergeRequest.request_merge!(stack, params[:number], current_user)
27
27
  render(stack_status, layout: !request.xhr?)
28
28
  end
29
29
 
30
30
  def dequeue
31
- if pull_request = stack.pull_requests.find_by_number(params[:number])
32
- pull_request.cancel! if pull_request.waiting?
31
+ if merge_request = stack.merge_requests.find_by_number(params[:number])
32
+ merge_request.cancel! if merge_request.waiting?
33
33
  end
34
34
  render(stack_status, layout: !request.xhr?)
35
35
  end
@@ -38,12 +38,12 @@ module Shipit
38
38
  respond_to do |format|
39
39
  format.html do
40
40
  if stack_status == 'success'
41
- render plain: 'ok'
41
+ render(plain: 'ok')
42
42
  else
43
- render plain: stack_status, status: 503
43
+ render(plain: stack_status, status: 503)
44
44
  end
45
45
  end
46
- format.json { render json: { stack_status: stack_status } }
46
+ format.json { render(json: { stack_status: stack_status }) }
47
47
  end
48
48
  end
49
49
 
@@ -82,10 +82,10 @@ module Shipit
82
82
  @referrer_parser ||= ReferrerParser.new(params[:referrer])
83
83
  end
84
84
 
85
- def pull_request
86
- return @pull_request if defined?(@pull_request)
87
- @pull_request = pull_request_number && stack.pull_requests.find_by_number(pull_request_number)
88
- @pull_request ||= UnknownPullRequest.new
85
+ def merge_request
86
+ return @merge_request if defined?(@merge_request)
87
+ @merge_request = pull_request_number && stack.merge_requests.find_by_number(pull_request_number)
88
+ @merge_request ||= UnknownMergeRequest.new
89
89
  end
90
90
 
91
91
  def pull_request_number
@@ -98,14 +98,14 @@ module Shipit
98
98
  end
99
99
 
100
100
  helper_method :pull_request_number
101
- helper_method :pull_request
101
+ helper_method :merge_request
102
102
  helper_method :queue_enabled?
103
103
  helper_method :stack
104
104
  helper_method :stack_status
105
105
 
106
106
  # FIXME: for some reason if invoked in the view, those path helpers will link to /events?...
107
- helper_method :enqueue_pull_request_path
108
- helper_method :dequeue_pull_request_path
107
+ helper_method :enqueue_merge_request_path
108
+ helper_method :dequeue_merge_request_path
109
109
 
110
110
  class ReferrerParser
111
111
  URL_PATTERN = %r{\Ahttps://github\.com/([^/]+)/([^/]+)/pull/(\d+)}
@@ -123,7 +123,7 @@ module Shipit
123
123
  end
124
124
  end
125
125
 
126
- class UnknownPullRequest
126
+ class UnknownMergeRequest
127
127
  attr_reader :updated_at
128
128
 
129
129
  def initialize