githubissueswatcher 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in githubissueswatcher.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ ## Github Issues Watcher
2
+
3
+ Github issues watcher is a simple and useful gem that help you to constantly monitor your issues for both public and private repos.
4
+
5
+ It is a fork of the excellent [githubwatcher](https://github.com/DAddYE/githubwatcher)
6
+
7
+ It uses [foreverb](https://github.com/DAddYE/foreverb) to demonize the process.
8
+
9
+ A [demonstration video is here](http://www.daddye.it/post/7275490125/github-growl)
10
+
11
+ ## Prerequisites
12
+
13
+ You need to have **growlnotify** installed. To do that you can install it through official [site](http://growl.info) or
14
+ if you have the awesome [brew](https://github.com/mxcl/homebrew) simply with:
15
+
16
+ ``` sh
17
+ $ brew install growlnotify
18
+ ```
19
+
20
+ ## Installation ##
21
+
22
+ You may need to manually stop the process and run ```githubissueswatcher start``` if you encounter errors.
23
+
24
+ ``` sh
25
+ $ sudo gem install githubissueswatcher
26
+ $ githubissueswatcher start
27
+ $ githubissueswatcher config
28
+ $ githubissueswatcher repos
29
+
30
+ $ githubissueswatcher stop
31
+ ```
32
+
33
+ ## Configuration ##
34
+
35
+
36
+ You need to enter in your username and password for Github in ```~/.githubissueswatcher/config.yaml```
37
+ It's in plaintext so make sure this folder is secure.
38
+
39
+ You need to tell to our program which repositories you want to watch, to do that simply edit ```~/.githubissueswatcher/repos.yaml```
40
+ with your favorite editor.
41
+
42
+ Should look like this (if you have ran ```githubissueswatcher start```)
43
+
44
+ We provide a `config` command to easily edit it.
45
+
46
+ ``` sh
47
+ $ githubissueswatcher config
48
+ ```
49
+
50
+ It will open in texmate or vim this:
51
+
52
+ ``` yaml
53
+ ---
54
+ - daddye/foreverb/mentioned-assigned
55
+ - padrino/padrino-framework/all
56
+ ```
57
+ The correct format is **username/repo/filters** where filters are separated by a '-'
58
+ Filters include *mentioned*,*assigned*,*created* and *all*.
59
+ Note: Issues where you are mentioned will be *sticky*
60
+ So if for example you want to watch issues in [sinatra](https://github.com/sinatra/sinatra) where you are mentioned or assigned, the result should look like:
61
+
62
+ ``` yaml
63
+ ---
64
+ - daddye/foreverb/mentioned-assigned
65
+ - padrino/padrino-framework/all
66
+ - sinatra/sinatra/mentioned-assigned
67
+ ```
68
+
69
+ If you want to watch **all** issues of a repository of a given user you simply provide **/all** so will look like:
70
+
71
+ ``` yaml
72
+ ---
73
+ - daddye/foreverb/mentioned-assigned
74
+ - padrino/padrino-framework/all
75
+ - sinatra/sinatra/all
76
+ ```
77
+
78
+ Restart the deamon
79
+
80
+ ``` sh
81
+ $ githubissueswatcher restart
82
+ ```
83
+
84
+ ## Working with Ruby Forever
85
+
86
+ ``` sh
87
+ $ foreverb list
88
+ PID RSS CPU CMD
89
+ 12494 27132 0.2 Forever: /usr/bin/githubissueswatcher
90
+
91
+ $ foreverb stop github
92
+ Do you want really stop Forever: /usr/bin/githubissueswatcher with pid 12494? y
93
+ Killing process Forever: /usr/bin/githubissueswatcher with pid 12494...
94
+ ```
95
+
96
+ Your are done!
97
+
98
+ ## Hacks
99
+
100
+ In some env you use `sudo gem install`, so in this case the first time you launch the app use `sudo`,
101
+ in this way will be generated the `Gemfile.lock`, in future you will be able to run it without `sudo`.
102
+
103
+ ## Author ##
104
+
105
+ Peter Gabbay (Artcentric)
106
+
107
+ Original Github Issues:
108
+
109
+ DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye)
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems' unless defined?(Gem)
2
+ require 'bundler/gem_tasks'
3
+
4
+ %w(install release).each do |task|
5
+ Rake::Task[task].enhance do
6
+ sh "rm -rf pkg"
7
+ end
8
+ end
9
+
10
+ desc "Bump version on github"
11
+ task :bump do
12
+ puts "Nothing to commit (working directory clean)" and return if `git status -s`.strip == ""
13
+ if `git status -s`.strip == ""
14
+ puts "\e[31mNothing to commit (working directory clean)\e[0m"
15
+ else
16
+ version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
17
+ sh "git add .; git commit -a -m \"Bump to version #{version}\""
18
+ end
19
+ end
20
+
21
+ task :release => :bump
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby
2
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'rubygems' unless defined?(Gem)
5
+ require 'bundler/setup'
6
+ require 'forever'
7
+ require 'githubissueswatcher'
8
+
9
+ while ARGV.size > 0
10
+ case arg = ARGV.shift
11
+ when "config"
12
+ editor = `which mate`.chomp! || `which vim`.chomp!
13
+ puts "Im unable to find an editor, open manually ~/.githubissueswatcher/config.yaml" and exit unless editor
14
+ system editor, File.expand_path('~/.githubissueswatcher/config.yaml') and exit
15
+ when "repos"
16
+ editor = `which mate`.chomp! || `which vim`.chomp!
17
+ puts "Im unable to find an editor, open manually ~/.githubissueswatcher/repos.yaml" and exit unless editor
18
+ system editor, File.expand_path('~/.githubissueswatcher/repos.yaml') and exit
19
+ when "reset"
20
+ system "rm -rf ~/.githubissueswatcher"
21
+ end
22
+ end
23
+
24
+ Forever.run do
25
+ # Our working directory, here we store pids/logs and obviously our list of repo to watch
26
+ dir File.expand_path('~/.githubissueswatcher')
27
+
28
+ on_error do |e|
29
+ unless (@_errors ||= []).include?(e.message)
30
+ Githubissueswatcher.notify("Error!", e.message, false)
31
+ @_errors << e.message
32
+ end
33
+ end
34
+
35
+ on_ready do
36
+ Githubissueswatcher.setup
37
+ Githubissueswatcher.notify("GitHub Issues Watcher", "was started...", false)
38
+ end
39
+
40
+ on_exit do
41
+ Githubissueswatcher.notify("GitHub Issues Watcher", "was stopped...", false)
42
+ end
43
+
44
+ every 30.seconds do
45
+ Githubissueswatcher.run
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*- #
2
+
3
+
4
+ $:.push File.expand_path("../lib", __FILE__)
5
+ require "githubissueswatcher/version"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "githubissueswatcher"
9
+ s.version = Githubissueswatcher::VERSION
10
+ s.authors = ["Peter Gabbay", "Davide D'Agostino"]
11
+ s.email = ["peter@check2.com"]
12
+ s.homepage = "https://github.com/Artcentric/githubissueswatcher"
13
+ s.summary = "Github Issues Growl Watcher, watch any project issues and receive growl notification"
14
+ s.description = "Github Issues Growl Watcher, watch any project issues and receive growl notification based on whether you are mentioned, assigned or the creator."
15
+
16
+ s.rubyforge_project = "githubissueswatcher"
17
+
18
+ s.files = Dir["**/*"].reject { |f| File.directory?(f) || f == "Gemfile.lock" }
19
+ s.test_files = []
20
+ s.executables = %w[githubissueswatcher]
21
+ s.require_paths = %w[lib]
22
+ s.add_dependency 'httparty', '~>0.7.8'
23
+ s.add_dependency 'growl', '~>1.0.3'
24
+ s.add_dependency 'foreverb', '~>0.2.6'
25
+ end
data/images/icon.png ADDED
Binary file
@@ -0,0 +1,140 @@
1
+ require 'yaml' unless defined?(YAML)
2
+ require_relative "githubissueswatcher/version"
3
+ require "httparty"
4
+ require "growl"
5
+
6
+ YAML::ENGINE.yamler = "syck" if defined?(YAML::ENGINE)
7
+
8
+ module Githubissueswatcher
9
+ extend self
10
+ include HTTParty
11
+
12
+ CONFIG = File.expand_path("~/.githubissueswatcher/config.yaml")
13
+ WATCH = File.expand_path("~/.githubissueswatcher/repos.yaml")
14
+ DB = File.expand_path("~/.githubissueswatcher/db.yaml")
15
+
16
+ format :json
17
+
18
+ def setup
19
+ raise "You need to install growlnotify, use brew install growlnotify or install it from growl.info site" unless Growl.installed?
20
+ puts "Starting GitHub Issues Watcher..."
21
+ warn "If timeout occurs, your credentials may be wrong."
22
+
23
+ unless File.exist?(CONFIG)
24
+ Dir.mkdir(File.dirname(CONFIG)) unless File.exist?(File.dirname(CONFIG))
25
+ File.open(CONFIG, "w") { |f| f.write \
26
+ YAML.load("
27
+ api:
28
+ url: 'https://api.github.com'
29
+ version: 'v3'
30
+ user:
31
+ username:
32
+ password:
33
+ ").to_yaml }
34
+ end
35
+
36
+ unless File.exist?(WATCH)
37
+ warn "Add the repositories you're willing to monitor editing: ~/.githubissueswatcher/repos.yaml"
38
+ Dir.mkdir(File.dirname(WATCH)) unless File.exist?(File.dirname(WATCH))
39
+ File.open(WATCH, "w") { |f| f.write ["daddye/foreverb/mentioned-assigned", "padrino/padrino-framework/all"].to_yaml }
40
+ end
41
+
42
+ unless File.exist?(DB)
43
+ Dir.mkdir(File.dirname(DB)) unless File.exist?(File.dirname(DB))
44
+ File.open(DB, "w") { |f| f.write (Time.now - 86400).to_yaml }
45
+ end
46
+
47
+ @_watch = YAML.load_file(WATCH)
48
+ @_config = YAML.load_file(CONFIG)
49
+ @base_uri, @api_version = @_config['api']['url'], @_config['api']['version']
50
+ @username, @password = @_config['user']['username'], @_config['user']['password']
51
+ raise "Oops. You forgot your username/password in ~/.githubissueswatcher/config.yaml" if @username.nil? || @password.nil?
52
+
53
+ @_db = DB # To accomodate testing
54
+
55
+ base_uri @base_uri
56
+ basic_auth @username, @password
57
+
58
+ end
59
+
60
+ def start!
61
+ time_since = time_since_last_run
62
+ time_started = Time.now
63
+ Dir.mkdir(File.dirname(db)) unless File.exist?(File.dirname(db))
64
+ File.open(db, "w"){ |f| f.write time_started.to_yaml }
65
+
66
+ issues_reported = []
67
+
68
+ watch.each do |value|
69
+ key, value, filtered = *value.split("/")
70
+ filtered = filtered.split("-")
71
+
72
+ if filtered.include?("mentioned")
73
+ m = get_mentioned_issues(key,value,time_since)
74
+ m.each do |issue|
75
+ issues_reported << issue["number"]
76
+ notify("Mentioned Issue - #{value}", issue["title"], true)
77
+ end
78
+ end
79
+
80
+ a = get_all_issues(key,value,time_since)
81
+ a.each do |issue|
82
+ next if issues_reported.include?(issue["number"])
83
+ issues_reported << issue["number"]
84
+ if filtered.include?("assigned") && issue["assignee"] && issue["assignee"]["login"].downcase == config["user"]["username"].downcase
85
+ notify("Assigned Issue", issue["title"])
86
+ next
87
+ end
88
+
89
+ if filtered.include?("created") && issue["user"]["login"].downcase == config["user"]["username"].downcase
90
+ notify("Created Issue", issue["title"])
91
+ next
92
+ end
93
+
94
+ if filtered.include?("all")
95
+ notify("Issue", issue["title"])
96
+ next
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+ alias :run :start!
103
+
104
+ def time_since_last_run
105
+ File.exist?(db) ? YAML.load_file(db) : Time.now
106
+ end
107
+
108
+ def watch
109
+ @_watch ||= []
110
+ end
111
+
112
+ def config
113
+ @_config
114
+ end
115
+
116
+ def db
117
+ @_db
118
+ end
119
+
120
+ def notify(title, text, sticky=false)
121
+ Growl.notify(text, :title => title, :icon => File.expand_path("../../images/icon.png", __FILE__), :sticky => sticky)
122
+ puts "=> #{title}: #{text}"
123
+ end
124
+
125
+ def get_mentioned_issues(username, repo, since_time)
126
+ giw_get "/repos/#{username}/#{repo}/issues?mentioned=artcentric&since=#{since_time.round.iso8601}"
127
+ end
128
+
129
+ def get_all_issues(username, repo, since_time)
130
+ giw_get "/repos/#{username}/#{repo}/issues?since=#{since_time.round.iso8601}"
131
+ end
132
+
133
+ def giw_get(url)
134
+ response = get(url)
135
+ puts response
136
+ raise "Bad credentials. Check your username/password in ~/.githubissueswatcher/config.yaml" if response.is_a?(Hash) && response["message"] == "Bad credentials"
137
+ raise "Repo not found at #{url}. Check your repo in ~/.githubissueswatcher/repos.yaml. Also, you may not have proper credentials. Check config.yaml." if response.is_a?(Hash) && response["message"] == "Not Found"
138
+ return response
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ module Githubissueswatcher
2
+ VERSION = "0.0.11"
3
+ end
Binary file
Binary file
data/test/api.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ api:
3
+ url: https://api.github.com
4
+ version: v3
5
+ user:
6
+ username: Artcentric
7
+ password: 'uQ.%:sd9#i0z.E0%:"Q5.I'
data/test/config.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ api:
3
+ url: https://api.github.com
4
+ version: v3
5
+ user:
6
+ username: Artcentric
7
+ password: 'uQ.%:sd9#i0z.E0%:"Q5.I'
data/test/db.yaml ADDED
@@ -0,0 +1 @@
1
+ --- 2011-10-10 23:39:49.804623 -07:00
data/test/repos.yaml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ - Artcentric/check2/mentioned-created-assigned
data/test/run_test.rb ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'test_helper'
2
+
3
+ class RunTest < MiniTest::Unit::TestCase
4
+ include TestHelper
5
+ include HTTParty
6
+
7
+ def setup
8
+ puts "Starting Test"
9
+
10
+ # File.delete(Githubissueswatcher::CONFIG_TEST) if File.exists?(Githubissueswatcher::CONFIG_TEST)
11
+ # File.delete(Githubissueswatcher::WATCH_TEST) if File.exists?(Githubissueswatcher::WATCH_TEST)
12
+ File.delete(Githubissueswatcher::DB_TEST) if File.exists?(Githubissueswatcher::DB_TEST)
13
+
14
+ Githubissueswatcher.setup
15
+
16
+ @_watch = YAML.load_file(Githubissueswatcher::WATCH_TEST)
17
+ @_repos = YAML.load_file(Githubissueswatcher::DB_TEST) if File.exist?(Githubissueswatcher::DB_TEST)
18
+ @base_uri, @api_version = YAML.load_file(Githubissueswatcher::CONFIG_TEST)
19
+
20
+ end
21
+
22
+
23
+
24
+ def test_run_tester
25
+ Githubissueswatcher.start!
26
+ assert_equal true,true
27
+ end
28
+
29
+ end
@@ -0,0 +1,69 @@
1
+ require 'rubygems' unless defined?(Gem)
2
+ require_relative '../lib/githubissueswatcher'
3
+ require 'minitest/autorun'
4
+
5
+ module TestHelper
6
+
7
+ def setup_files(api,watch)
8
+
9
+ Dir.mkdir(File.dirname(api)) unless File.exist?(File.dirname(watch))
10
+ File.open(api, "w") { |f| f.write ["https://api.github.com", "v3"].to_yaml }
11
+
12
+ Dir.mkdir(File.dirname(watch)) unless File.exist?(File.dirname(watch))
13
+ File.open(watch, "w") { |f| f.write ["daddye/all", "padrino/all"].to_yaml }
14
+
15
+ end
16
+
17
+ end
18
+
19
+ module Githubissueswatcher
20
+
21
+ this_dir = File.dirname(__FILE__)
22
+ puts this_dir
23
+
24
+ CONFIG_TEST = File.expand_path("#{this_dir}/config.yaml")
25
+ WATCH_TEST = File.expand_path("#{this_dir}/repos.yaml")
26
+ DB_TEST = File.expand_path("#{this_dir}/db.yaml")
27
+
28
+ def self.setup
29
+
30
+ warn "If timeout occurs, your credentials may be wrong."
31
+
32
+ unless File.exist?(CONFIG_TEST)
33
+ Dir.mkdir(File.dirname(CONFIG_TEST)) unless File.exist?(File.dirname(CONFIG_TEST))
34
+ File.open(CONFIG_TEST, "w") { |f| f.write \
35
+ YAML.load("
36
+ api:
37
+ url: 'https://api.github.com'
38
+ version: 'v3'
39
+ user:
40
+ username:
41
+ password:
42
+ ").to_yaml }
43
+ end
44
+
45
+ unless File.exist?(WATCH_TEST)
46
+ warn "Add the repositories you're willing to monitor editing: ~/.githubissueswatcher/repos.yaml"
47
+ Dir.mkdir(File.dirname(WATCH_TEST)) unless File.exist?(File.dirname(WATCH_TEST))
48
+ File.open(WATCH_TEST, "w") { |f| f.write ["padrino/all"].to_yaml }
49
+ end
50
+
51
+ unless File.exist?(DB_TEST)
52
+ Dir.mkdir(File.dirname(DB_TEST)) unless File.exist?(File.dirname(DB_TEST))
53
+ File.open(DB_TEST, "w") { |f| f.write (Time.now - 86400).to_yaml }
54
+ end
55
+
56
+ @_watch = YAML.load_file(WATCH_TEST)
57
+ @_time_since = YAML.load_file(DB_TEST) if File.exist?(DB_TEST)
58
+ @_config = YAML.load_file(CONFIG_TEST)
59
+ @base_uri, @api_version = @_config['api']['url'], @_config['api']['version']
60
+ @username, @password = @_config['user']['username'], @_config['user']['password']
61
+
62
+ @_db = DB_TEST
63
+
64
+ base_uri @base_uri
65
+ basic_auth @username, @password
66
+
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: githubissueswatcher
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 11
9
+ version: 0.0.11
10
+ platform: ruby
11
+ authors:
12
+ - Peter Gabbay
13
+ - Davide D'Agostino
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-11 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ - 7
32
+ - 8
33
+ version: 0.7.8
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: growl
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 3
48
+ version: 1.0.3
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: foreverb
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ - 2
62
+ - 6
63
+ version: 0.2.6
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ description: Github Issues Growl Watcher, watch any project issues and receive growl notification based on whether you are mentioned, assigned or the creator.
67
+ email:
68
+ - peter@check2.com
69
+ executables:
70
+ - githubissueswatcher
71
+ extensions: []
72
+
73
+ extra_rdoc_files: []
74
+
75
+ files:
76
+ - bin/githubissueswatcher
77
+ - Gemfile
78
+ - githubissueswatcher.gemspec
79
+ - images/icon.png
80
+ - lib/githubissueswatcher/version.rb
81
+ - lib/githubissueswatcher.rb
82
+ - pkg/githubissueswatcher-0.0.10.gem
83
+ - pkg/githubissueswatcher-0.0.9.gem
84
+ - Rakefile
85
+ - README.md
86
+ - test/api.yaml
87
+ - test/config.yaml
88
+ - test/db.yaml
89
+ - test/repos.yaml
90
+ - test/run_test.rb
91
+ - test/test_helper.rb
92
+ has_rdoc: true
93
+ homepage: https://github.com/Artcentric/githubissueswatcher
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: githubissueswatcher
120
+ rubygems_version: 1.3.7
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Github Issues Growl Watcher, watch any project issues and receive growl notification
124
+ test_files: []
125
+