ci-notify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 837ab6195028f94fe1050adc690c806e5f625a62
4
+ data.tar.gz: 95ce881d376a9ba73e86ca96f0507f5bd4898fe0
5
+ SHA512:
6
+ metadata.gz: bf8ccc6dbb60c1623f81354793a6141a162e3e6ae0c5e986d25fe284546555b34504aeef8d637ca0fa398550528a994f76e86dbeed228063d660881d50b00a6f
7
+ data.tar.gz: 709a1d267a039d4e0e6bb96b750272abdf74afaf7b88ddfc6ff16887cdb43b2cee246fd4b47a62719b69a66ff54956989979938d5c5ba00a25b3a089a6178917
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ ci-notify
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ci-notify.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # ci-notify
2
+
3
+ With the advent of Jenkinsfile and the pipeline, I ran into the problem that
4
+ IRC-notifications were not supported (yet). Since I wanted to migrate to the
5
+ new way, I created a little script to provide me those notifications.
6
+
7
+ Before long, I wanted to share this between projects. You won't guess what
8
+ happened next...
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ci-notify'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ci-notify
25
+
26
+ ## Usage
27
+
28
+ ```bash
29
+ IRC_CHANNEL="foo" DRY_RUN=true ci-notify SUCCESS
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. You can
35
+ also run `bin/console` for an interactive prompt that will allow you to
36
+ experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To
39
+ release a new version, update the version number in `version.rb`, and then run
40
+ `bundle exec rake release`, which will create a git tag for the version, push
41
+ git commits and tags, and push the `.gem` file to
42
+ [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome.
47
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ci/notify"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ci/notify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ci-notify"
8
+ spec.version = Ci::Notify::VERSION
9
+ spec.authors = ["Matthias Viehweger"]
10
+ spec.email = ["kronn@kronn.de"]
11
+
12
+ spec.summary = %q{Send a short notification from Jenkins to IRC}
13
+ spec.description = %q{With the new Jenkinsfile-approach, I wanted a small script to send notifications to IRC. Since most of the information comes from env-vars supplied by Jenkins, this is a very generic script. Packaging this a gem enables proper dependency management.}
14
+ spec.homepage = "https://git.lanpartei.de/kronn/ci-notify"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "shout-bot"
22
+ spec.add_dependency "string-irc"
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require "ci/notify"
4
+
5
+ @dry_run = ENV["DRY_RUN"] || false
6
+ @branch = ENV["BRANCH_NAME"]
7
+ @build_url = ENV["BUILD_URL"]
8
+ @result = ARGV[0]
9
+
10
+ @job_name = ENV["JOB_NAME"] || "CI-job"
11
+ @job_number = ENV["BUILD_NUMBER"]
12
+ @bot_name = %w[ Jenkline Pipekins ].sample
13
+
14
+ unless @dry_run
15
+ @irc_server = ENV["IRC_SERVER"] || "chat.freenode.net"
16
+ @irc_port = ENV["IRC_PORT"] || 6667
17
+ @irc_channel= ENV.fetch("IRC_CHANNEL")
18
+ end
19
+
20
+ @job_name = @job_name.split("/")[0] if @branch && @job_name.gsub("%2F", "/").include?(@branch)
21
+
22
+ @local_echo = Object.new
23
+ def @local_echo.say(message)
24
+ puts "IRC: " + message
25
+ end
26
+
27
+ def irc
28
+ if @dry_run
29
+ yield @local_echo
30
+ else
31
+ begin
32
+ require "shout-bot"
33
+ ShoutBot.new(@irc_server, @irc_port, @bot_name) do |irc|
34
+ irc.channel = @irc_channel
35
+ yield irc
36
+ end
37
+ rescue Errno::ENETUNREACH => e
38
+ yield @local_echo
39
+
40
+ $stderr.puts "Error: #{e.class}"
41
+ $stderr.puts " #{e.message}"
42
+ end
43
+ end
44
+ end
45
+
46
+ # only really needed in dry-run
47
+ module BoldString
48
+ refine String do
49
+ def bold
50
+ self
51
+ end
52
+ end
53
+ end
54
+ using BoldString
55
+
56
+ def color(string, color)
57
+ return string if @dry_run
58
+
59
+ require "string-irc"
60
+ StringIrc.new(string).send(color)
61
+ end
62
+
63
+ irc do |channel|
64
+ branch_info = "for #{color(@branch, :purple)}" if @branch
65
+ job_info = "##{@job_number}" if @job_number
66
+ build_url = "(#{@build_url})" if @build_url
67
+
68
+ if @result && @result != "null"
69
+ result_color = case @result
70
+ when "SUCCESS" then :green
71
+ when "UNSTABLE" then :yellow
72
+ when "FAILURE" then :red
73
+ else :white
74
+ end
75
+ result_info = "with #{color(@result, result_color).bold}"
76
+ end
77
+
78
+ message = [
79
+ @job_name,
80
+ job_info,
81
+ "completed",
82
+ branch_info,
83
+ result_info,
84
+ build_url,
85
+ ].compact.join(" ")
86
+
87
+ channel.say message
88
+ end
@@ -0,0 +1,7 @@
1
+ require "ci/notify/version"
2
+
3
+ module Ci
4
+ module Notify
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Ci
2
+ module Notify
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci-notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Viehweger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shout-bot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: string-irc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: With the new Jenkinsfile-approach, I wanted a small script to send notifications
70
+ to IRC. Since most of the information comes from env-vars supplied by Jenkins, this
71
+ is a very generic script. Packaging this a gem enables proper dependency management.
72
+ email:
73
+ - kronn@kronn.de
74
+ executables:
75
+ - ci-notify
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".ruby-gemset"
81
+ - ".ruby-version"
82
+ - Gemfile
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - ci-notify.gemspec
88
+ - exe/ci-notify
89
+ - lib/ci/notify.rb
90
+ - lib/ci/notify/version.rb
91
+ homepage: https://git.lanpartei.de/kronn/ci-notify
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.4
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Send a short notification from Jenkins to IRC
114
+ test_files: []