bozo-scripts 0.3.1 → 0.3.2

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.
@@ -1,79 +1,79 @@
1
- module Bozo::Hooks
2
-
3
- # Hooks for notifying GitHub of the build
4
- #
5
- # The following env variables are required
6
- # - BUILD_URL
7
- # - BUILD_NUMBER
8
- #
9
- # with_hook :git_hub do |h|
10
- # h.token '.....'
11
- # h.owner 'zopaUK'
12
- # h.repo 'bozo-scripts'
13
- # end
14
- #
15
- class GitHub
16
- require 'net/http'
17
- require 'openssl'
18
- require 'json'
19
-
20
- def pre_build
21
- submit_notification(:pending, "Build #{build_number} pending")
22
- end
23
-
24
- def post_build
25
- submit_notification(:success, "Build #{build_number} succeeded")
26
- end
27
-
28
- def failed_build
29
- submit_notification(:failure, "Build #{build_number} failed")
30
- end
31
-
32
- def token(token)
33
- @token = token
34
- end
35
-
36
- def owner(owner)
37
- @owner = owner
38
- end
39
-
40
- def repo(repo)
41
- @repo = repo
42
- end
43
-
44
- private
45
-
46
- def build_url
47
- env['BUILD_URL']
48
- end
49
-
50
- def build_number
51
- env['BUILD_NUMBER']
52
- end
53
-
54
- def submit_notification(state, description)
55
- return unless build_server?
56
-
57
- log_info "Notifying GitHub of #{state} - #{description} - #{build_url}"
58
-
59
- commit = `git rev-parse HEAD`
60
-
61
- uri = URI("https://api.github.com/repos/#{@owner}/#{@repo}/statuses/#{commit}")
62
- header = {
63
- 'Content-Type' => 'application/json',
64
- 'Authorization' => "token #{@token}",
65
- 'User-Agent' => 'Bozo GitHub notifier'
66
- }
67
- data = { state: state, description: description, target_url: build_url}.to_json
68
-
69
- http = Net::HTTP.new(uri.host, uri.port)
70
- http.use_ssl = true
71
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
72
- http.post(uri.request_uri, data, header)
73
-
74
- log_info "Notified GitHub of #{state} - #{description} - #{build_url}"
75
- end
76
-
77
- end
78
-
79
- end
1
+ module Bozo::Hooks
2
+
3
+ # Hooks for notifying GitHub of the build
4
+ #
5
+ # The following env variables are required
6
+ # - BUILD_URL
7
+ # - BUILD_NUMBER
8
+ #
9
+ # with_hook :git_hub do |h|
10
+ # h.token '.....'
11
+ # h.owner 'zopaUK'
12
+ # h.repo 'bozo-scripts'
13
+ # end
14
+ #
15
+ class GitHub
16
+ require 'net/http'
17
+ require 'openssl'
18
+ require 'json'
19
+
20
+ def pre_build
21
+ submit_notification(:pending, "Build #{build_number} pending")
22
+ end
23
+
24
+ def post_build
25
+ submit_notification(:success, "Build #{build_number} succeeded")
26
+ end
27
+
28
+ def failed_build
29
+ submit_notification(:failure, "Build #{build_number} failed")
30
+ end
31
+
32
+ def token(token)
33
+ @token = token
34
+ end
35
+
36
+ def owner(owner)
37
+ @owner = owner
38
+ end
39
+
40
+ def repo(repo)
41
+ @repo = repo
42
+ end
43
+
44
+ private
45
+
46
+ def build_url
47
+ env['BUILD_URL']
48
+ end
49
+
50
+ def build_number
51
+ env['BUILD_NUMBER']
52
+ end
53
+
54
+ def submit_notification(state, description)
55
+ return unless build_server?
56
+
57
+ log_info "Notifying GitHub of #{state} - #{description} - #{build_url}"
58
+
59
+ commit = `git rev-parse HEAD`
60
+
61
+ uri = URI("https://api.github.com/repos/#{@owner}/#{@repo}/statuses/#{commit}")
62
+ header = {
63
+ 'Content-Type' => 'application/json',
64
+ 'Authorization' => "token #{@token}",
65
+ 'User-Agent' => 'Bozo GitHub notifier'
66
+ }
67
+ data = { state: state, description: description, target_url: build_url}.to_json
68
+
69
+ http = Net::HTTP.new(uri.host, uri.port)
70
+ http.use_ssl = true
71
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
72
+ http.post(uri.request_uri, data, header)
73
+
74
+ log_info "Notified GitHub of #{state} - #{description} - #{build_url}"
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -1,23 +1,23 @@
1
- module Bozo::Hooks
2
-
3
- # Hook to tag a git repository when a release is published from a build
4
- # server.
5
- class GitTagRelease
6
-
7
- def post_publish
8
- return unless build_server?
9
- log_info "Tagging repository for release #{env['BUILD_VERSION']}"
10
-
11
- tag_name = "rel-#{env['BUILD_VERSION']}"
12
-
13
- if `git tag`.split("\n").include? tag_name
14
- log_warn "The tag #{tag_name} already exists"
15
- else
16
- execute_command :git, ['git', 'tag', tag_name]
17
- execute_command :git, ['git', 'push', '--tags']
18
- end
19
- end
20
-
21
- end
22
-
1
+ module Bozo::Hooks
2
+
3
+ # Hook to tag a git repository when a release is published from a build
4
+ # server.
5
+ class GitTagRelease
6
+
7
+ def post_publish
8
+ return unless build_server?
9
+ log_info "Tagging repository for release #{env['BUILD_VERSION']}"
10
+
11
+ tag_name = "rel-#{env['BUILD_VERSION']}"
12
+
13
+ if `git tag`.split("\n").include? tag_name
14
+ log_warn "The tag #{tag_name} already exists"
15
+ else
16
+ execute_command :git, ['git', 'tag', tag_name]
17
+ execute_command :git, ['git', 'push', '--tags']
18
+ end
19
+ end
20
+
21
+ end
22
+
23
23
  end
@@ -1,102 +1,102 @@
1
- module Bozo::Hooks
2
-
3
- # Hooks for notifying Hipchat of the build
4
- #
5
- # The following env variables are required
6
- # - BUILD_URL
7
- # - BUILD_NAME
8
- #
9
- # with_hook :hipchat do |h|
10
- # h.token '.....'
11
- # h.room_id 'Dev'
12
- # h.name 'Bozo'
13
- # h.notify :failure
14
- # end
15
- #
16
- class Hipchat
17
- require 'net/http'
18
- require 'openssl'
19
- require 'json'
20
-
21
- COLOR_MAP = { pending: 'gray', success: 'green', failure: 'red' }
22
-
23
- def initialize
24
- @name = 'Bozo'
25
- @notify = []
26
- end
27
-
28
- def pre_build
29
- submit_notification(:pending, "Building #{project_name}")
30
- end
31
-
32
- def post_build
33
- submit_notification(:success, "Built #{project_name}")
34
- end
35
-
36
- def failed_build
37
- submit_notification(:failure, "Failed to build #{project_name}")
38
- end
39
-
40
- def token(token)
41
- @token = token
42
- end
43
-
44
- def room_id(room)
45
- @room = room
46
- end
47
-
48
- def name(name)
49
- @name = name
50
- end
51
-
52
- def notify(state)
53
- @notify << state
54
- end
55
-
56
- private
57
-
58
- def build_url
59
- env['BUILD_URL']
60
- end
61
-
62
- def build_number
63
- env['BUILD_NUMBER']
64
- end
65
-
66
- def project_name
67
- env['BUILD_NAME']
68
- end
69
-
70
- def submit_notification(state, description)
71
- return unless build_server?
72
- return unless @notify.include?(state)
73
-
74
- log_info "Notifying Hipchat of #{state} - #{description} - #{build_url}"
75
-
76
- message = "#{description} - <a href=\"#{build_url}\">view</a>"
77
-
78
- uri = URI("https://api.hipchat.com/v1/rooms/message?format=json&auth_token=#{@token}")
79
- header = {
80
- 'Content-Type' => 'application/x-www-form-urlencoded',
81
- 'User-Agent' => 'Bozo Hipchat notifier'
82
- }
83
- data = URI.encode_www_form({
84
- room_id: @room,
85
- from: @name,
86
- message: message,
87
- message_format: 'html',
88
- color: COLOR_MAP[state],
89
- notify: state == :failure ? '1' : '0'
90
- })
91
-
92
- http = Net::HTTP.new(uri.host, uri.port)
93
- http.use_ssl = true
94
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
95
- http.post(uri.request_uri, data, header)
96
-
97
- log_info "Notified Hipchat of #{state} - #{description} - #{build_url}"
98
- end
99
-
100
- end
101
-
1
+ module Bozo::Hooks
2
+
3
+ # Hooks for notifying Hipchat of the build
4
+ #
5
+ # The following env variables are required
6
+ # - BUILD_URL
7
+ # - BUILD_NAME
8
+ #
9
+ # with_hook :hipchat do |h|
10
+ # h.token '.....'
11
+ # h.room_id 'Dev'
12
+ # h.name 'Bozo'
13
+ # h.notify :failure
14
+ # end
15
+ #
16
+ class Hipchat
17
+ require 'net/http'
18
+ require 'openssl'
19
+ require 'json'
20
+
21
+ COLOR_MAP = { pending: 'gray', success: 'green', failure: 'red' }
22
+
23
+ def initialize
24
+ @name = 'Bozo'
25
+ @notify = []
26
+ end
27
+
28
+ def pre_build
29
+ submit_notification(:pending, "Building #{project_name}")
30
+ end
31
+
32
+ def post_build
33
+ submit_notification(:success, "Built #{project_name}")
34
+ end
35
+
36
+ def failed_build
37
+ submit_notification(:failure, "Failed to build #{project_name}")
38
+ end
39
+
40
+ def token(token)
41
+ @token = token
42
+ end
43
+
44
+ def room_id(room)
45
+ @room = room
46
+ end
47
+
48
+ def name(name)
49
+ @name = name
50
+ end
51
+
52
+ def notify(state)
53
+ @notify << state
54
+ end
55
+
56
+ private
57
+
58
+ def build_url
59
+ env['BUILD_URL']
60
+ end
61
+
62
+ def build_number
63
+ env['BUILD_NUMBER']
64
+ end
65
+
66
+ def project_name
67
+ env['BUILD_NAME']
68
+ end
69
+
70
+ def submit_notification(state, description)
71
+ return unless build_server?
72
+ return unless @notify.include?(state)
73
+
74
+ log_info "Notifying Hipchat of #{state} - #{description} - #{build_url}"
75
+
76
+ message = "#{description} - <a href=\"#{build_url}\">view</a>"
77
+
78
+ uri = URI("https://api.hipchat.com/v1/rooms/message?format=json&auth_token=#{@token}")
79
+ header = {
80
+ 'Content-Type' => 'application/x-www-form-urlencoded',
81
+ 'User-Agent' => 'Bozo Hipchat notifier'
82
+ }
83
+ data = URI.encode_www_form({
84
+ room_id: @room,
85
+ from: @name,
86
+ message: message,
87
+ message_format: 'html',
88
+ color: COLOR_MAP[state],
89
+ notify: state == :failure ? '1' : '0'
90
+ })
91
+
92
+ http = Net::HTTP.new(uri.host, uri.port)
93
+ http.use_ssl = true
94
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
95
+ http.post(uri.request_uri, data, header)
96
+
97
+ log_info "Notified Hipchat of #{state} - #{description} - #{build_url}"
98
+ end
99
+
100
+ end
101
+
102
102
  end
@@ -1,19 +1,19 @@
1
- module Bozo::Hooks
2
-
3
- class Jenkins
4
-
5
- def pre_build
6
- if Jenkins.hosted_in_jenkins?
7
- env['BUILD_URL'] = ENV['BUILD_URL']
8
- env['BUILD_NUMBER'] = ENV['BUILD_NUMBER']
9
- env['BUILD_NAME'] = ENV['JOB_NAME']
10
- end
11
- end
12
-
13
- def self.hosted_in_jenkins?
14
- not ENV['JENKINS_HOME'].nil?
15
- end
16
-
17
- end
18
-
1
+ module Bozo::Hooks
2
+
3
+ class Jenkins
4
+
5
+ def pre_build
6
+ if Jenkins.hosted_in_jenkins?
7
+ env['BUILD_URL'] = ENV['BUILD_URL']
8
+ env['BUILD_NUMBER'] = ENV['BUILD_NUMBER']
9
+ env['BUILD_NAME'] = ENV['JOB_NAME']
10
+ end
11
+ end
12
+
13
+ def self.hosted_in_jenkins?
14
+ not ENV['JENKINS_HOME'].nil?
15
+ end
16
+
17
+ end
18
+
19
19
  end
@@ -1,92 +1,92 @@
1
- module Bozo::Hooks
2
-
3
- class Teamcity
4
-
5
- include Bozo::ClassNameHelpers
6
-
7
- def pre_compile
8
- return unless Teamcity.hosted_in_teamcity?
9
- log_pre_step :compile
10
-
11
- puts "##teamcity[buildNumber '#{version}']"
12
- # currently a general compiler which wraps everything. Once a compiler hook is added can distinguish
13
- # each specific compiler
14
- puts "##teamcity[compilationStarted compiler='Bozo']"
15
- end
16
-
17
- def post_compile
18
- return unless Teamcity.hosted_in_teamcity?
19
- puts "##teamcity[compilationFinished compiler='Bozo']"
20
- log_post_step :compile
21
- end
22
-
23
- def post_test
24
- return unless Teamcity.hosted_in_teamcity?
25
-
26
- report
27
- report_dotnetcoverage
28
-
29
- log_post_step :test
30
- end
31
-
32
- def method_missing(method, *args)
33
- if method.to_s =~ /^(pre|post)_(.+)/
34
- send "log_#{$1}_step".to_sym, $2
35
- else
36
- super
37
- end
38
- end
39
-
40
- def respond_to?(method)
41
- method.to_s =~ /^(pre|post)_(.+)/ or super
42
- end
43
-
44
- # Returns whether teamcity is hosting bozo
45
- def self.hosted_in_teamcity?
46
- not ENV['TEAMCITY_VERSION'].nil?
47
- end
48
-
49
- private
50
-
51
- # Notifies teamcity of general reports such as test runner results
52
- def report
53
- report_types = [:nunit, :fxcop]
54
- report_types.each do |type|
55
- reports = report_files(File.join(Dir.pwd, "/temp"), type)
56
-
57
- reports.each do |report|
58
- puts "##teamcity[importData type='#{type}' path='#{report}']"
59
- end
60
- end
61
- end
62
-
63
- # Notifies teamcity of dotNetCoverage results
64
- def report_dotnetcoverage
65
- tool_types = [:dot_cover]
66
-
67
- tool_types.each do |type|
68
- reports = report_files(File.join(Dir.pwd, "/temp"), type)
69
-
70
- reports.each do |report|
71
- tool_name = to_class_name(type).downcase
72
- puts "##teamcity[importData type='dotNetCoverage' tool='#{tool_name}' path='#{report}']"
73
- end
74
- end
75
- end
76
-
77
- def log_pre_step(step)
78
- puts "##teamcity[progressStart 'Pre #{step}']" if Teamcity.hosted_in_teamcity?
79
- end
80
-
81
- def log_post_step(step)
82
- puts "##teamcity[progressEnd 'Post #{step}']" if Teamcity.hosted_in_teamcity?
83
- end
84
-
85
- def report_files(path, type)
86
- files = File.expand_path(File.join(path, "/**/*-#{to_class_name(type)}-report.xml"))
87
- Dir[files]
88
- end
89
-
90
- end
91
-
1
+ module Bozo::Hooks
2
+
3
+ class Teamcity
4
+
5
+ include Bozo::ClassNameHelpers
6
+
7
+ def pre_compile
8
+ return unless Teamcity.hosted_in_teamcity?
9
+ log_pre_step :compile
10
+
11
+ puts "##teamcity[buildNumber '#{version}']"
12
+ # currently a general compiler which wraps everything. Once a compiler hook is added can distinguish
13
+ # each specific compiler
14
+ puts "##teamcity[compilationStarted compiler='Bozo']"
15
+ end
16
+
17
+ def post_compile
18
+ return unless Teamcity.hosted_in_teamcity?
19
+ puts "##teamcity[compilationFinished compiler='Bozo']"
20
+ log_post_step :compile
21
+ end
22
+
23
+ def post_test
24
+ return unless Teamcity.hosted_in_teamcity?
25
+
26
+ report
27
+ report_dotnetcoverage
28
+
29
+ log_post_step :test
30
+ end
31
+
32
+ def method_missing(method, *args)
33
+ if method.to_s =~ /^(pre|post)_(.+)/
34
+ send "log_#{$1}_step".to_sym, $2
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def respond_to?(method)
41
+ method.to_s =~ /^(pre|post)_(.+)/ or super
42
+ end
43
+
44
+ # Returns whether teamcity is hosting bozo
45
+ def self.hosted_in_teamcity?
46
+ not ENV['TEAMCITY_VERSION'].nil?
47
+ end
48
+
49
+ private
50
+
51
+ # Notifies teamcity of general reports such as test runner results
52
+ def report
53
+ report_types = [:nunit, :fxcop]
54
+ report_types.each do |type|
55
+ reports = report_files(File.join(Dir.pwd, "/temp"), type)
56
+
57
+ reports.each do |report|
58
+ puts "##teamcity[importData type='#{type}' path='#{report}']"
59
+ end
60
+ end
61
+ end
62
+
63
+ # Notifies teamcity of dotNetCoverage results
64
+ def report_dotnetcoverage
65
+ tool_types = [:dot_cover]
66
+
67
+ tool_types.each do |type|
68
+ reports = report_files(File.join(Dir.pwd, "/temp"), type)
69
+
70
+ reports.each do |report|
71
+ tool_name = to_class_name(type).downcase
72
+ puts "##teamcity[importData type='dotNetCoverage' tool='#{tool_name}' path='#{report}']"
73
+ end
74
+ end
75
+ end
76
+
77
+ def log_pre_step(step)
78
+ puts "##teamcity[progressStart 'Pre #{step}']" if Teamcity.hosted_in_teamcity?
79
+ end
80
+
81
+ def log_post_step(step)
82
+ puts "##teamcity[progressEnd 'Post #{step}']" if Teamcity.hosted_in_teamcity?
83
+ end
84
+
85
+ def report_files(path, type)
86
+ files = File.expand_path(File.join(path, "/**/*-#{to_class_name(type)}-report.xml"))
87
+ Dir[files]
88
+ end
89
+
90
+ end
91
+
92
92
  end