bugsnag-capistrano 1.1.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ require_relative './helpers/server'
2
+ require_relative './helpers/capistrano'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keegan Lowenstein
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-11-23 00:00:00.000000000 Z
14
+ date: 2021-07-13 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: Correlate Capistrano deploys with new errors and increased error rates
17
17
  in Bugsnag
@@ -23,26 +23,32 @@ extra_rdoc_files:
23
23
  - README.md
24
24
  - CHANGELOG.md
25
25
  files:
26
+ - ".github/ISSUE_TEMPLATE/A.md"
27
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
28
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
29
+ - ".github/PULL_REQUEST_TEMPLATE.md"
30
+ - ".github/support.md"
31
+ - ".github/workflows/tests.yml"
26
32
  - ".gitignore"
27
- - ".travis.yml"
28
33
  - CHANGELOG.md
29
34
  - CONTRIBUTING.md
30
35
  - Gemfile
31
36
  - LICENSE.txt
32
37
  - README.md
33
38
  - Rakefile
39
+ - UPGRADING.md
34
40
  - VERSION
35
41
  - bugsnag-capistrano.gemspec
36
42
  - lib/bugsnag-capistrano.rb
37
43
  - lib/bugsnag-capistrano/capistrano.rb
38
44
  - lib/bugsnag-capistrano/capistrano2.rb
39
- - lib/bugsnag-capistrano/deploy.rb
40
- - lib/bugsnag-capistrano/tasks.rb
41
- - lib/bugsnag-capistrano/tasks/bugsnag-capistrano.rake
45
+ - lib/bugsnag-capistrano/release.rb
42
46
  - lib/bugsnag-capistrano/tasks/bugsnag.cap
43
47
  - spec/capistrano_spec.rb
44
- - spec/deploy_spec.rb
45
- - spec/rake_spec.rb
48
+ - spec/helpers/capistrano.rb
49
+ - spec/helpers/server.rb
50
+ - spec/release_spec.rb
51
+ - spec/spec_helper.rb
46
52
  homepage: http://github.com/bugsnag/bugsnag-capistrano
47
53
  licenses:
48
54
  - MIT
@@ -62,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
68
  - !ruby/object:Gem::Version
63
69
  version: '0'
64
70
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 2.6.13
71
+ rubygems_version: 3.2.11
67
72
  signing_key:
68
73
  specification_version: 4
69
74
  summary: Notify Bugsnag when deploying with Capistrano
data/.travis.yml DELETED
@@ -1,77 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
- before_install:
5
- - gem update --system 2.6.11
6
- - gem install bundler -v 1.12.0
7
- - gem --version
8
-
9
- before_script:
10
- - bundle list | grep 'bugsnag\|capistrano'
11
- script: bundle exec rake spec
12
-
13
- jobs:
14
- include:
15
- # JRuby 1.9
16
- - stage: test
17
- env: CAP_2_TEST=true
18
- install: bundle _1.12.0_ install --with test bugsnag
19
- rvm: jruby-19mode
20
- - stage: test
21
- env: CAP_2_TEST=true
22
- install: bundle _1.12.0_ install --with test --without bugsnag
23
- rvm: jruby-19mode
24
- - stage: test
25
- install: bundle _1.12.0_ install --with test bugsnag
26
- rvm: jruby-19mode
27
- - stage: test
28
- install: bundle _1.12.0_ install --with test --without bugsnag
29
- rvm: jruby-19mode
30
-
31
- # Ruby 2.0.0
32
- - stage: test
33
- env: CAP_2_TEST=true
34
- install: bundle install --with test bugsnag --binstubs
35
- rvm: 2.0.0
36
- - stage: test
37
- env: CAP_2_TEST=true
38
- install: bundle install --with test --without bugsnag --binstubs
39
- rvm: 2.0.0
40
- - stage: test
41
- install: bundle install --with test bugsnag --binstubs
42
- rvm: 2.0.0
43
- - stage: test
44
- install: bundle install --with test --without bugsnag --binstubs
45
- rvm: 2.0.0
46
-
47
- # Ruby 2.1.10
48
- - stage: test
49
- env: CAP_2_TEST=true
50
- install: bundle install --with test bugsnag --binstubs
51
- rvm: 2.1.10
52
- - stage: test
53
- env: CAP_2_TEST=true
54
- install: bundle install --with test --without bugsnag --binstubs
55
- rvm: 2.1.10
56
- - stage: test
57
- install: bundle install --with test bugsnag --binstubs
58
- rvm: 2.1.10
59
- - stage: test
60
- install: bundle install --with test --without bugsnag --binstubs
61
- rvm: 2.1.10
62
-
63
- # Ruby 2.3.0
64
- - stage: test
65
- install: bundle install --with test bugsnag --binstubs
66
- rvm: 2.3.0
67
- - stage: test
68
- install: bundle install --with test --without bugsnag --binstubs
69
- rvm: 2.3.0
70
-
71
- # Ruby 2.4.2
72
- - stage: test
73
- install: bundle install --with test bugsnag --binstubs
74
- rvm: 2.4.2
75
- - stage: test
76
- install: bundle install --with test --without bugsnag --binstubs
77
- rvm: 2.4.2
@@ -1,98 +0,0 @@
1
- require "json"
2
- require "net/http"
3
- require "logger"
4
-
5
- module Bugsnag
6
- module Capistrano
7
- class Deploy
8
-
9
- HEADERS = {"Content-Type" => "application/json"}
10
- DEFAULT_DEPLOY_ENDPOINT = "https://notify.bugsnag.com/deploy"
11
-
12
- def self.notify(opts = {})
13
- begin
14
- require 'bugsnag'
15
- self.notify_using_bugsnag(opts)
16
- rescue LoadError
17
- self.notify_without_bugsnag(opts)
18
- end
19
- end
20
-
21
- def self.notify_using_bugsnag(opts = {})
22
-
23
- configuration = Bugsnag.configuration.dup
24
-
25
- [:api_key, :app_version, :release_stage, :endpoint, :use_ssl,
26
- :proxy_host, :proxy_port, :proxy_user, :proxy_password].each do |param|
27
- unless opts[param].nil?
28
- configuration.send :"#{param}=", opts[param]
29
- end
30
- end
31
-
32
- if Gem::Version.new(Bugsnag::VERSION).release >= Gem::Version.new('6.0.0')
33
- endpoint = configuration.endpoint
34
- else
35
- endpoint = (configuration.use_ssl ? "https://" : "http://") + configuration.endpoint
36
- end
37
-
38
- parameters = {
39
- "apiKey" => configuration.api_key,
40
- "releaseStage" => configuration.release_stage,
41
- "appVersion" => configuration.app_version,
42
- "revision" => opts[:revision],
43
- "repository" => opts[:repository],
44
- "branch" => opts[:branch]
45
- }.reject {|k,v| v == nil}
46
-
47
- raise RuntimeError.new("No API key found when notifying of deploy") if !parameters["apiKey"] || parameters["apiKey"].empty?
48
-
49
-
50
- payload_string = ::JSON.dump(parameters)
51
- Bugsnag::Delivery::Synchronous.deliver(endpoint, payload_string, configuration)
52
- end
53
-
54
- def self.notify_without_bugsnag(opts = {})
55
- endpoint = (opts[:endpoint].nil? ? DEFAULT_DEPLOY_ENDPOINT : opts[:endpoint])
56
-
57
- parameters = {
58
- "apiKey" => opts[:api_key],
59
- "releaseStage" => opts[:release_stage],
60
- "appVersion" => opts[:app_version],
61
- "revision" => opts[:revision],
62
- "repository" => opts[:repository],
63
- "branch" => opts[:branch]
64
- }.reject {|k, v| v == nil}
65
-
66
- raise RuntimeError.new("No API key found when notifying of deploy") if !parameters["apiKey"] || parameters["apiKey"].empty?
67
-
68
- payload_string = ::JSON.dump(parameters)
69
- self.deliver(endpoint, payload_string)
70
- end
71
-
72
- def self.deliver(url, body)
73
- logger = Logger.new(STDOUT)
74
- logger.level = Logger::INFO
75
- begin
76
- request(url, body)
77
- rescue StandardError => e
78
- logger.warn("Notification to #{url} failed, #{e.inspect}")
79
- logger.warn(e.backtrace)
80
- end
81
- end
82
-
83
- def self.request(url, body)
84
- uri = URI.parse(url)
85
- http = Net::HTTP.new(uri.host, uri.port)
86
- http.read_timeout = 15
87
- http.open_timeout = 15
88
-
89
- http.use_ssl = uri.scheme == "https"
90
-
91
- uri.path == "" ? "/" : uri.path
92
- request = Net::HTTP::Post.new(uri, HEADERS)
93
- request.body = body
94
- http.request(request)
95
- end
96
- end
97
- end
98
- end
@@ -1,2 +0,0 @@
1
- require_relative 'deploy'
2
- load File.join(File.dirname(File.expand_path(__FILE__)), 'tasks/bugsnag-capistrano.rake')
@@ -1,85 +0,0 @@
1
- require "bugsnag-capistrano/deploy"
2
-
3
- namespace :bugsnag do
4
-
5
- desc "Notify Bugsnag of a new deploy."
6
- task :deploy do
7
- api_key = ENV["BUGSNAG_API_KEY"]
8
- release_stage = ENV["BUGSNAG_RELEASE_STAGE"]
9
- app_version = ENV["BUGSNAG_APP_VERSION"]
10
- revision = ENV["BUGSNAG_REVISION"]
11
- repository = ENV["BUGSNAG_REPOSITORY"]
12
- branch = ENV["BUGSNAG_BRANCH"]
13
- endpoint = ENV["BUGSNAG_ENDPOINT"]
14
-
15
- Rake::Task["load"].invoke unless api_key
16
-
17
- Bugsnag::Capistrano::Deploy.notify({
18
- :api_key => api_key,
19
- :release_stage => release_stage,
20
- :app_version => app_version,
21
- :revision => revision,
22
- :repository => repository,
23
- :branch => branch,
24
- :endpoint => endpoint,
25
- })
26
- end
27
-
28
- namespace :heroku do
29
- desc "Add a heroku deploy hook to notify Bugsnag of deploys"
30
- task :add_deploy_hook => :load do
31
- # Wrapper to run command safely even in bundler
32
- run_command = lambda { |command|
33
- defined?(Bundler.with_clean_env) ? Bundler.with_clean_env { `#{command}` } : `#{command}`
34
- }
35
-
36
- # Fetch heroku config settings
37
- config_command = "heroku config --shell"
38
- config_command += " --app #{ENV["HEROKU_APP"]}" if ENV["HEROKU_APP"]
39
- heroku_env = run_command.call(config_command).split(/[\n\r]/).each_with_object({}) do |c, obj|
40
- k,v = c.split("=")
41
- obj[k] = (v.nil? || v.strip.empty?) ? nil : v
42
- end
43
-
44
- # Check for Bugsnag API key (required) using Bugsnag configuration only if available
45
- begin
46
- require 'bugsnag'
47
- api_key = heroku_env["BUGSNAG_API_KEY"] || Bugsnag.configuration.api_key || ENV["BUGSNAG_API_KEY"]
48
- rescue LoadError
49
- api_key = heroku_env["BUGSNAG_API_KEY"] || ENV["BUGSNAG_API_KEY"]
50
- end
51
-
52
- unless api_key
53
- puts "Error: No API key found, have you run 'heroku config:set BUGSNAG_API_KEY=your-api-key'?"
54
- next
55
- end
56
-
57
- # Build the request, making use of deploy hook variables
58
- # (https://devcenter.heroku.com/articles/deploy-hooks#customizing-messages)
59
- params = {
60
- :apiKey => api_key,
61
- :branch => "master",
62
- :revision => "{{head_long}}",
63
- :releaseStage => heroku_env["RAILS_ENV"] || ENV["RAILS_ENV"] || "production"
64
- }
65
- repo = `git config --get remote.origin.url`.strip
66
- params[:repository] = repo unless repo.empty?
67
-
68
- # Add the hook
69
- url = "https://notify.bugsnag.com/deploy?" + params.map {|k,v| "#{k}=#{v}"}.join("&")
70
- command = "heroku addons:add deployhooks:http --url=\"#{url}\""
71
- command += " --app #{ENV["HEROKU_APP"]}" if ENV["HEROKU_APP"]
72
-
73
- puts "$ #{command}"
74
- run_command.call(command)
75
- end
76
- end
77
-
78
- end
79
-
80
- task :load do
81
- begin
82
- Rake::Task["environment"].invoke
83
- rescue
84
- end
85
- end
data/spec/deploy_spec.rb DELETED
@@ -1,66 +0,0 @@
1
- require 'webmock/rspec'
2
- require 'rspec/expectations'
3
- require 'rspec/mocks'
4
- require 'logger'
5
- require 'json'
6
-
7
- require 'webrick'
8
-
9
- require 'bugsnag-capistrano/deploy'
10
-
11
- describe Bugsnag::Capistrano::Deploy do
12
- describe "with notifier loadable", :with_notifier do
13
-
14
- before do
15
- require "bugsnag"
16
- Bugsnag.configure do |config|
17
- config.api_key = "TEST_API_KEY"
18
- config.release_stage = "production"
19
- config.logger = Logger.new(StringIO.new)
20
- end
21
- end
22
-
23
- after do
24
- Bugsnag.configuration.clear_request_data
25
- end
26
-
27
- it "should call notify_with_bugsnag" do
28
- expect(Bugsnag::Delivery::Synchronous).to receive(:deliver)
29
- Bugsnag::Capistrano::Deploy.notify()
30
- end
31
- end
32
-
33
- describe "without notifier loadable", :without_notifier do
34
- it "should call notify_without bugsnag" do
35
- expect(Bugsnag::Capistrano::Deploy).to receive(:deliver)
36
- Bugsnag::Capistrano::Deploy.notify({:api_key => "test"})
37
- end
38
- end
39
-
40
- describe "the delivery function", :always do
41
- it "delivers a request to the given url" do
42
- url = "http://localhost:56456"
43
- stub_request(:post, url)
44
- .to_return(status:200, body: "")
45
- Bugsnag::Capistrano::Deploy.deliver(url, nil)
46
- end
47
-
48
- it "delivers a body unmodified" do
49
- body = ::JSON.dump({
50
- "paramA" => 'a',
51
- "paramB" => 'b',
52
- "paramHash" => {
53
- "one" => 1,
54
- "two" => 2,
55
- "three" => 3
56
- }
57
- })
58
- url = "http://localhost:56456"
59
- request = stub_request(:post, url)
60
- .with(body: body, headers: { 'Content-Type' => 'application/json'})
61
- .to_return(status:200, body: "")
62
- Bugsnag::Capistrano::Deploy.deliver(url, body)
63
- assert_requested request
64
- end
65
- end
66
- end
data/spec/rake_spec.rb DELETED
@@ -1,64 +0,0 @@
1
- require 'webmock/rspec'
2
- require 'rspec/expectations'
3
- require 'rspec/mocks'
4
-
5
- require 'webrick'
6
-
7
- describe "bugsnag rake", :always do
8
-
9
- server = nil
10
- queue = Queue.new
11
- fixture_path = '../examples/rake'
12
- exec_string = 'bundle exec rake bugsnag:deploy'
13
- example_path = File.join(File.dirname(__FILE__), fixture_path)
14
-
15
- before do
16
- server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new(STDOUT), :AccessLog => []
17
- server.mount_proc '/deploy' do |req, res|
18
- queue.push req.body
19
- res.status = 200
20
- res.body = "OK\n"
21
- end
22
- Thread.new{ server.start }
23
- end
24
-
25
- after do
26
- server.stop
27
- queue.clear
28
- end
29
-
30
- let(:request) { JSON.parse(queue.pop) }
31
-
32
- it "sends a deploy notification to the set endpoint" do
33
- ENV['BUGSNAG_ENDPOINT'] = "http://localhost:" + server.config[:Port].to_s + "/deploy"
34
- ENV['BUGSNAG_API_KEY'] = "YOUR_API_KEY"
35
-
36
- Dir.chdir(example_path) do
37
- system(exec_string)
38
- end
39
-
40
- payload = request()
41
- expect(payload["apiKey"]).to eq('YOUR_API_KEY')
42
- end
43
-
44
- it "allows modifications of deployment characteristics" do
45
- ENV['BUGSNAG_ENDPOINT'] = "http://localhost:" + server.config[:Port].to_s + "/deploy"
46
- ENV['BUGSNAG_API_KEY'] = "this is a test key"
47
- ENV['BUGSNAG_RELEASE_STAGE'] = "test"
48
- ENV['BUGSNAG_REVISION'] = "test"
49
- ENV['BUGSNAG_APP_VERSION'] = "1"
50
- ENV['BUGSNAG_REPOSITORY'] = "test@repo.com:test/test_repo.git"
51
-
52
- Dir.chdir(example_path) do
53
- system(exec_string)
54
- end
55
-
56
- payload = request()
57
- expect(payload["apiKey"]).to eq('this is a test key')
58
- expect(payload["releaseStage"]).to eq('test')
59
- expect(payload["repository"]).to eq("test@repo.com:test/test_repo.git")
60
- expect(payload["appVersion"]).to eq("1")
61
- expect(payload["revision"]).to eq("test")
62
- end
63
- end
64
-