project_monitor_stat 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12fce13b0a99d317cb5123603632ac4734f21179
4
+ data.tar.gz: 56949f29051251f71e370cbc990d21ed05bc1f8c
5
+ SHA512:
6
+ metadata.gz: 0f2a51290bac000d1001a9da221d7a3120d573210b7e452e9a313b92414bfc0306f5d85b6b9303f8224ef2bca9e46c05958b0f1c2286cdf3366617b7d388a7d0
7
+ data.tar.gz: 98172f1c35774215f7c074e511a6236b46d907ff12a91243ca517648b4eddf559aa28a058d9b081f305272f24ea026e0a1bf253e8914af2504854dafde74d94f
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Micah Young
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # project_monitor_stat
2
+ A simple utility to fetch the overall build status of Project Monitor projects
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require 'project_monitor_stat'
3
+
4
+ config = ProjectMonitorStat::Config.parse_options(argv: ARGV)
5
+ result = ProjectMonitorStat::Fetcher.new(url: config.url).fetch
6
+
7
+ case result
8
+ when :success
9
+ if config.success_cmd
10
+ system(config.success_cmd)
11
+ else
12
+ exit(0)
13
+ end
14
+ when :building
15
+ if config.building_cmd
16
+ system(config.building_cmd)
17
+ else
18
+ exit(0)
19
+ end
20
+ when :fail
21
+ if config.fail_cmd
22
+ system(config.fail_cmd)
23
+ else
24
+ exit(1)
25
+ end
26
+ when :error
27
+ raise 'Error'
28
+ else
29
+ raise 'Unknown Error'
30
+ end
@@ -0,0 +1,6 @@
1
+ module ProjectMonitorStat
2
+ VERSION = '0.0.2'
3
+
4
+ autoload :Config, 'project_monitor_stat/config'
5
+ autoload :Fetcher, 'project_monitor_stat/fetcher'
6
+ end
@@ -0,0 +1,81 @@
1
+ require 'uri'
2
+ require 'optparse'
3
+
4
+ module ProjectMonitorStat
5
+ class Config
6
+ def self.parse_options(argv: raise)
7
+ tag = argv[0] || raise(ArgumentError.new('You must provide a tag'))
8
+ url = 'http://pulse.pivotallabs.com/projects.json'
9
+ session_id = nil
10
+ success_cmd = nil
11
+ building_cmd = nil
12
+ fail_cmd = nil
13
+
14
+ opt_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{File.basename(__FILE__)} tag [options]"
16
+
17
+ opts.on('-sCOMMAND', '--success COMMAND',
18
+ 'Success command') do |s|
19
+ success_cmd = s
20
+ end
21
+
22
+ opts.on('-bCOMMAND', '--building COMMAND',
23
+ 'Building command') do |b|
24
+ building_cmd = b
25
+ end
26
+
27
+ opts.on('-fCOMMAND', '--fail COMMAND',
28
+ 'Fail command') do |s|
29
+ fail_cmd = s
30
+ end
31
+
32
+ opts.on('-u', '--url',
33
+ 'Your projectMonitor url ',
34
+ " Default: #{url}") do |u|
35
+ url = u
36
+ end
37
+
38
+ opts.on('-i', '--session_id []',
39
+ 'Your _projectmonitor_session cookie if outside a whitelisted IP ',
40
+ ' Get this from your browser cookie inspector') do |i|
41
+ session_id = i
42
+ end
43
+
44
+ opts.on_tail('-h', '--help', 'Show this message') do
45
+ puts opts
46
+ exit
47
+ end
48
+
49
+ opts.on_tail('--version', 'Show version') do
50
+ puts VERSION
51
+ exit
52
+ end
53
+ end
54
+
55
+ opt_parser.parse!(argv)
56
+
57
+ new(url: url, tag: tag, success_cmd: success_cmd, building_cmd: building_cmd, fail_cmd: fail_cmd, session_id: session_id)
58
+ end
59
+
60
+ attr_reader :success_cmd, :building_cmd, :fail_cmd, :session_id
61
+
62
+ def initialize(url: raise, tag: raise, success_cmd: raise, building_cmd: raise, fail_cmd: raise, session_id: nil)
63
+ @base_url = url
64
+ @tag = tag
65
+ @success_cmd = success_cmd
66
+ @building_cmd = building_cmd
67
+ @fail_cmd = fail_cmd
68
+ @session_id = session_id
69
+ end
70
+
71
+ def url
72
+ uri = URI(base_url)
73
+ uri.query = "tags=#{tag}"
74
+ uri
75
+ end
76
+
77
+ private
78
+
79
+ attr_reader :base_url, :tag
80
+ end
81
+ end
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module ProjectMonitorStat
5
+ class Fetcher
6
+ def initialize(url: raise, session_id: nil)
7
+ @uri = URI(url)
8
+ end
9
+
10
+ def fetch
11
+ request = Net::HTTP::Get.new(uri)
12
+
13
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
14
+ http.request(request)
15
+ end
16
+
17
+ begin
18
+ projects = JSON.parse(response.body)
19
+ rescue JSON::ParserError
20
+ return :error
21
+ end
22
+
23
+ begin
24
+ success_results = projects.map do |project|
25
+ project.fetch('build').fetch('status') == 'success'
26
+ end
27
+ building_results = projects.map do |project|
28
+ project.fetch('build').fetch('building')
29
+ end
30
+ rescue JSON::ParserError, TypeError
31
+ return :error
32
+ end
33
+
34
+ if success_results.all?
35
+ if building_results.any?
36
+ :building
37
+ else
38
+ :success
39
+ end
40
+ else
41
+ :fail
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :uri
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: project_monitor_stat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Micah Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: A command line until to fetch your build status from project monitor
42
+ and return the response as your exit code
43
+ email: micah@young.io
44
+ executables:
45
+ - project_monitor_stat
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - README.md
51
+ - bin/project_monitor_stat
52
+ - lib/project_monitor_stat.rb
53
+ - lib/project_monitor_stat/config.rb
54
+ - lib/project_monitor_stat/fetcher.rb
55
+ homepage: http://rubygems.org/gems/project_monitor_stat
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Ping Project Monitor for your build status
79
+ test_files: []