Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 04a901aa74b09c3e3d331b25011bd607249cb9f2 @DAddYE committed Jul 8, 2011
Showing with 248 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +14 −0 .irbrc
  3. +4 −0 Gemfile
  4. +66 −0 README.md
  5. +2 −0 Rakefile
  6. +31 −0 bin/githubwatcher
  7. +24 −0 githubwatcher.gemspec
  8. BIN images/icon.png
  9. +100 −0 lib/githubwatcher.rb
  10. +3 −0 lib/githubwatcher/version.rb
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
14 .irbrc
@@ -0,0 +1,14 @@
+# http://blog.nicksieger.com/articles/2006/04/23/tweaking-irb
+ARGV.concat ["--readline", "--prompt-mode", "simple"]
+
+require 'irb/completion'
+require 'irb/ext/save-history'
+IRB.conf[:SAVE_HISTORY] = 500
+IRB.conf[:HISTORY_FILE] = File.expand_path('~/.irb_history')
+
+require 'pp'
+
+def restart
+ $0 += " console" if $0 =~ /bundle$/
+ exec $0
+end
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in githubwatcher.gemspec
+gemspec
@@ -0,0 +1,66 @@
+## Github Watcher
+
+Github watcher is a simple and useful gem that help you to constantly monitor your repositories to get updates when:
+
+* Number of watchers change
+* Number of forks change
+* Number of issues change
+* Repo was updated
+
+It uses [ruby forever](https://github.com/DAddYE/forever) to demonize the process.
+
+## Prerequisites
+
+You need to have **growlnotify** installed. To do that you can install it through official [site](http://growl.info) or
+if you have the awesome [brew](https://github.com/mxcl/homebrew) simply with:
+
+``` sh
+$ brew install growlnotify
+```
+
+## Installation
+
+``` sh
+$ sudo gem install githubwatcher
+$ githubwatcher start
+$ githubwatcher stop
+```
+
+## Configuration
+
+You need to tell to our program which repositories you want to watch, to do that simply edit ```~/.githubwatcher/repos.yaml```
+with your favorite editor.
+
+Should look like this (if you have ran ```githubwatcher start```)
+
+``` yml
+---
+- daddye/all
+- padrino/all
+```
+
+So if for example you want to watch [sinatra](https://github.com/sinatra/sinatra) add it, the result should look like:
+
+``` yml
+---
+- daddye/all
+- padrino/all
+- sinatra/sinatra
+```
+
+If you want to watch **all** repositories of a given user you simply provide **/all** so will look like:
+
+``` yml
+---
+- daddye/all
+- padrino/all
+- sinatra/all
+```
+
+Restart the deamon
+
+```
+githubwatcher start
+```
+
+Your are done!
@@ -0,0 +1,2 @@
+require 'rubygems' unless defined?(Gem)
+require 'bundler/gem_tasks'
@@ -0,0 +1,31 @@
+#!/usr/bin/ruby
+require 'rubygems' unless defined?(Gem)
+require 'forever'
+require 'mail'
+
+Forever.run do
+ ##
+ # You can set these values
+ #
+ # dir "foo" # Default: File.expand_path('../../', __FILE__)
+ # file "bar" # Default: __FILE__
+ # log "bar.log" # Default: File.expand_path(dir, '/log/[file_name].log')
+ # pid "bar.pid" # Default: File.expand_path(dir, '/tmp/[file_name].pid')
+ #
+
+ on_error do |e|
+ Mail.deliver do
+ delivery_method :sendmail, :location => `which sendmail`.chomp
+ to "d.dagostino@lipsiasoft.com"
+ from "exceptions@lipsiasoft.com"
+ subject "[GitHub Watcher] #{e.message}"
+ body "%s\n %s" % [e.message, e.backtrace.join("\n ")]
+ end
+ end
+
+ on_ready do
+ require 'bundler/setup'
+ require 'githubwatcher'
+ Githubwatcher.start!
+ end
+end
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "githubwatcher/version"
+
+Gem::Specification.new do |s|
+ s.name = "githubwatcher"
+ s.version = Githubwatcher::VERSION
+ s.authors = ["Davide D'Agostino"]
+ s.email = ["d.dagostino@lipsiasoft.com"]
+ s.homepage = "https://github.com/DAddYE/githubwatcher"
+ s.summary = "Github Growl Watcher, watch any project and receive growl notification"
+ s.description = "Github Growl Watcher, watch any project and receive growl notification for updates, new watchers, forks and issues"
+
+ s.rubyforge_project = "githubwatcher"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+ s.add_dependency 'httparty', '~>0.7.8'
+ s.add_dependency 'growl', '~>1.0.3'
+ s.add_dependency 'forever', '~>0.1.0'
+ s.add_dependency 'mail', '~>2.3.0'
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,100 @@
+require "githubwatcher/version"
+require "httparty"
+require "growl"
+
+module Githubwatcher
+ extend self
+ include HTTParty
+
+ WATCH = File.expand_path("~/.githubwatcher/repos.yaml")
+ DB = File.expand_path("~/.githubwatcher/db.yaml", __FILE__)
+
+ base_uri 'https://api.github.com'
+ format :json
+
+ def start!
+ raise "You need to install growlnotify, use brew install growlnotify or install it from growl.info site" unless Growl.installed?
+ log "Starting GitHub Watcher..."
+
+ unless File.exist?(WATCH)
+ warn "Add the repositories you're willing to monitor editing: ~/.githubwatcher/repos.yaml"
+ Dir.mkdir(File.dirname(WATCH)) unless File.exist?(File.dirname(WATCH))
+ File.open(WATCH, "w") { |f| f.write ["daddye/all", "padrino/all"].to_yaml }
+ end
+
+ @_watch = YAML.load_file(WATCH)
+
+ notify("GitHub Watcher", "is now listening...")
+ @_repos = YAML.load_file(DB) if File.exist?(DB)
+ while !@_stop do
+ repos_was = repos.dup
+ watch.each do |value|
+ key, value = *value.split("/")
+ r = get "/users/%s/repos" % key
+ r.each do |repo|
+ next unless value.include?(repo["name"]) || value.include?("all")
+ log "Quering #{repo["git_url"]}..."
+
+ found = repos_was.find { |r| r["name"] == repo["name"] }
+
+ if !found
+ notify(repo["name"], "Was created")
+ repos_was << repo
+ repos << repo
+ end
+
+ repo_was = repos_was.find { |r| r["name"] == repo["name"] }
+
+ if repo_was["watchers"] != repo["watchers"]
+ notify(repo["name"], "Has new #{repo["watchers"]-repo_was["watchers"]} watchers")
+ repo_was["watchers"] = repo["watchers"]
+ end
+
+ if repo_was["open_issues"] != repo["open_issues"]
+ notify(repo["name"], "Has new #{repo["open_issues"]-repo_was["open_issues"]} open issues")
+ repo_was["open_issues"] = repo["open_issues"]
+ end
+
+ if repo_was["pushed_at"] != repo["pushed_at"]
+ notify(repo["name"], "Was updated!")
+ repo_was["pushed_at"] = repo["pushed_at"]
+ end
+
+ if repo_was["forks"] != repo["forks"]
+ notify(repo["name"], "Has new #{repo["forks"]-repo_was["forks"]} forks")
+ repo_was["forks"] = repo["forks"]
+ end
+
+ found = repo if found
+ end
+ end
+ Dir.mkdir(File.dirname(DB)) unless File.exist?(File.dirname(DB))
+ File.open(DB, "w"){ |f| f.write @_repos.to_yaml }
+ sleep 5
+ end
+ end
+
+ def repos
+ @_repos ||= []
+ end
+
+ def watch
+ @_watch ||= []
+ end
+
+ def stop!
+ puts "\n<= Exiting ..."
+ @_stop = true
+ end
+
+ def log(text="")
+ text = "[%s] %s" % [Time.now.strftime("%d/%m %H:%M"), text.to_s]
+ text += "\n" unless text[-1] == ?\n
+ print text; $stdout.flush
+ end
+
+ def notify(title, text)
+ Growl.notify text, :title => title, :icon => File.expand_path("../../images/icon.png", __FILE__); sleep 0.2
+ log "=> #{title}: #{text}"
+ end
+end
@@ -0,0 +1,3 @@
+module Githubwatcher
+ VERSION = "0.0.1"
+end

0 comments on commit 04a901a

Please sign in to comment.