shipit-engine 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -106
  3. data/app/assets/images/timedout.svg +14 -0
  4. data/app/assets/stylesheets/_pages/_commits.scss +11 -2
  5. data/app/controllers/shipit/stacks_controller.rb +1 -7
  6. data/app/controllers/shipit/webhooks_controller.rb +102 -66
  7. data/app/helpers/shipit/github_url_helper.rb +2 -2
  8. data/app/helpers/shipit/shipit_helper.rb +3 -31
  9. data/app/jobs/shipit/destroy_job.rb +9 -0
  10. data/app/jobs/shipit/github_sync_job.rb +1 -1
  11. data/app/jobs/shipit/setup_github_hook_job.rb +1 -3
  12. data/app/models/shipit/anonymous_user.rb +4 -1
  13. data/app/models/shipit/commit.rb +8 -8
  14. data/app/models/shipit/commit_deployment.rb +3 -3
  15. data/app/models/shipit/commit_deployment_status.rb +2 -2
  16. data/app/models/shipit/deploy.rb +3 -3
  17. data/app/models/shipit/deploy_spec/file_system.rb +3 -3
  18. data/app/models/shipit/deploy_spec/kubernetes_discovery.rb +10 -2
  19. data/app/models/shipit/github_hook.rb +2 -99
  20. data/app/models/shipit/github_status.rb +1 -1
  21. data/app/models/shipit/hook.rb +1 -1
  22. data/app/models/shipit/pull_request.rb +10 -10
  23. data/app/models/shipit/rollback.rb +1 -1
  24. data/app/models/shipit/stack.rb +27 -26
  25. data/app/models/shipit/task.rb +2 -2
  26. data/app/models/shipit/team.rb +4 -17
  27. data/app/models/shipit/user.rb +3 -3
  28. data/app/serializers/shipit/task_serializer.rb +2 -2
  29. data/app/serializers/shipit/user_serializer.rb +1 -1
  30. data/app/views/shipit/missing_settings.html.erb +5 -36
  31. data/app/views/shipit/stacks/new.html.erb +1 -1
  32. data/app/views/shipit/stacks/settings.html.erb +0 -4
  33. data/config/routes.rb +3 -13
  34. data/config/secrets.development.shopify.yml +10 -15
  35. data/config/secrets.development.yml +1 -1
  36. data/db/migrate/20180417130436_remove_all_github_hooks.rb +11 -0
  37. data/lib/shipit.rb +13 -56
  38. data/lib/shipit/command.rb +1 -1
  39. data/lib/shipit/engine.rb +2 -8
  40. data/lib/shipit/github_app.rb +122 -0
  41. data/lib/shipit/octokit_bot_users_patch.rb +25 -0
  42. data/lib/shipit/octokit_iterator.rb +2 -2
  43. data/lib/shipit/version.rb +1 -1
  44. data/lib/tasks/teams.rake +8 -24
  45. data/test/controllers/stacks_controller_test.rb +3 -29
  46. data/test/controllers/webhooks_controller_test.rb +29 -46
  47. data/test/dummy/config/secrets.yml +40 -10
  48. data/test/dummy/db/development.sqlite3 +0 -0
  49. data/test/dummy/db/schema.rb +1 -1
  50. data/test/dummy/db/seeds.rb +0 -1
  51. data/test/dummy/db/test.sqlite3 +0 -0
  52. data/test/fixtures/payloads/push_master.json +7 -6
  53. data/test/fixtures/payloads/push_not_master.json +7 -6
  54. data/test/fixtures/shipit/users.yml +2 -2
  55. data/test/helpers/hooks_helper.rb +1 -1
  56. data/test/helpers/payloads_helper.rb +1 -2
  57. data/test/jobs/destroy_stack_job_test.rb +1 -1
  58. data/test/models/commits_test.rb +5 -5
  59. data/test/models/deploy_spec_test.rb +17 -5
  60. data/test/models/github_hook_test.rb +1 -40
  61. data/test/models/pull_request_test.rb +11 -11
  62. data/test/models/stacks_test.rb +4 -10
  63. data/test/models/team_test.rb +3 -3
  64. data/test/models/users_test.rb +7 -7
  65. data/test/test_helper.rb +1 -1
  66. data/test/unit/github_app_test.rb +44 -0
  67. data/test/unit/shipit_test.rb +2 -49
  68. metadata +9 -3
  69. data/lib/tasks/webhook.rake +0 -6
@@ -11,9 +11,9 @@ module Shipit
11
11
  end
12
12
 
13
13
  test ".find_or_create_by_handle fetch the team from github if it's not in the db already" do
14
- Shipit.github_api.expects(:org_teams).with('shopify', per_page: 100)
14
+ Shipit.github.api.expects(:org_teams).with('shopify', per_page: 100)
15
15
  response = stub(rels: {}, data: [new_team])
16
- Shipit.github_api.expects(:last_response).returns(response)
16
+ Shipit.github.api.expects(:last_response).returns(response)
17
17
  assert_difference -> { Team.count }, 1 do
18
18
  Team.find_or_create_by_handle('Shopify/new-team')
19
19
  end
@@ -21,7 +21,7 @@ module Shipit
21
21
 
22
22
  test "#refresh_members! fetch all the team members from github" do
23
23
  response = stub(rels: {members: members_resource})
24
- Shipit.github_api.expects(:get).with(@team.api_url).returns(response)
24
+ Shipit.github.api.expects(:get).with(@team.api_url).returns(response)
25
25
  assert_difference -> { User.count }, 1 do
26
26
  @team.refresh_members!
27
27
  end
@@ -69,7 +69,7 @@ module Shipit
69
69
  end
70
70
 
71
71
  test "#refresh_from_github! update the user with the latest data from GitHub's API" do
72
- Shipit.github_api.expects(:user).with(@user.github_id).returns(@github_user)
72
+ Shipit.github.api.expects(:user).with(@user.github_id).returns(@github_user)
73
73
  @user.refresh_from_github!
74
74
  @user.reload
75
75
 
@@ -82,8 +82,8 @@ module Shipit
82
82
  user.update!(github_id: @github_user.id)
83
83
  commit = user.authored_commits.last
84
84
 
85
- Shipit.github_api.expects(:user).with(user.github_id).raises(Octokit::NotFound)
86
- Shipit.github_api.expects(:commit).with(commit.github_repo_name, commit.sha).returns(mock(author: @github_user))
85
+ Shipit.github.api.expects(:user).with(user.github_id).raises(Octokit::NotFound)
86
+ Shipit.github.api.expects(:commit).with(commit.github_repo_name, commit.sha).returns(mock(author: @github_user))
87
87
 
88
88
  assert_equal 'bob', user.login
89
89
 
@@ -99,12 +99,12 @@ module Shipit
99
99
  assert_equal @user.github_access_token, @user.github_api.access_token
100
100
  end
101
101
 
102
- test "#github_api fallbacks to Shipit.github_api if the user doesn't have an access_token" do
103
- assert_equal Shipit.github_api, shipit_users(:bob).github_api
102
+ test "#github_api fallbacks to Shipit.github.api if the user doesn't have an access_token" do
103
+ assert_equal Shipit.github.api, shipit_users(:bob).github_api
104
104
  end
105
105
 
106
- test "#github_api fallbacks to Shipit.github_api for anonymous users" do
107
- assert_equal Shipit.github_api, AnonymousUser.new.github_api
106
+ test "#github_api fallbacks to Shipit.github.api for anonymous users" do
107
+ assert_equal Shipit.github.api, AnonymousUser.new.github_api
108
108
  end
109
109
 
110
110
  test "users with legacy encrypted access token get their token reset automatically" do
@@ -43,7 +43,7 @@ class ActiveSupport::TestCase
43
43
  setup do
44
44
  @routes = Shipit::Engine.routes
45
45
  Process.stubs(:kill)
46
- Shipit.github_api.stubs(:login).returns('shipit')
46
+ Shipit.github.api.stubs(:login).returns('shipit')
47
47
  end
48
48
 
49
49
  teardown do
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Shipit
4
+ class GitHubAppTest < ActiveSupport::TestCase
5
+ setup do
6
+ @github = app
7
+ @enterprise = app(domain: 'github.example.com')
8
+ end
9
+
10
+ test "#initialize doesn't raise if given an empty config" do
11
+ assert_nothing_raised do
12
+ GitHubApp.new({})
13
+ end
14
+ end
15
+
16
+ test "#domain defaults to github.com" do
17
+ assert_equal 'github.com', @github.domain
18
+ end
19
+
20
+ test "#url returns the HTTPS url to the github installation" do
21
+ assert_equal 'https://github.example.com', @enterprise.url
22
+ assert_equal 'https://github.example.com/foo/bar', @enterprise.url('/foo/bar')
23
+ assert_equal 'https://github.example.com/foo/bar/baz', @enterprise.url('foo/bar', 'baz')
24
+ end
25
+
26
+ test "#oauth_config.last[:client_options] is nil if domain is not overriden" do
27
+ assert_nil @github.oauth_config.last[:client_options][:site]
28
+ end
29
+
30
+ test "#oauth_config.last[:client_options] returns Enterprise endpoint if domain is overriden" do
31
+ assert_equal 'https://github.example.com/api/v3/', @enterprise.oauth_config.last[:client_options][:site]
32
+ end
33
+
34
+ private
35
+
36
+ def app(extra_config = {})
37
+ GitHubApp.new(default_config.deep_merge(extra_config))
38
+ end
39
+
40
+ def default_config
41
+ Rails.application.secrets.github.deep_dup
42
+ end
43
+ end
44
+ end
@@ -6,60 +6,13 @@ module Shipit
6
6
  Shipit.instance_variables.each(&Shipit.method(:remove_instance_variable))
7
7
  end
8
8
 
9
- test ".github_domain defaults to github.com" do
10
- assert_equal 'github.com', Shipit.github_domain
11
- end
12
-
13
- test ".github_domain can be overriden" do
14
- Rails.application.secrets.stubs(:github_domain).returns('github.example.com')
15
- assert_equal 'github.example.com', Shipit.github_domain
16
- end
17
-
18
- test ".github_enterprise? returns false if github_domain is not overriden" do
19
- refute Shipit.github_enterprise?
20
- end
21
-
22
- test ".github_enterprise? returns true if github_domain is overriden" do
23
- Rails.application.secrets.stubs(:github_domain).returns('github.example.com')
24
- assert Shipit.github_enterprise?
25
- end
26
-
27
- test ".github_url returns the HTTPS url to the github installation" do
28
- Rails.application.secrets.stubs(:github_domain).returns('github.example.com')
29
- assert_equal 'https://github.example.com', Shipit.github_url
30
- assert_equal 'https://github.example.com/foo/bar', Shipit.github_url('/foo/bar')
31
- assert_equal 'https://github.example.com/foo/bar', Shipit.github_url('foo/bar')
32
- end
33
-
34
- test ".github_api_endpoint returns nil if github_domain is not overriden" do
35
- assert_nil Shipit.github_api_endpoint
36
- end
37
-
38
- test ".github_api_endpoint returns Enterprise endpoint if github_domain is overriden" do
39
- Rails.application.secrets.stubs(:github_domain).returns('github.example.com')
40
- assert_equal 'https://github.example.com/api/v3/', Shipit.github_api_endpoint
41
- end
42
-
43
- test ".github_oauth_options returns an empty hash if not enterprise" do
44
- refute Shipit.github_enterprise?
45
- assert_equal({}, Shipit.github_oauth_options)
46
- end
47
-
48
9
  test ".github_teams returns an empty array if there's no team" do
49
10
  assert_equal([], Shipit.github_teams)
50
11
  end
51
12
 
52
- test ".github_teams returns the team key as an array" do
53
- Rails.application.secrets.stubs(:github_oauth).returns('team' => 'shopify/developers')
13
+ test ".github_teams returns the teams key as an array of Team" do
14
+ Shipit.github.stubs(:oauth_teams).returns(['shopify/developers'])
54
15
  assert_equal(['shopify/developers'], Shipit.github_teams.map(&:handle))
55
16
  end
56
-
57
- test ".github_teams merges the teams and team keys in a single array" do
58
- Rails.application.secrets.stubs(:github_oauth).returns(
59
- 'team' => 'shopify/developers',
60
- 'teams' => ['shopify/developers', 'cyclimse/cooks'],
61
- )
62
- assert_equal(['cyclimse/cooks', 'shopify/developers'], Shipit.github_teams.map(&:handle))
63
- end
64
17
  end
65
18
  end
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.21.0
4
+ version: 0.22.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: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -423,6 +423,7 @@ files:
423
423
  - app/assets/images/ship.png
424
424
  - app/assets/images/success-small.svg
425
425
  - app/assets/images/success.svg
426
+ - app/assets/images/timedout.svg
426
427
  - app/assets/images/unknown.svg
427
428
  - app/assets/images/validation/invalid.png
428
429
  - app/assets/images/validation/required.png
@@ -506,6 +507,7 @@ files:
506
507
  - app/jobs/shipit/create_on_github_job.rb
507
508
  - app/jobs/shipit/deferred_touch_job.rb
508
509
  - app/jobs/shipit/deliver_hook_job.rb
510
+ - app/jobs/shipit/destroy_job.rb
509
511
  - app/jobs/shipit/destroy_stack_job.rb
510
512
  - app/jobs/shipit/emit_event_job.rb
511
513
  - app/jobs/shipit/fetch_commit_stats_job.rb
@@ -662,6 +664,7 @@ files:
662
664
  - db/migrate/20170904103242_reindex_deliveries.rb
663
665
  - db/migrate/20171120161420_add_base_info_to_pull_request.rb
664
666
  - db/migrate/20180202220850_add_aborted_by_to_tasks.rb
667
+ - db/migrate/20180417130436_remove_all_github_hooks.rb
665
668
  - lib/shipit-engine.rb
666
669
  - lib/shipit.rb
667
670
  - lib/shipit/command.rb
@@ -671,7 +674,9 @@ files:
671
674
  - lib/shipit/engine.rb
672
675
  - lib/shipit/environment_variables.rb
673
676
  - lib/shipit/first_parent_commits_iterator.rb
677
+ - lib/shipit/github_app.rb
674
678
  - lib/shipit/null_serializer.rb
679
+ - lib/shipit/octokit_bot_users_patch.rb
675
680
  - lib/shipit/octokit_iterator.rb
676
681
  - lib/shipit/paginator.rb
677
682
  - lib/shipit/rollback_commands.rb
@@ -697,7 +702,6 @@ files:
697
702
  - lib/tasks/cron.rake
698
703
  - lib/tasks/dev.rake
699
704
  - lib/tasks/teams.rake
700
- - lib/tasks/webhook.rake
701
705
  - test/controllers/api/base_controller_test.rb
702
706
  - test/controllers/api/ccmenu_controller_test.rb
703
707
  - test/controllers/api/commits_controller_test.rb
@@ -845,6 +849,7 @@ files:
845
849
  - test/unit/csv_serializer_test.rb
846
850
  - test/unit/deploy_commands_test.rb
847
851
  - test/unit/environment_variables_test.rb
852
+ - test/unit/github_app_test.rb
848
853
  - test/unit/github_url_helper_test.rb
849
854
  - test/unit/shipit_test.rb
850
855
  - test/unit/variable_definition_test.rb
@@ -884,6 +889,7 @@ test_files:
884
889
  - test/unit/command_test.rb
885
890
  - test/unit/commands_test.rb
886
891
  - test/unit/deploy_commands_test.rb
892
+ - test/unit/github_app_test.rb
887
893
  - test/unit/github_url_helper_test.rb
888
894
  - test/unit/variable_definition_test.rb
889
895
  - test/unit/csv_serializer_test.rb
@@ -1,6 +0,0 @@
1
- namespace :webhook do
2
- desc "get all the webhooks back in sync"
3
- task sync_all: [:environment] do
4
- Shipit::Stack.find_each(&:setup_hooks)
5
- end
6
- end