housefire 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 dbgrandi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.markdown ADDED
@@ -0,0 +1,26 @@
1
+ Housefire
2
+ =========
3
+
4
+ I work with a bunch of guys who like to stomp on lighthouse tickets all the
5
+ live long day. We needed a way to keep track of who was working on what
6
+ ticket. We like campfire.
7
+
8
+ Most importantly, housefire just seemed like an awesome name for a gem.
9
+
10
+ Create a ~/.housefire file with some info about your LH account and your
11
+ campfire account.
12
+
13
+ #required config:
14
+ lhuser: <your lh login>
15
+ lhpass: <your lh password>
16
+ account: <your campfire domain>
17
+ token: <your campfire auth token>
18
+ room: <the campfire room to talk to>
19
+ # optional config:
20
+ ssl: <use ssl for campfire, defaults to false>
21
+ lhcache: <where to put the lighthouse event cache, defaults to ~/.housefire.tmp>
22
+
23
+ Then, start up housefire and just leave it running. It currently checks LH
24
+ every 60 seconds and keeps a local cache of what it has previously seen to
25
+ keep the spam down on campfire.
26
+
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "housefire"
8
+ gem.summary = %Q{Send ticket notifications to Campfire}
9
+ gem.description = %Q{Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view}
10
+ gem.email = "dave@wegoto12.com"
11
+ gem.homepage = "http://github.com/dbgrandi/housefire"
12
+ gem.authors = ["dbgrandi"]
13
+ gem.files = FileList['[A-Z]*',
14
+ 'lib/**/*.rb',
15
+ 'bin/housefire']
16
+ gem.add_development_dependency "shoulda", ">= 0"
17
+ gem.add_dependency('broach', '>= 0.1.4')
18
+ gem.add_dependency('nokogiri' ,'>= 0')
19
+ gem.add_dependency('sanitize' ,'>= 0')
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+ task :test => :check_dependencies
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "Housefire #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/housefire ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = housefire(1)
4
+ #
5
+ # == USAGE
6
+ # housefire
7
+ # housefire -c path-to-housefire.yml
8
+ #
9
+ # == INSTALL
10
+ # RubyGem:
11
+ # gem install housefire
12
+ #
13
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
14
+ require 'housefire'
15
+ Housefire.new(*ARGV).run
data/lib/housefire.rb ADDED
@@ -0,0 +1,98 @@
1
+ #
2
+ # Lighthouse --> Campfire = housefire
3
+ #
4
+ # dbgrandi.in.2010
5
+ #
6
+ require 'rubygems'
7
+ require 'nokogiri'
8
+ require 'sanitize'
9
+ require 'broach'
10
+
11
+ class Housefire
12
+
13
+ def initialize(*args)
14
+ #
15
+ # required config:
16
+ # lhuser: <your lh login>
17
+ # lhpass: <your lh password>
18
+ # account: <your campfire domain>
19
+ # token: <your campfire auth token>
20
+ # room: <the campfire room to talk to>
21
+ #
22
+ # optional config:
23
+ # ssl: <use ssl for campfire?>
24
+ # lhcache: <where to put the lighthouse event cache>
25
+ #
26
+ @conf = YAML.load(File.read(File.expand_path("~/.housefire")))
27
+ @conf['ssl'] ||= false
28
+ @conf['lhcache'] ||= File.expand_path("~/.housefire.tmp")
29
+
30
+ Broach.settings = {
31
+ 'account' => @conf['account'],
32
+ 'token' => @conf['token'],
33
+ 'use_ssl' => @conf['ssl'],
34
+ }
35
+ @room = Broach::Room.find_by_name(@conf['room'])
36
+ end
37
+
38
+ def run
39
+ while true
40
+ poll_lighthouse
41
+ sleep 60
42
+ end
43
+ end
44
+
45
+ def poll_lighthouse
46
+ puts "running..."
47
+ # check for a cached copy of the last feed pull
48
+ recent_items = load_db(@conf['lhcache']) || {}
49
+
50
+ doc = Nokogiri::XML(`curl -su "#{@conf['lhuser']}":#{@conf['lhpass']} https://#{@conf['lhdomain']}.lighthouseapp.com/events.atom`)
51
+
52
+ # parse out events into things we recognize (changeset, ticket, etc.)
53
+ doc.css("entry").each do |entry|
54
+ id = entry.css("id")[0].content.split("Event/")[1].to_i
55
+
56
+ # DON'T notify the same event more than once
57
+ if !recent_items.key?(id)
58
+ e = {}
59
+ e[:id] = id
60
+
61
+ # DON'T notify changesets, github already does that
62
+ title = entry.css("title")[0].content
63
+ if !title.include?("[Changeset] ")
64
+ e[:title] = title
65
+ e[:content] = Sanitize.clean(entry.css("content")[0].content)
66
+ e[:author] = entry.css("author name")[0].content
67
+ e[:link] = entry.css("link")[0].attributes["href"].content
68
+ e[:date] = entry.css("published")[0].content
69
+
70
+ message = "#{e[:author]}: #{e[:title]} -- #{e[:content]}".gsub(/[^[:print:]]/, '').gsub(/&amp;/,'&')
71
+ puts message
72
+ puts "\n\n\n"
73
+ @room.speak(message)
74
+ end
75
+ # recent_items = recent_items.sort.last 10
76
+ recent_items[id] = e
77
+ save_db(@conf['lhcache'], recent_items)
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ def save_db(file, object)
84
+ f = File.open(file, "w")
85
+ f.write Marshal.dump(object)
86
+ f.close
87
+ true
88
+ end
89
+
90
+ def load_db(file)
91
+ if File.exists?(file)
92
+ if marshalled_data = File.read(file)
93
+ Marshal.load(marshalled_data)
94
+ end
95
+ end
96
+ end
97
+
98
+ end #class
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'housefire'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ # Don't really have an idea how to test this.
4
+ class TestHousefire < Test::Unit::TestCase
5
+ should "probably write better tests" do
6
+ assert_equal true, false
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: housefire
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - dbgrandi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-26 00:00:00 +01:00
18
+ default_executable: housefire
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: broach
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ - 1
42
+ - 4
43
+ version: 0.1.4
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: nokogiri
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :runtime
57
+ version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ name: sanitize
60
+ prerelease: false
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ type: :runtime
69
+ version_requirements: *id004
70
+ description: Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view
71
+ email: dave@wegoto12.com
72
+ executables:
73
+ - housefire
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - LICENSE
78
+ - README.markdown
79
+ files:
80
+ - LICENSE
81
+ - README.markdown
82
+ - Rakefile
83
+ - VERSION
84
+ - bin/housefire
85
+ - lib/housefire.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/dbgrandi/housefire
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --charset=UTF-8
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.3.6
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Send ticket notifications to Campfire
116
+ test_files:
117
+ - test/helper.rb
118
+ - test/test_housefire.rb