tddium_status 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # TddiumStatus
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tddium_status'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tddium_status
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/bin/tddium_status ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..' , 'lib'))
4
+
5
+ require 'tddium_status'
6
+ require 'rainbow'
7
+
8
+ def show
9
+ if TddiumStatus.feeds.empty?
10
+ puts "No feeds have been added to your configuration".inverse
11
+ puts ""
12
+ help
13
+ exit
14
+ end
15
+
16
+ projects = TddiumStatus.projects.each do |project|
17
+ line = "#{project.status} #{project.name}"
18
+ if project.passing?
19
+ line = line.foreground(:green)
20
+ else
21
+ line = line.foreground(:red)
22
+ end
23
+
24
+ line = line.inverse if project.building?
25
+
26
+ puts line
27
+ end
28
+ end
29
+
30
+ def settings
31
+ TddiumStatus.feeds.each do |feed|
32
+ if feed.patterns
33
+ feed.patterns.each do |pattern|
34
+ puts "#{feed.url} #{pattern.inspect}"
35
+ end
36
+ else
37
+ puts feed.url
38
+ end
39
+ end
40
+ end
41
+
42
+ def add(url, pattern)
43
+ if url.nil?
44
+ puts "Usage: tddium_status add URL REGEX"
45
+ puts ""
46
+ puts "Where:"
47
+ puts " URL Is the url of the tddium cc feed"
48
+ puts " REGEX Is an optional regular expression used to match projects"
49
+ exit
50
+ end
51
+
52
+ require 'uri'
53
+ url = URI.parse(url)
54
+ feed = TddiumStatus.feeds.find { |f| f.url == url }
55
+ feed ||= TddiumStatus::Feed.new(url)
56
+
57
+ if pattern
58
+ regex = eval(pattern)
59
+ raise "#{pattern.inspect} is not a valid regex" unless regex.is_a?(Regexp)
60
+ feed.add_pattern(regex)
61
+ end
62
+
63
+ feed.save
64
+
65
+ settings
66
+ end
67
+
68
+ def help
69
+ puts "Usage: tddium_status [COMMAND] OTHER_ARGS"
70
+ puts ""
71
+ puts "Commands:"
72
+ puts " show Show the current status if your builds"
73
+ puts " settings Show the currently configured feeds"
74
+ puts " add Add a new feed"
75
+ end
76
+
77
+ case ARGV[0]
78
+ when nil, 'show'
79
+ show
80
+ when 'settings'
81
+ settings
82
+ when 'add'
83
+ add(ARGV[1], ARGV[2])
84
+ else
85
+ help
86
+ end
@@ -0,0 +1,31 @@
1
+ require 'yaml/store'
2
+
3
+ module TddiumStatus
4
+ class Configuration
5
+ def initialize(path = self.class.default_path)
6
+ @store = YAML::Store.new(path)
7
+ end
8
+
9
+ def feeds
10
+ @feeds ||= @store.transaction do
11
+ @store[:feeds] ||= []
12
+ end
13
+ end
14
+
15
+ def feeds=(feeds)
16
+ @store.transaction do
17
+ @store[:feeds] = feeds || []
18
+ end
19
+ end
20
+
21
+ def save_feed(feed)
22
+ feeds = self.feeds
23
+ feeds << feed unless feeds.include?(feed)
24
+ self.feeds = feeds
25
+ end
26
+
27
+ def self.default_path
28
+ File.join(Dir.home, '.tddium_status.yml')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,82 @@
1
+ require 'uri'
2
+ require 'open-uri'
3
+ require 'rexml/document'
4
+
5
+ module TddiumStatus
6
+ class Feed
7
+ attr_accessor :patterns
8
+
9
+ def initialize(url, patterns = nil)
10
+ @url_string = URI.parse(url.to_s).to_s
11
+ @patterns = patterns
12
+ @updated_at = nil
13
+ end
14
+
15
+ def to_yaml_properties
16
+ [:@url_string, :@patterns, :@updated_at, :@projects]
17
+ end
18
+
19
+ def url
20
+ @url = URI.parse(@url_string) if @url_string.is_a?(String)
21
+ end
22
+
23
+ def add_pattern(pattern)
24
+ return if @patterns && @patterns.include?(pattern)
25
+ @patterns ||= []
26
+ @patterns << pattern
27
+ expire
28
+ end
29
+
30
+ def needs_refresh?
31
+ (@updated_at.to_i + TddiumStatus.refresh_every) < Time.now.to_i
32
+ end
33
+
34
+ def document
35
+ @document = nil if needs_refresh?
36
+
37
+ @document ||= REXML::Document.new(url.read)
38
+ end
39
+
40
+ def projects
41
+ @projects = nil if needs_refresh?
42
+
43
+ return @projects if @projects
44
+
45
+ @projects = document.root.elements.map do |project_element|
46
+ project_name = project_element.attributes['name']
47
+ project_url = project_element.attributes['webUrl']
48
+ project_options = {
49
+ :status => project_element.attributes['lastBuildStatus'],
50
+ :build_time => project_element.attributes['lastBuildTime'],
51
+ :activity => project_element.attributes['activity']
52
+ }
53
+
54
+ project = Project.new(project_name, project_url, project_options)
55
+
56
+ matches_pattern?(project) ? project : nil
57
+ end.compact
58
+
59
+ @updated_at = Time.now
60
+ save
61
+
62
+ @projects
63
+ end
64
+
65
+ def matches_pattern?(project)
66
+ return true if patterns.nil?
67
+
68
+ patterns.any? do |pattern|
69
+ project.name =~ pattern
70
+ end
71
+ end
72
+
73
+ def expire
74
+ @updated_at = nil
75
+ end
76
+
77
+ def save
78
+ TddiumStatus.configuration.save_feed(self)
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,33 @@
1
+ require 'date'
2
+
3
+ module TddiumStatus
4
+ class Project
5
+ include Comparable
6
+ attr_reader :name, :url, :status, :build_time, :activity
7
+
8
+ def initialize(name, url, options = {})
9
+ @name = name
10
+ @url = url
11
+ @status = options[:status]
12
+ @activity = options[:activity]
13
+ @build_time = options[:build_time]
14
+ @build_time = DateTime.parse(@build_time).to_time if @build_time.is_a?(String)
15
+ end
16
+
17
+ def to_yaml_properties
18
+ [:@name, :@url, :@status, :@build_time, :@activity]
19
+ end
20
+
21
+ def passing?
22
+ status.nil? || status.strip == '' || status == 'Success'
23
+ end
24
+
25
+ def building?
26
+ activity == 'Building'
27
+ end
28
+
29
+ def <=>(other)
30
+ other.build_time.to_i <=> build_time.to_i
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module TddiumStatus
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'tddium_status/version'
2
+ require 'tddium_status/configuration'
3
+ require 'tddium_status/feed'
4
+ require 'tddium_status/project'
5
+
6
+ module TddiumStatus
7
+ CONFIGURATION = Configuration.new
8
+ MAX_AGE = 60 * 60 * 24 * 7 # a week in seconds
9
+
10
+ def self.configuration
11
+ CONFIGURATION
12
+ end
13
+
14
+ def self.feeds
15
+ configuration.feeds
16
+ end
17
+
18
+ def self.projects(max_age = MAX_AGE)
19
+ projects = feeds.map(&:projects).flatten
20
+ projects = projects.select do |project|
21
+ project.building? || (project.build_time.to_i > (Time.now.to_i - max_age))
22
+ end
23
+ projects.sort
24
+ end
25
+
26
+ def self.refresh_every
27
+ 60
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tddium_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mick Staugaard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A library (and CLI) for getting the status of your tddium builds
31
+ email:
32
+ - mick@staugaard.com
33
+ executables:
34
+ - tddium_status
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - bin/tddium_status
39
+ - lib/tddium_status/configuration.rb
40
+ - lib/tddium_status/feed.rb
41
+ - lib/tddium_status/project.rb
42
+ - lib/tddium_status/version.rb
43
+ - lib/tddium_status.rb
44
+ - README.md
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Easy access to the status of your tddium builds
69
+ test_files: []