danger-jenkins 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c73c63198272bfa8fbff9e8fb9c533d46f81c997
4
+ data.tar.gz: 028935ffba5be57aae2855d54c92058b44de0fb7
5
+ SHA512:
6
+ metadata.gz: 78516d6408c8ad92b419b7259379e52483c19bd77a21124e31dde114b4ec4ada6b80178b2ea24c0f97d0120a4bfede0f3e0cdafb8383503b991627b7b14f9dfa
7
+ data.tar.gz: 803e4e903dec81f7841d9297eba6c8978504beff3eeae9483048e9b4081b2184329cdb361b6515e5e696436a1b38ecbf69d352e30f644ff495e1b054851b4b21
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake spec
data/.yardoc/checksums ADDED
@@ -0,0 +1,4 @@
1
+ /Users/thiagofelix/workspace/danger-jenkins/lib/danger_jenkins.rb 281beec810012a6a0760b645d8d6eb826f0f8d88
2
+ /Users/thiagofelix/workspace/danger-jenkins/lib/danger_plugin.rb 67001214803ca51d71a62d8f997e2a6fe8419957
3
+ /Users/thiagofelix/workspace/danger-jenkins/lib/jenkins/gem_version.rb fb773d79261e4063070441bbadbc52cb6b9dd504
4
+ /Users/thiagofelix/workspace/danger-jenkins/lib/jenkins/plugin.rb 64ad88c7be7cc7e81128f0366817814d63e9942d
data/.yardoc/complete ADDED
File without changes
Binary file
Binary file
Binary file
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-jenkins.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,157 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-jenkins (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ ast (2.3.0)
12
+ claide (1.0.0)
13
+ claide-plugins (0.9.1)
14
+ cork
15
+ nap
16
+ open4 (~> 1.3)
17
+ coderay (1.1.1)
18
+ colored (1.2)
19
+ cork (0.2.0)
20
+ colored (~> 1.2)
21
+ crack (0.4.3)
22
+ safe_yaml (~> 1.0.0)
23
+ danger (3.3.2)
24
+ claide (~> 1.0)
25
+ claide-plugins (> 0.9.0)
26
+ colored (~> 1.2)
27
+ cork (~> 0.1)
28
+ faraday (~> 0.9)
29
+ faraday-http-cache (~> 1.0)
30
+ git (~> 1)
31
+ gitlab (~> 3.7.0)
32
+ kramdown (~> 1.5)
33
+ octokit (~> 4.2)
34
+ terminal-table (~> 1)
35
+ danger-plugin-api (1.0.0)
36
+ danger (> 2.0)
37
+ diff-lcs (1.2.5)
38
+ faraday (0.9.2)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday-http-cache (1.3.1)
41
+ faraday (~> 0.8)
42
+ ffi (1.9.14)
43
+ formatador (0.2.5)
44
+ git (1.3.0)
45
+ gitlab (3.7.0)
46
+ httparty (~> 0.13.0)
47
+ terminal-table
48
+ guard (2.14.0)
49
+ formatador (>= 0.2.4)
50
+ listen (>= 2.7, < 4.0)
51
+ lumberjack (~> 1.0)
52
+ nenv (~> 0.1)
53
+ notiffany (~> 0.0)
54
+ pry (>= 0.9.12)
55
+ shellany (~> 0.0)
56
+ thor (>= 0.18.1)
57
+ guard-compat (1.2.1)
58
+ guard-rspec (4.7.3)
59
+ guard (~> 2.1)
60
+ guard-compat (~> 1.1)
61
+ rspec (>= 2.99.0, < 4.0)
62
+ hashdiff (0.3.0)
63
+ httparty (0.13.7)
64
+ json (~> 1.8)
65
+ multi_xml (>= 0.5.2)
66
+ json (1.8.3)
67
+ kramdown (1.12.0)
68
+ listen (3.0.7)
69
+ rb-fsevent (>= 0.9.3)
70
+ rb-inotify (>= 0.9.7)
71
+ lumberjack (1.0.10)
72
+ method_source (0.8.2)
73
+ multi_xml (0.5.5)
74
+ multipart-post (2.0.0)
75
+ nap (1.1.0)
76
+ nenv (0.3.0)
77
+ notiffany (0.1.1)
78
+ nenv (~> 0.1)
79
+ shellany (~> 0.0)
80
+ octokit (4.3.0)
81
+ sawyer (~> 0.7.0, >= 0.5.3)
82
+ open4 (1.3.4)
83
+ parser (2.3.1.3)
84
+ ast (~> 2.2)
85
+ powerpack (0.1.1)
86
+ pry (0.10.4)
87
+ coderay (~> 1.1.0)
88
+ method_source (~> 0.8.1)
89
+ slop (~> 3.4)
90
+ rack (1.6.4)
91
+ rack-protection (1.5.3)
92
+ rack
93
+ rainbow (2.1.0)
94
+ rake (10.5.0)
95
+ rb-fsevent (0.9.7)
96
+ rb-inotify (0.9.7)
97
+ ffi (>= 0.5.0)
98
+ rspec (3.5.0)
99
+ rspec-core (~> 3.5.0)
100
+ rspec-expectations (~> 3.5.0)
101
+ rspec-mocks (~> 3.5.0)
102
+ rspec-core (3.5.3)
103
+ rspec-support (~> 3.5.0)
104
+ rspec-expectations (3.5.0)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.5.0)
107
+ rspec-mocks (3.5.0)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.5.0)
110
+ rspec-support (3.5.0)
111
+ rubocop (0.43.0)
112
+ parser (>= 2.3.1.1, < 3.0)
113
+ powerpack (~> 0.1)
114
+ rainbow (>= 1.99.1, < 3.0)
115
+ ruby-progressbar (~> 1.7)
116
+ unicode-display_width (~> 1.0, >= 1.0.1)
117
+ ruby-progressbar (1.8.1)
118
+ safe_yaml (1.0.4)
119
+ sawyer (0.7.0)
120
+ addressable (>= 2.3.5, < 2.5)
121
+ faraday (~> 0.8, < 0.10)
122
+ shellany (0.0.1)
123
+ sinatra (1.4.7)
124
+ rack (~> 1.5)
125
+ rack-protection (~> 1.4)
126
+ tilt (>= 1.3, < 3)
127
+ slop (3.6.0)
128
+ terminal-table (1.7.2)
129
+ unicode-display_width (~> 1.1.1)
130
+ thor (0.19.1)
131
+ tilt (2.0.5)
132
+ unicode-display_width (1.1.1)
133
+ webmock (2.1.0)
134
+ addressable (>= 2.3.6)
135
+ crack (>= 0.3.2)
136
+ hashdiff
137
+ yard (0.9.5)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ bundler (~> 1.3)
144
+ danger-jenkins!
145
+ guard (~> 2.14)
146
+ guard-rspec (~> 4.7)
147
+ listen (= 3.0.7)
148
+ pry
149
+ rake (~> 10.0)
150
+ rspec (~> 3.4)
151
+ rubocop (~> 0.41)
152
+ sinatra (~> 1.4)
153
+ webmock (~> 2.1)
154
+ yard (~> 0.8)
155
+
156
+ BUNDLED WITH
157
+ 1.13.1
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Thiago Felix <thiago@thiagofelix.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+
2
+
3
+ ### jenkins
4
+
5
+ Get access to Jenkins information right into your Dangerfile
6
+
7
+ <blockquote>Configure credentials to access the Jenkins API
8
+ <pre>jenkins.user_id = YOUR_USER_ID
9
+ jenkins.api_token = YOUR_API_TOKEN</pre>
10
+ </blockquote>
11
+
12
+ <blockquote>Print list of artifacts in the PR page
13
+ <pre>jenkins.print_artifacts</pre>
14
+ </blockquote>
15
+
16
+ <blockquote>Print console output in the PR page
17
+ <pre>jenkins.print_console_output</pre>
18
+ </blockquote>
19
+
20
+ <blockquote>Get access to the build properties
21
+ <pre>message "The spent #{jenkins.build.duration} time"</pre>
22
+ </blockquote>
23
+
24
+ <blockquote>Customize how you want to present the console output
25
+ <pre>markdown "### Console output: \n\n #{jenkins.console_text}"</pre>
26
+ </blockquote>
27
+
28
+
29
+
30
+ #### Attributes
31
+
32
+ `user_id` - User to authenticate with Jenkins REST API
33
+
34
+ `api_token` - API token to authenticate with Jenkins REST API
35
+
36
+
37
+
38
+
39
+ #### Methods
40
+
41
+ `build` - Hash containing details about the build which triggered
42
+ the danger process
43
+
44
+ `console_html` - Console output in html format
45
+
46
+ `console_text` - Console output in text format
47
+
48
+ `print_artifacts` - Adds a list of artifacts to the danger comment
49
+
50
+ `print_console_output` - Adds a collapsable console output to danger comment
51
+
52
+
53
+
54
+
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jenkins/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-jenkins'
8
+ spec.version = Jenkins::VERSION
9
+ spec.authors = ['Thiago Felix']
10
+ spec.email = ['thiago@thiagofelix.com']
11
+ spec.description = 'Jenkins build information on Danger DSL.'
12
+ spec.summary = ''
13
+ spec.homepage = 'https://github.com/thiagofelix/danger-jenkins'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+
23
+ # General ruby development
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+
27
+ # Testing support
28
+ spec.add_development_dependency 'rspec', '~> 3.4'
29
+ spec.add_development_dependency 'webmock', '~> 2.1'
30
+ spec.add_development_dependency 'sinatra', '~> 1.4'
31
+
32
+ # Linting code and docs
33
+ spec.add_development_dependency 'rubocop', '~> 0.41'
34
+ spec.add_development_dependency 'yard', '~> 0.8'
35
+
36
+ # Makes testing easy via `bundle exec guard`
37
+ spec.add_development_dependency 'guard', '~> 2.14'
38
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
39
+
40
+ # If you want to work on older builds of ruby
41
+ spec.add_development_dependency 'listen', '3.0.7'
42
+
43
+ # This gives you the chance to run a REPL inside your tests
44
+ # via:
45
+ #
46
+ # require 'pry'
47
+ # binding.pry
48
+ #
49
+ # This will stop test execution and let you inspect the results
50
+ spec.add_development_dependency 'pry'
51
+ end
@@ -0,0 +1 @@
1
+ require 'jenkins/gem_version'
@@ -0,0 +1 @@
1
+ require 'jenkins/plugin'
@@ -0,0 +1,3 @@
1
+ module Jenkins
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,152 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Danger
5
+ # Get access to Jenkins information right into your Dangerfile
6
+ #
7
+ # @example Configure credentials to access the Jenkins API
8
+ # jenkins.user_id = YOUR_USER_ID
9
+ # jenkins.api_token = YOUR_API_TOKEN
10
+ #
11
+ # @example Print list of artifacts in the PR page
12
+ # jenkins.print_artifacts
13
+ #
14
+ # @example Print console output in the PR page
15
+ # jenkins.print_console_output
16
+ #
17
+ # @example Get access to the build properties
18
+ # message "The spent #{jenkins.build.duration} time"
19
+ #
20
+ # @example Customize how you want to present the console output
21
+ # markdown "### Console output: \n\n #{jenkins.console_text}"
22
+ #
23
+ # @see thiagofelix/danger-jenkins
24
+ # @tags jenkins
25
+ #
26
+ class DangerJenkins < Plugin
27
+ JENKINS_ICON = 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png'.freeze
28
+
29
+ # User to authenticate with Jenkins REST API
30
+ #
31
+ # @return String
32
+ attr_accessor :user_id
33
+
34
+ # API token to authenticate with Jenkins REST API
35
+ #
36
+ # @return String
37
+ attr_accessor :api_token
38
+
39
+ def initialize(dangerfile)
40
+ super(dangerfile)
41
+
42
+ @env = dangerfile.env
43
+ @user_id = ENV['JENKINS_USER_ID']
44
+ @api_token = ENV['JENKINS_API_TOKEN']
45
+ @build_url = ENV['BUILD_URL']
46
+
47
+ raise 'Invalid CI for Jenkins plugin.' unless jenkins?
48
+ raise "Can't find current build" if @build_url.nil?
49
+ end
50
+
51
+ # Hash containing details about the build which triggered
52
+ # the danger process
53
+ #
54
+ # @return OpenStruct
55
+ def build
56
+ @current_build ||= fetch_current_build
57
+ end
58
+
59
+ # Console output in html format
60
+ #
61
+ # @return String
62
+ def console_html
63
+ @console_html_format ||= fetch_console(:html)
64
+ end
65
+
66
+ # Console output in text format
67
+ #
68
+ # @return String
69
+ def console_text
70
+ @console_text_format ||= fetch_console(:text)
71
+ end
72
+
73
+ # Adds a list of artifacts to the danger comment
74
+ #
75
+ # @return [void]
76
+ #
77
+ def print_artifacts
78
+ artifacts = build.artifacts
79
+ return if artifacts.empty?
80
+
81
+ content = "### Jenkins artifacts:\n\n"
82
+ content << "<img width='40' align='right' src='#{JENKINS_ICON}'></img>\n"
83
+
84
+ artifacts.each do |artifact|
85
+ content << "* #{artifact_link(artifact)}\n"
86
+ end
87
+
88
+ markdown content
89
+ end
90
+
91
+ # Adds a collapsable console output to danger comment
92
+ #
93
+ # @return [void]
94
+ #
95
+ def print_console_output
96
+ content = "### Jenkins console output:\n\n"
97
+ content << '<details>'
98
+ content << '<summary>Details</summary>'
99
+ content << "<pre>#{console_html}</pre>"
100
+ content << '</details>'
101
+ markdown content
102
+ end
103
+
104
+ private
105
+
106
+ def jenkins?
107
+ !@env.ci_source.nil? && @env.ci_source.is_a?(Danger::Jenkins)
108
+ end
109
+
110
+ def artifact_link(artifact)
111
+ href = "#{@build_url}/artifact/#{artifact.relativePath}"
112
+ "<a href=#{href} target='_blank'>#{artifact.relativePath}</a>"
113
+ end
114
+
115
+ def fetch_console(type = :text)
116
+ case type
117
+ when :text then
118
+ fetch("#{@build_url}/logText/progressiveText")
119
+ when :html then
120
+ fetch("#{@build_url}/logText/progressiveHtml")
121
+ end
122
+ end
123
+
124
+ def fetch_current_build
125
+ url = "#{@build_url}/api/json"
126
+ body = fetch(url)
127
+ JSON.parse(body, object_class: OpenStruct)
128
+ end
129
+
130
+ def fetch(url, limit = 10)
131
+ res = request(url)
132
+
133
+ case res
134
+ when Net::HTTPSuccess then
135
+ res.body
136
+ when Net::HTTPRedirection then
137
+ fetch(res['location'], limit - 1)
138
+ else
139
+ res.value
140
+ end
141
+ end
142
+
143
+ def request(url)
144
+ uri = URI.parse(url)
145
+ http = Net::HTTP.new(uri.host, uri.port)
146
+ req = Net::HTTP::Get.new(uri.request_uri)
147
+ req.basic_auth(@user_id, @api_token)
148
+
149
+ http.request(req)
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerJenkins do
5
+ it 'should be a plugin' do
6
+ dangerfile = jenkins_dangerfile
7
+ expect(Danger::DangerJenkins.new(dangerfile)).to be_a Danger::Plugin
8
+ end
9
+
10
+ #
11
+ # You should test your custom attributes and methods here
12
+ #
13
+ describe 'with Dangerfile' do
14
+ before do
15
+ @dangerfile = jenkins_dangerfile
16
+ @jenkins = @dangerfile.jenkins
17
+ end
18
+
19
+ it 'raise if not Jenkins CI' do
20
+ expect { travis_dangerfile }.to raise_error(RuntimeError)
21
+ end
22
+
23
+ it "raise if can't determine current build" do
24
+ ENV.delete 'BUILD_URL'
25
+ expect { travis_dangerfile }.to raise_error(RuntimeError)
26
+ end
27
+
28
+ it 'queries current build on Jenkins' do
29
+ expect(@jenkins.build.id).to eq('2')
30
+ expect(@jenkins.build.number).to eq(2)
31
+ expect(@jenkins.build.displayName).to eq('#2')
32
+ expect(@jenkins.build.fullDisplayName).to eq('DemoJob #2')
33
+ expect(@jenkins.build.nextBuild.number).to eq(3)
34
+ expect(@jenkins.build.nextBuild.url).to eq('http://jenkins.ci/job/DemoJob/3/')
35
+ expect(@jenkins.build.previousBuild.number).to eq(1)
36
+ expect(@jenkins.build.previousBuild.url).to eq('http://jenkins.ci/job/DemoJob/1/')
37
+ expect(@jenkins.build.result).to eq('SUCCESS')
38
+
39
+ artifacts = ['report.html', 'App.ipa']
40
+ expect(@jenkins.build.artifacts.map(&:displayPath)).to eq(artifacts)
41
+ end
42
+
43
+ it 'prints artifacts' do
44
+ expected = <<-EOF
45
+ ### Jenkins artifacts:
46
+
47
+ <img width='40' align='right' src='https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png'></img>
48
+ * <a href=http://jenkins.ci/job/DemoJob/1/artifact/output/report.html target='_blank'>output/report.html</a>
49
+ * <a href=http://jenkins.ci/job/DemoJob/1/artifact/output/App.ipa target='_blank'>output/App.ipa</a>
50
+ EOF
51
+
52
+ @jenkins.print_artifacts
53
+ markdowns = @dangerfile.status_report[:markdowns].map(&:message)
54
+ expect(markdowns).to eq([expected])
55
+ end
56
+
57
+ it 'prints console output' do
58
+ @jenkins.print_console_output
59
+ markdowns = @dangerfile.status_report[:markdowns].map(&:message)
60
+ expected = [
61
+ "### Jenkins console output:\n\n",
62
+ '<details>',
63
+ '<summary>Details</summary>',
64
+ '<pre>console output</pre>',
65
+ "</details>"
66
+ ].join
67
+ expect(markdowns).to eq([expected])
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,86 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
7
+
8
+ require 'bundler/setup'
9
+ require 'pry'
10
+
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
+ require 'danger'
14
+
15
+ # Use coloured output, it's the best.
16
+ RSpec.configure do |config|
17
+ config.filter_gems_from_backtrace 'bundler'
18
+ config.color = true
19
+ config.tty = true
20
+ config.before(:each) do
21
+ stub_request(:any, /jenkins.ci/).to_rack(FakeJenkins)
22
+ end
23
+ end
24
+
25
+ WebMock.disable_net_connect!(allow_localhost: true)
26
+
27
+ require 'danger_plugin'
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def travis_env
54
+ {
55
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
56
+ 'TRAVIS_PULL_REQUEST' => '800',
57
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
58
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
59
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
60
+ }
61
+ end
62
+
63
+ # Example environment (ENV) that would come from
64
+ # running a PR on Jenkins
65
+ def jenkins_env
66
+ {
67
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio',
68
+ 'ghprbPullId' => 1,
69
+ 'JENKINS_URL' => 'http://jenkins.ci',
70
+ 'BUILD_URL' => 'http://jenkins.ci/job/DemoJob/1',
71
+ 'GIT_URL' => 'https://github.com/danger/danger.git'
72
+ }
73
+ end
74
+
75
+ # A stubbed out Dangerfile on Jenkins for use in tests
76
+ def jenkins_dangerfile
77
+ env = Danger::EnvironmentManager.new(jenkins_env)
78
+ ENV['BUILD_URL'] = jenkins_env['BUILD_URL']
79
+ Danger::Dangerfile.new(env, testing_ui)
80
+ end
81
+
82
+ # A stubbed out Dangerfile on Travis for use in tests
83
+ def travis_dangerfile
84
+ env = Danger::EnvironmentManager.new(travis_env)
85
+ Danger::Dangerfile.new(env, testing_ui)
86
+ end
@@ -0,0 +1,28 @@
1
+ require 'sinatra/base'
2
+
3
+ class FakeJenkins < Sinatra::Base
4
+ get '/job/:job/:build_number/api/json' do
5
+ json_response 200, "#{underscore(params['job'])}.json"
6
+ end
7
+
8
+ get '/job/:job/:build_number/logText/progressiveHtml' do
9
+ content_type :html
10
+ [200, 'console output']
11
+ end
12
+
13
+ private
14
+
15
+ def underscore(camel_cased_word)
16
+ camel_cased_word.to_s.gsub(/::/, '/')
17
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
18
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
19
+ .tr('-', '_')
20
+ .downcase
21
+ end
22
+
23
+ def json_response(response_code, file_name)
24
+ content_type :json
25
+ status response_code
26
+ File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ {
2
+ "_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
3
+ "actions": [],
4
+ "artifacts": [
5
+ {
6
+ "displayPath": "report.html",
7
+ "fileName": "report.html",
8
+ "relativePath": "output/report.html"
9
+ },
10
+ {
11
+ "displayPath": "App.ipa",
12
+ "fileName": "App.ipa",
13
+ "relativePath": "output/App.ipa"
14
+ }
15
+ ],
16
+ "building": false,
17
+ "changeSets": [],
18
+ "description": null,
19
+ "displayName": "#2",
20
+ "duration": 130475,
21
+ "estimatedDuration": 132354,
22
+ "executor": null,
23
+ "fullDisplayName": "DemoJob #2",
24
+ "id": "2",
25
+ "keepLog": false,
26
+ "nextBuild": {
27
+ "number": 3,
28
+ "url": "http://jenkins.ci/job/DemoJob/3/"
29
+ },
30
+ "number": 2,
31
+ "previousBuild": {
32
+ "number": 1,
33
+ "url": "http://jenkins.ci/job/DemoJob/1/"
34
+ },
35
+ "queueId": 182,
36
+ "result": "SUCCESS",
37
+ "timestamp": 1474080704593,
38
+ "url": "http://jenkins.ci/job/DemoJob/2/"
39
+ }
40
+
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-jenkins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Felix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.41'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.41'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.7'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.7
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.7
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Jenkins build information on Danger DSL.
182
+ email:
183
+ - thiago@thiagofelix.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".travis.yml"
190
+ - ".yardoc/checksums"
191
+ - ".yardoc/complete"
192
+ - ".yardoc/object_types"
193
+ - ".yardoc/objects/root.dat"
194
+ - ".yardoc/proxy_types"
195
+ - Gemfile
196
+ - Gemfile.lock
197
+ - Guardfile
198
+ - LICENSE.txt
199
+ - README.md
200
+ - Rakefile
201
+ - danger-jenkins.gemspec
202
+ - lib/danger_jenkins.rb
203
+ - lib/danger_plugin.rb
204
+ - lib/jenkins/gem_version.rb
205
+ - lib/jenkins/plugin.rb
206
+ - spec/jenkins_spec.rb
207
+ - spec/spec_helper.rb
208
+ - spec/support/fake_jenkins.rb
209
+ - spec/support/fixtures/demo_job.json
210
+ homepage: https://github.com/thiagofelix/danger-jenkins
211
+ licenses:
212
+ - MIT
213
+ metadata: {}
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.4.5.1
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: ''
234
+ test_files:
235
+ - spec/jenkins_spec.rb
236
+ - spec/spec_helper.rb
237
+ - spec/support/fake_jenkins.rb
238
+ - spec/support/fixtures/demo_job.json