project_monitor_stat 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fd0660a2bd38ea4903964262bb9689e1be59744
4
- data.tar.gz: 567a98a4eb0682134fd9ae75d05391acda3b618d
3
+ metadata.gz: 60cafe63acb23bdd72a7faf84396a3e04e4da2b0
4
+ data.tar.gz: 7763aaf8a523c96b6af81cc3dee9891437257b62
5
5
  SHA512:
6
- metadata.gz: afa731a9590eebef622b554da32d8aa76be9257fd9a4f5ab2c32d78aed4dc7973c824b87d3f1692f9bffadfb46ee91c5f8774464244b963eb4ca3f6031c7e97e
7
- data.tar.gz: 4b2998256587b6adbf4b57332303d1bb3f622ba6e515cb9ef755d4f7021f2e2eb80232baf4a69183a2d815535ea4ce32bd824c1e05d247bf7a76a4cd8f8e1ccc
6
+ metadata.gz: 5fd66e2ad6a8074952d9ff5252f8a3e3055b4c96fd0bf22016e121f7f07a20d7f26932f5cb195072abf012e1f68d542fc699f2c847dba6ca14ae0750c88c78ac
7
+ data.tar.gz: a804ad1ebddfb9ac628688f3591e77a85ff1db3e12d79c10d660a2deed056ef163e1173fa8132a48a87bd3819dae1415003138c72d8a544d04758a333a391331
@@ -6,34 +6,46 @@ module ProjectMonitorStat
6
6
  def self.parse_options(argv: raise)
7
7
  tag = argv[0] || raise(ArgumentError.new('You must provide a tag'))
8
8
  instance = new
9
+ instance.tag = tag
9
10
  instance.base_url = 'http://pulse.pivotallabs.com/projects.json'
11
+ instance.idle_seconds = 600
10
12
 
11
13
  opt_parser = OptionParser.new do |opts|
12
14
  opts.banner = "Usage: #{File.basename(__FILE__)} tag [options]"
13
15
 
14
16
  opts.on('-sCOMMAND', '--success COMMAND',
15
- 'Success command') do |s|
17
+ 'Command after success') do |s|
16
18
  instance.success_cmd = s
17
19
  end
18
20
 
21
+ opts.on('-iCOMMAND', '--idle COMMAND',
22
+ 'Command when idle after success') do |i|
23
+ instance.idle_cmd = i
24
+ end
25
+
26
+ opts.on('--idle-seconds SECONDS',
27
+ 'Seconds after which a success build is idle') do |is|
28
+ instance.idle_seconds = is.to_i
29
+ end
30
+
19
31
  opts.on('-bCOMMAND', '--building COMMAND',
20
- 'Building command') do |b|
32
+ 'Command when building') do |b|
21
33
  instance.building_cmd = b
22
34
  end
23
35
 
24
36
  opts.on('-fCOMMAND', '--fail COMMAND',
25
- 'Fail command') do |s|
37
+ 'Command after fail') do |s|
26
38
  instance.fail_cmd = s
27
39
  end
28
40
 
29
41
  opts.on('-uURL', '--url URL',
30
- 'Your projectMonitor url ',
42
+ 'Custom project monitor url ',
31
43
  " Default: #{instance.base_url}") do |u|
32
44
 
33
45
  instance.base_url = u
34
46
  end
35
47
 
36
- opts.on('-c', '--cookies []',
48
+ opts.on('-cCOOKIE', '--cookies COOKIE',
37
49
  'Your cookie string',
38
50
  ' Get this from your browser cookie inspector') do |c|
39
51
  instance.cookie = c
@@ -55,16 +67,12 @@ module ProjectMonitorStat
55
67
  instance
56
68
  end
57
69
 
58
- attr_accessor :base_url, :success_cmd, :building_cmd, :fail_cmd, :cookie
70
+ attr_accessor :tag, :base_url, :success_cmd, :building_cmd, :fail_cmd, :idle_cmd, :idle_seconds, :cookie
59
71
 
60
72
  def url
61
73
  uri = URI(base_url)
62
74
  uri.query = "tags=#{tag}"
63
75
  uri
64
76
  end
65
-
66
- private
67
-
68
- attr_reader :tag
69
77
  end
70
78
  end
@@ -1,5 +1,5 @@
1
- require 'net/http'
2
1
  require 'json'
2
+ require 'time'
3
3
 
4
4
  module ProjectMonitorStat
5
5
  class Fetcher
@@ -13,25 +13,42 @@ module ProjectMonitorStat
13
13
  begin
14
14
  projects = JSON.parse(json)
15
15
  rescue JSON::ParserError
16
- return :error
16
+ return :error_invalid_json
17
+ end
18
+
19
+ if projects.empty?
20
+ return :error_no_projects
17
21
  end
18
22
 
19
23
  begin
20
- success_results = projects.map do |project|
24
+ sucesss_results = projects.map do |project|
21
25
  project.fetch('build').fetch('status') == 'success'
22
26
  end
23
27
  building_results = projects.map do |project|
24
28
  project.fetch('build').fetch('building')
25
29
  end
26
- rescue JSON::ParserError, TypeError
27
- return :error
30
+ rescue JSON::ParserError, KeyError, TypeError
31
+ return :error_invalid_project_attributes
28
32
  end
29
33
 
30
- if success_results.all?
34
+ if sucesss_results.all?
31
35
  if building_results.any?
32
36
  :building
33
37
  else
34
- :success
38
+ if config.idle_seconds
39
+ recent_results = projects.map do |project|
40
+ published_at = Time.parse(project.fetch('build').fetch('published_at'))
41
+ published_at > (Time.now - config.idle_seconds)
42
+ end
43
+
44
+ if recent_results.any?
45
+ :success
46
+ else
47
+ :idle
48
+ end
49
+ else
50
+ :success
51
+ end
35
52
  end
36
53
  else
37
54
  :fail
@@ -25,7 +25,13 @@ module ProjectMonitorStat
25
25
  else
26
26
  Util.puts result
27
27
  end
28
- when :error
28
+ when :idle
29
+ if config.idle_cmd
30
+ Util.system(config.idle_cmd)
31
+ else
32
+ Util.puts result
33
+ end
34
+ when :error_invalid_json, :error_no_projects, :error_invalid_project_attributes
29
35
  Util.puts result
30
36
  else
31
37
  raise 'Unknown Error'
@@ -1,3 +1,6 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
1
4
  module ProjectMonitorStat
2
5
  class Util
3
6
  def self.puts(*args)
@@ -1,5 +1,5 @@
1
1
  module ProjectMonitorStat
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
 
4
4
  autoload :Config, 'project_monitor_stat/config'
5
5
  autoload :Fetcher, 'project_monitor_stat/fetcher'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: project_monitor_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Young
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra-contrib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
41
55
  description: A command line until to fetch your build status from project monitor
42
56
  and return the response as your exit code
43
57
  email: micah@young.io