uniq-ci-reporter 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ff886cb567c48864019b0b2f6300df18f9a40c4
4
+ data.tar.gz: c702c448dc920f39826d721b1e6a30f7374b1679
5
+ SHA512:
6
+ metadata.gz: b74f75f41c2612efb0cd4e8d8610fb363096b92f88055396b97eb17ada4d875e9e596822fec1aa6ccbfb29eb00cc7070fec24006a12dda5a6e117f914caeea56
7
+ data.tar.gz: 9002b3425c3252e162fce48f5916daa3fbb02bf0d388d4d5a92f00d105d3980dff3b4012133618f3c198eeddd0eb6603399470c22783b38ddbba37b27851be1c
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Kasatenko
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.
@@ -0,0 +1,29 @@
1
+ # .
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem '.'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install .
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/./fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,111 @@
1
+ #!/bin/bash
2
+
3
+ ###############################################################################
4
+ #
5
+ # ./hipchat_room_message
6
+ #
7
+ # A script for sending a system message to a room.
8
+ #
9
+ # Docs: http://github.com/hipchat/hipchat-cli
10
+ #
11
+ # Usage:
12
+ # cat message.txt | ./hipchat_room_message -t <token> -r 1234 -f "System"
13
+ # echo -e "New\nline" | ./hipchat_room_message -t <token> -r 1234 -f "System"
14
+ #
15
+ ###############################################################################
16
+
17
+ # exit on failure
18
+ set -e
19
+
20
+ usage() {
21
+ cat << EOF
22
+ Usage: $0 -t <token> -r <room id> -f <from name>
23
+
24
+ This script will read from stdin and send the contents to the given room as
25
+ a system message.
26
+
27
+ OPTIONS:
28
+ -h Show this message
29
+ -t <token> API token
30
+ -r <room id> Room ID
31
+ -f <from name> From name
32
+ -c <color> Message color (yellow, red, green, purple or random - default: yellow)
33
+ -m <format> Message format (html or text - default: html)
34
+ -i <input> Optional: Input to send to room (default: stdin)
35
+ -l <level> Nagios message level (critical, warning, unknown, ok, down, up). Will override color.
36
+ -n Trigger notification for people in the room
37
+ -o API host (api.hipchat.com)
38
+ EOF
39
+ }
40
+
41
+ # Include hipchat defaults if available
42
+ test -f /etc/hipchat && . /etc/hipchat
43
+
44
+ TOKEN=${HIPCHAT_TOKEN:-}
45
+ ROOM_ID=${HIPCHAT_ROOM_ID:-}
46
+ FROM=${HIPCHAT_FROM:-}
47
+ COLOR=${HIPCHAT_COLOR:-}
48
+ FORMAT=${HIPCHAT_FORMAT:-html}
49
+ MESSAGE=${HIPCHAT_MESSAGE:-html}
50
+ NOTIFY=${HIPCHAT_NOTIFY:-0}
51
+ HOST=${HIPCHAT_HOST:-api.hipchat.com}
52
+ LEVEL=${HIPCHAT_LEVEL:-}
53
+ while getopts “ht:r:f:c:m:o:i:l:n” OPTION; do
54
+ case $OPTION in
55
+ h) usage; exit 1;;
56
+ t) TOKEN=$OPTARG;;
57
+ r) ROOM_ID=$OPTARG;;
58
+ f) FROM=$OPTARG;;
59
+ c) COLOR=$OPTARG;;
60
+ m) FORMAT=$OPTARG;;
61
+ n) NOTIFY=1;;
62
+ i) INPUT=$OPTARG;;
63
+ l) LEVEL=$OPTARG;;
64
+ o) HOST=$OPTARG;;
65
+ [?]) usage; exit;;
66
+ esac
67
+ done
68
+
69
+ # check for required args
70
+ if [[ -z $TOKEN ]] || [[ -z $ROOM_ID ]] || [[ -z $FROM ]]; then
71
+ usage
72
+ exit 1
73
+ fi
74
+
75
+ # nagios levels
76
+ if [ ! -z "$LEVEL" ]; then
77
+ if [[ $LEVEL == 'CRITICAL' ]] || [[ $LEVEL == 'critical' ]]; then
78
+ COLOR="red";
79
+ elif [[ $LEVEL == 'WARNING' ]] || [[ $LEVEL == 'warning' ]]; then
80
+ COLOR="yellow";
81
+ elif [[ $LEVEL == 'UNKNOWN' ]] || [[ $LEVEL == 'unknown' ]]; then
82
+ COLOR="gray";
83
+ elif [[ $LEVEL == 'OK' ]] || [[ $LEVEL == 'ok' ]]; then
84
+ COLOR="green";
85
+ elif [[ $LEVEL == 'DOWN' ]] || [[ $LEVEL == 'down' ]]; then
86
+ COLOR="red";
87
+ elif [[ $LEVEL == 'UP' ]] || [[ $LEVEL == 'up' ]]; then
88
+ COLOR="green";
89
+ fi
90
+ fi
91
+
92
+ if [ -z "$INPUT" ]; then
93
+ # read stdin
94
+ INPUT=$(cat)
95
+ fi
96
+
97
+ # replace newlines with XHTML <br>
98
+ if [ $FORMAT == 'html' ]; then
99
+ INPUT=$(echo -n "${INPUT}" | sed "s/$/\<br\>/")
100
+ fi
101
+
102
+ # replace bare URLs with real hyperlinks
103
+ INPUT=$(echo -n "${INPUT}" | perl -p -e "s/(?<!href=\"|href=')((?:https?|ftp|mailto)\:\/\/[^ \n]*)/\<a href=\"\1\"\>\1\<\/a>/g")
104
+
105
+ # urlencode with perl
106
+ INPUT=$(echo -n "${INPUT}" | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')
107
+
108
+ # do the curl
109
+ curl -sS \
110
+ -d "auth_token=$TOKEN&room_id=$ROOM_ID&from=$FROM&color=$COLOR&message_format=$FORMAT&message=$INPUT&notify=$NOTIFY" \
111
+ https://$HOST/v1/rooms/message
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'open3'
6
+ require 'yaml'
7
+
8
+ class Options
9
+ def initialize(args)
10
+ @args = args
11
+ end
12
+
13
+ def verb
14
+ @args[0]
15
+ end
16
+
17
+ def hipchat_token
18
+ ci_config["hipchat_token"]
19
+ end
20
+
21
+ def hipchat_room
22
+ ci_config["hipchat_room"]
23
+ end
24
+
25
+ def matchers
26
+ ci_config["matchers"]
27
+ end
28
+
29
+ def valid?
30
+ [ "fail", "success" ].include?(verb) && !ci_config.nil? &&
31
+ hipchat_token && hipchat_room && matchers
32
+ end
33
+
34
+ private
35
+
36
+ def ci_config
37
+ config_file_name = "./ci/config.yml"
38
+ if File.exists?(config_file_name)
39
+ @ci_config ||= YAML.load_file("./ci/config.yml")
40
+ else
41
+ nil
42
+ end
43
+ end
44
+ end
45
+
46
+ class Git
47
+ def initialize(matchers)
48
+ @matchers = matchers
49
+ end
50
+
51
+ def last_comitter_name
52
+ map_comitter_name `git log -1 "--pretty=format:%an"`
53
+ end
54
+
55
+ def last_commit_sha
56
+ `git log -1 "--pretty=format:%h"`
57
+ end
58
+
59
+ def last_commit_time
60
+ `git log -1 "--pretty=format:%ai"`
61
+ end
62
+
63
+ private
64
+
65
+ def map_comitter_name(name)
66
+ @matchers.each { |regex, value|
67
+ return value if regex.match(name)
68
+ }
69
+ return "Юзернейм"
70
+ end
71
+ end
72
+
73
+ class TalkingRamil
74
+ class << self
75
+
76
+ def announce(what, hero)
77
+ puts "Announcing #{what} for #{hero}"
78
+ send_ramil_request(what, hero: hero)
79
+ end
80
+
81
+ private
82
+
83
+ def send_ramil_request(verb, params={})
84
+ Net::HTTP.post_form(URI.parse("http://192.168.15.9:8080/build/#{verb}"), params)
85
+ end
86
+ end
87
+ end
88
+
89
+ class Hipchat
90
+ class << self
91
+ def announce(token, room, what, moment, hash, hero)
92
+ send("announce_#{what}", token, room, moment, hash, hero)
93
+ end
94
+
95
+ private
96
+
97
+ def announce_success(token, room, moment, hash, hero)
98
+ message = %Q|<b>#{hash} #{hero} @ #{moment}</b><br />Зелёный билд, дамы и господа!|
99
+ send_hipchat(token, room, "green", message)
100
+ end
101
+
102
+ def announce_fail(token, room, moment, hash, hero)
103
+ message = %Q|<b>#{hash} #{hero} @ #{moment}</b><br />Билд безнадёжно сломан!|
104
+ send_hipchat(token, room, "red", message)
105
+ end
106
+
107
+ def send_hipchat(token, room, color, text)
108
+ stdin, stdout_and_stderr, wait_thr = Open3.popen2e(File.expand_path("../hipchat_room_message", __FILE__),
109
+ "-t", token, "-f", "CI", "-c", color, "-r", room, "-n")
110
+ stdin.write(text)
111
+ stdin.close
112
+ stdout_and_stderr.close
113
+ end
114
+ end
115
+ end
116
+
117
+ opts = Options.new(ARGV)
118
+ unless opts.valid?
119
+ puts "usage: uniq-ci-report success|fail"
120
+ puts "\nci/config.yml must contain: 'hipchat_token', 'hipchat_room' and 'matchers' keys"
121
+ exit(-1)
122
+ end
123
+
124
+ git = Git.new(opts.matchers)
125
+ Hipchat.announce(opts.hipchat_token, opts.hipchat_room, opts.verb, git.last_commit_time, git.last_commit_sha, git.last_comitter_name)
126
+ TalkingRamil.announce(opts.verb, git.last_comitter_name)
127
+
128
+ case opts.verb
129
+ when "success"
130
+ exit(0)
131
+ when "fail"
132
+ exit(1)
133
+ else
134
+ raise "Unknown verb: #{opts.verb}"
135
+ end
136
+
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "uniq-ci-reporter"
7
+ spec.version = "0.2.2"
8
+ spec.authors = ["Ivan Kasatenko"]
9
+ spec.email = ["sky.31338@gmail.com"]
10
+ spec.summary = %q{UNIQ systems CI reporter}
11
+ spec.homepage = "http://uniq.systems/"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = [ 'uniq-ci-report', 'hipchat_room_message' ]
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = [ 'lib' ]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 0"
21
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uniq-ci-reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Kasatenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - sky.31338@gmail.com
44
+ executables:
45
+ - uniq-ci-report
46
+ - hipchat_room_message
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/hipchat_room_message
56
+ - bin/uniq-ci-report
57
+ - uniq-ci-reporter.gemspec
58
+ homepage: http://uniq.systems/
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: UNIQ systems CI reporter
82
+ test_files: []