shipit-engine 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a30e953800b45a4493e91c7e8caa2ad53f3dc447
4
- data.tar.gz: 16b5dabad1863d6982dbd8736152e37e19a3a671
3
+ metadata.gz: 982c05d52c22af2e2e26f352efc805d9ef961759
4
+ data.tar.gz: 3a43a97130cc13814c6368ec89e219cb5face2c9
5
5
  SHA512:
6
- metadata.gz: cb4027d810267d4c983dd26fa0a602af2db1a5015e3371b2b02e2d8d8636d791a596517a5528df4c89b9d95cc6b638a2ee7676a14215eae60fa2cfa9b8e67d27
7
- data.tar.gz: 10ff1beb9b067253a7814300ec69b9f7ef7e3c312d3c3b2c122183d0d90a0a97e84f8f267249dc393866fc9374986ce8b0c874d8a97d040e060c64d872ced214
6
+ metadata.gz: 2579172befb2eb5054a42935b8bf4fd97bfc53098291468a881171faa708b10f538c3ddbedc2b0560dd0a597bc9f64cee2066d2045ba46d9d66d60e152c38d13
7
+ data.tar.gz: 72f2f25e93719769e1ceeffe3c952cbd460a80864151ba9a5761b813114791aadbc6888cebd48e24fb552384ce3943250d698f2ef195ed1c3f304e5bd10d206c
data/README.md CHANGED
@@ -20,7 +20,7 @@ This guide aims to help you [set up](#installation-and-setup), [use](#using-ship
20
20
 
21
21
  * [Installation](#installation)
22
22
  * [Configuring shipit.yml and secrets.yml](#configuring-ymls)
23
- * [Updating and existing installation](#updating-shipit)
23
+ * [Updating an existing installation](#updating-shipit)
24
24
 
25
25
  **II. USING SHIPIT**
26
26
 
@@ -45,8 +45,8 @@ This guide aims to help you [set up](#installation-and-setup), [use](#using-ship
45
45
 
46
46
  Shipit provides you with a Rails template. To bootstrap your Shipit installation:
47
47
 
48
- 1. If you don't have Rails installed, run this command: `gem install rails -v 4.2.6`
49
- 2. Run this command: `rails _4.2.6_ new shipit -m https://raw.githubusercontent.com/Shopify/shipit-engine/master/template.rb`
48
+ 1. If you don't have Rails installed, run this command: `gem install rails -v 5.0.0.1`
49
+ 2. Run this command: `rails _5.0.0.1_ new shipit --skip-action-cable --skip-turbolinks --skip-action-mailer -m https://raw.githubusercontent.com/Shopify/shipit-engine/master/template.rb`
50
50
  3. Enter your **Client ID**, **Client Secret**, and **GitHub API access token** when prompted. These can be found on your application's GitHub page.
51
51
  4. To setup the database, run this command: `rake db:setup`
52
52
 
@@ -551,6 +551,7 @@ Your deploy scripts have access to the following environment variables:
551
551
  * `ENVIRONMENT`: The stack environment (e.g `production` / `staging`)
552
552
  * `BRANCH`: The stack branch (e.g `master`)
553
553
  * `LAST_DEPLOYED_SHA`: The git SHA of the last deployed commit
554
+ * `DIFF_LINK`: URL to the diff on GitHub.
554
555
  * All the content of the `secrets.yml` `env` key
555
556
  * All the content of the `shipit.yml` `machine.environment` key
556
557
 
@@ -54,7 +54,7 @@
54
54
  }
55
55
  }
56
56
 
57
- .task-output-container {
57
+ .task-output-container.task-output-container-main-page {
58
58
  height: calc(100vh - 9rem - 4rem - 1px); // .header and .deploy-banner. -1px is to floor the result
59
59
  }
60
60
 
@@ -0,0 +1,38 @@
1
+ module Shipit
2
+ module Authentication
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :force_github_authentication
7
+ helper_method :current_user
8
+ end
9
+
10
+ module ClassMethods
11
+ def skip_authentication(*args)
12
+ skip_before_action(:force_github_authentication, *args)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def force_github_authentication
19
+ if current_user.logged_in?
20
+ unless current_user.authorized?
21
+ team_handles = Shipit.github_teams.map(&:handle)
22
+ team_list = team_handles.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')
23
+ render plain: "You must be a member of #{team_list} to access this application.", status: :forbidden
24
+ end
25
+ else
26
+ redirect_to Shipit::Engine.routes.url_helpers.github_authentication_path(origin: request.original_url)
27
+ end
28
+ end
29
+
30
+ def current_user
31
+ @current_user ||= find_current_user || AnonymousUser.new
32
+ end
33
+
34
+ def find_current_user
35
+ session[:user_id].present? && User.find_by_id(session[:user_id])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ module Shipit
2
+ module Api
3
+ class CommitsController < BaseController
4
+ require_permission :read, :stack
5
+
6
+ def index
7
+ render_resources stack.commits.reachable.includes(:statuses)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,7 +3,7 @@ module Shipit
3
3
  include ChunksHelper
4
4
 
5
5
  before_action :load_stack
6
- before_action :load_deploy, only: %i(show rollback)
6
+ before_action :load_deploy, only: %i(show rollback revert)
7
7
  before_action :load_until_commit, only: :create
8
8
 
9
9
  def new
@@ -30,6 +30,11 @@ module Shipit
30
30
  @rollback = @deploy.build_rollback
31
31
  end
32
32
 
33
+ def revert
34
+ previous_deploy = @stack.deploys.success.where(until_commit_id: @deploy.since_commit_id).order(id: :desc).first!
35
+ redirect_to rollback_stack_deploy_path(@stack, previous_deploy)
36
+ end
37
+
33
38
  private
34
39
 
35
40
  def load_deploy
@@ -11,12 +11,9 @@ module Shipit
11
11
  helper Shipit::Engine.routes.url_helpers
12
12
  include Shipit::Engine.routes.url_helpers
13
13
 
14
- before_action(
15
- :toogle_bootstrap_feature,
16
- :ensure_required_settings,
17
- :force_github_authentication,
18
- :set_variant,
19
- )
14
+ before_action :toogle_bootstrap_feature, :ensure_required_settings
15
+
16
+ include Shipit::Authentication
20
17
 
21
18
  # Respond to HTML by default
22
19
  respond_to :html
@@ -36,35 +33,5 @@ module Shipit
36
33
 
37
34
  render 'shipit/missing_settings'
38
35
  end
39
-
40
- def force_github_authentication
41
- if current_user.logged_in?
42
- teams = Shipit.github_teams
43
- unless teams.empty? || current_user.teams.where(id: teams).exists?
44
- team_list = teams.map(&:handle).to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')
45
- render plain: "You must be a member of #{team_list} to access this application.", status: :forbidden
46
- end
47
- else
48
- redirect_to Shipit::Engine.routes.url_helpers.github_authentication_path(origin: request.original_url)
49
- end
50
- end
51
-
52
- def current_user
53
- @current_user ||= find_current_user || AnonymousUser.new
54
- end
55
- helper_method :current_user
56
-
57
- def find_current_user
58
- return unless session[:user_id].present?
59
- User.find(session[:user_id])
60
- rescue ActiveRecord::RecordNotFound
61
- end
62
-
63
- def set_variant
64
- return unless request.negotiate_mime('text/partial+html')
65
-
66
- request.format = :html
67
- request.variant = :partial
68
- end
69
36
  end
70
37
  end
@@ -18,10 +18,12 @@ module Shipit
18
18
  def github_commit_range_url(stack, since_commit, until_commit)
19
19
  github_repo_url(stack.repo_owner, stack.repo_name, 'compare', "#{since_commit.sha}...#{until_commit.sha}")
20
20
  end
21
+ module_function :github_commit_range_url
21
22
 
22
23
  def github_user_url(user, *args)
23
24
  [Shipit.github_url, user, *args].join('/')
24
25
  end
26
+ module_function :github_user_url
25
27
 
26
28
  def render_github_user(user)
27
29
  link_to(github_user_url(user.login), class: 'user main-user') do
@@ -32,6 +34,7 @@ module Shipit
32
34
  def github_repo_url(owner, repo, *args)
33
35
  github_user_url(owner, repo, *args)
34
36
  end
37
+ module_function :github_repo_url
35
38
 
36
39
  def github_commit_url(commit)
37
40
  github_repo_url(commit.stack.repo_owner, commit.stack.repo_name, 'commit', commit.sha)
@@ -23,6 +23,10 @@ module Shipit
23
23
  false
24
24
  end
25
25
 
26
+ def authorized?
27
+ false
28
+ end
29
+
26
30
  def stacks_contributed_to
27
31
  []
28
32
  end
@@ -9,6 +9,7 @@ module Shipit
9
9
 
10
10
  def refresh_status
11
11
  Rails.cache.write(CACHE_KEY, Shipit.github_api.github_status)
12
+ rescue Net::OpenTimeout, Octokit::ServerError
12
13
  end
13
14
  end
14
15
  end
@@ -61,6 +61,10 @@ module Shipit
61
61
  true
62
62
  end
63
63
 
64
+ def authorized?
65
+ @authorized ||= Shipit.github_teams.empty? || teams.where(id: Shipit.github_teams.map(&:id)).exists?
66
+ end
67
+
64
68
  def stacks_contributed_to
65
69
  return [] unless id
66
70
  Commit.where('author_id = :id or committer_id = :id', id: id).distinct.pluck(:stack_id)
@@ -6,7 +6,15 @@ module Shipit
6
6
  has_one :author
7
7
  has_one :committer
8
8
 
9
- attributes :additions, :deletions, :authored_at, :committed_at, :html_url, :pull_request
9
+ attributes :additions, :deletions, :authored_at, :committed_at, :html_url, :pull_request, :status, :deployed
10
+
11
+ def deployed
12
+ object.deployed?
13
+ end
14
+
15
+ def status
16
+ object.significant_status.state
17
+ end
10
18
 
11
19
  def html_url
12
20
  github_commit_url(object)
@@ -4,7 +4,7 @@ module Shipit
4
4
 
5
5
  has_many :commits
6
6
 
7
- attributes :compare_url, :additions, :deletions
7
+ attributes :compare_url, :rollback_url, :additions, :deletions
8
8
 
9
9
  def html_url
10
10
  stack_deploy_url(object.stack, object)
@@ -14,6 +14,10 @@ module Shipit
14
14
  github_commit_range_url(object.stack, object.since_commit, object.until_commit)
15
15
  end
16
16
 
17
+ def rollback_url
18
+ revert_stack_deploy_url(object.stack, object)
19
+ end
20
+
17
21
  def type
18
22
  :deploy
19
23
  end
@@ -3,5 +3,9 @@ module Shipit
3
3
  def type
4
4
  :rollback
5
5
  end
6
+
7
+ def include_rollback_url?
8
+ false
9
+ end
6
10
  end
7
11
  end
@@ -18,6 +18,7 @@ module Shipit
18
18
  ended_at
19
19
  updated_at
20
20
  created_at
21
+ env
21
22
  ))
22
23
 
23
24
  def revision
@@ -32,8 +32,10 @@
32
32
  <div class="banner__inner wrapper">
33
33
  <div class="banner__content">
34
34
  <h2 class="banner__title">GitHub is having issues</h2>
35
- "<i><%= github_status[:body] %></i>"
36
- <% unless github_status[:last_updated].nil? %>
35
+ <% if github_status[:body].present? %>
36
+ "<i><%= github_status[:body] %></i>"
37
+ <% end %>
38
+ <% if github_status[:last_updated].present? %>
37
39
  <%= time_ago_in_words(github_status[:last_updated]) %> ago
38
40
  <% end %>
39
41
  </div>
@@ -42,7 +42,7 @@
42
42
  <input type="search" class="search-input" />
43
43
  </div>
44
44
 
45
- <div class="clusterize-scroll task-output-container">
45
+ <div class="clusterize-scroll task-output-container task-output-container-main-page">
46
46
  <pre class="nowrap" data-status="<%= task.status %>"><code class="clusterize-content" data-output="<%= task.chunk_output %>" data-next-chunks-url="<%= next_chunks_url(task) %>"></code></pre>
47
47
  </div>
48
48
  </div>
data/config/routes.rb CHANGED
@@ -35,6 +35,7 @@ Shipit::Engine.routes.draw do
35
35
  resource :output, only: :show
36
36
  end
37
37
  resources :deploys, only: %i(create)
38
+ resources :commits, only: %i(index)
38
39
  post '/task/:task_name' => 'tasks#trigger', as: :trigger_task
39
40
  resources :hooks, only: %i(index create show update destroy)
40
41
  end
@@ -83,6 +84,7 @@ Shipit::Engine.routes.draw do
83
84
  get ':sha', sha: sha_format, on: :new, action: :new, as: ''
84
85
  member do
85
86
  get :rollback
87
+ get :revert
86
88
  end
87
89
  end
88
90
  end
@@ -9,11 +9,16 @@ module Shipit
9
9
  super.merge(
10
10
  'SHA' => commit.sha,
11
11
  'REVISION' => commit.sha,
12
+ 'DIFF_LINK' => diff_url,
12
13
  )
13
14
  end
14
15
 
15
16
  protected
16
17
 
18
+ def diff_url
19
+ Shipit::GithubUrlHelper.github_commit_range_url(@stack, *@task.commit_range)
20
+ end
21
+
17
22
  def permalink
18
23
  Shipit::Engine.routes.url_helpers.stack_deploy_url(@stack, @task)
19
24
  end
@@ -1,3 +1,3 @@
1
1
  module Shipit
2
- VERSION = '0.12.1'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ module Shipit
4
+ module Api
5
+ class CommitsControllerTest < ActionController::TestCase
6
+ setup do
7
+ @stack = shipit_stacks(:shipit)
8
+ authenticate!
9
+ end
10
+
11
+ test "#index returns a list of commits" do
12
+ commit = @stack.commits.last
13
+
14
+ get :index, params: {stack_id: @stack.to_param}
15
+ assert_response :ok
16
+ assert_json '0.sha', commit.sha
17
+ end
18
+ end
19
+ end
20
+ end
@@ -99,5 +99,10 @@ module Shipit
99
99
  end
100
100
  assert_select '#new_rollback #force', 1
101
101
  end
102
+
103
+ test ":revert redirect to the proper rollback page" do
104
+ get :revert, params: {stack_id: @stack.to_param, id: shipit_deploys(:shipit2).id}
105
+ assert_redirected_to rollback_stack_deploy_path(@stack, shipit_deploys(:shipit))
106
+ end
102
107
  end
103
108
  end
Binary file
Binary file
@@ -123,6 +123,25 @@ module Shipit
123
123
  assert_equal 't0k3n', legacy.github_access_token
124
124
  end
125
125
 
126
+ test "users are always logged_in?" do
127
+ assert_predicate @user, :logged_in?
128
+ end
129
+
130
+ test "users are always authorized? if Shipit.github_teams is empty" do
131
+ Shipit.stubs(:github_teams).returns([])
132
+ assert_predicate @user, :authorized?
133
+ end
134
+
135
+ test "users are not authorized? if they aren't part of any Shipit.github_teams" do
136
+ Shipit.stubs(:github_teams).returns([shipit_teams(:cyclimse_cooks)])
137
+ refute_predicate @user, :authorized?
138
+ end
139
+
140
+ test "users are authorized? if they are part of any Shipit.github_teams" do
141
+ Shipit.stubs(:github_teams).returns([shipit_teams(:shopify_developers)])
142
+ assert_predicate @user, :authorized?
143
+ end
144
+
126
145
  private
127
146
 
128
147
  def fetch_user
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipit-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -282,28 +282,28 @@ dependencies:
282
282
  requirements:
283
283
  - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: 5.0.3
285
+ version: '5.0'
286
286
  type: :runtime
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
- version: 5.0.3
292
+ version: '5.0'
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: coffee-rails
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - "~>"
298
298
  - !ruby/object:Gem::Version
299
- version: 4.1.0
299
+ version: '4.2'
300
300
  type: :runtime
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - "~>"
305
305
  - !ruby/object:Gem::Version
306
- version: 4.1.0
306
+ version: '4.2'
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: jquery-rails
309
309
  requirement: !ruby/object:Gem::Requirement
@@ -565,8 +565,10 @@ files:
565
565
  - app/controllers/concerns/shipit/api/cacheable.rb
566
566
  - app/controllers/concerns/shipit/api/paginable.rb
567
567
  - app/controllers/concerns/shipit/api/rendering.rb
568
+ - app/controllers/concerns/shipit/authentication.rb
568
569
  - app/controllers/concerns/shipit/pagination.rb
569
570
  - app/controllers/shipit/api/base_controller.rb
571
+ - app/controllers/shipit/api/commits_controller.rb
570
572
  - app/controllers/shipit/api/deploys_controller.rb
571
573
  - app/controllers/shipit/api/hooks_controller.rb
572
574
  - app/controllers/shipit/api/locks_controller.rb
@@ -745,6 +747,7 @@ files:
745
747
  - lib/tasks/teams.rake
746
748
  - lib/tasks/webhook.rake
747
749
  - test/controllers/api/base_controller_test.rb
750
+ - test/controllers/api/commits_controller_test.rb
748
751
  - test/controllers/api/deploys_controller_test.rb
749
752
  - test/controllers/api/hooks_controller_test.rb
750
753
  - test/controllers/api/locks_controller_test.rb
@@ -912,6 +915,7 @@ specification_version: 4
912
915
  summary: Application deployment software
913
916
  test_files:
914
917
  - test/controllers/api/base_controller_test.rb
918
+ - test/controllers/api/commits_controller_test.rb
915
919
  - test/controllers/api/deploys_controller_test.rb
916
920
  - test/controllers/api/hooks_controller_test.rb
917
921
  - test/controllers/api/locks_controller_test.rb