Module: Githubwatcher
- Extended by:
- Githubwatcher
- Includes:
- HTTParty, Notifier
- Included in:
- Githubwatcher
- Defined in:
- lib/githubwatcher.rb,
lib/githubwatcher/version.rb
Constant Summary collapse
- API =
File.("~/.githubwatcher/api.yaml")
- WATCH =
File.("~/.githubwatcher/repos.yaml")
- DB =
File.("~/.githubwatcher/db.yaml")
- VERSION =
"0.1.1"
Instance Method Summary collapse
- #get_repositories(key) ⇒ Object
- #notify(title, text, sticky = false) ⇒ Object
- #repos ⇒ Object
- #resource_url(key) ⇒ Object
- #setup ⇒ Object
- #start! ⇒ Object (also: #run)
- #watch ⇒ Object
Instance Method Details
#get_repositories(key) ⇒ Object
101 102 103 104 |
# File 'lib/githubwatcher.rb', line 101 def get_repositories(key) r = get resource_url(key) @api_version == "v3" ? r : r["repositories"] end |
#notify(title, text, sticky = false) ⇒ Object
96 97 98 99 |
# File 'lib/githubwatcher.rb', line 96 def notify(title, text, sticky=false) Growl.notify(:message => text, :title => title, :image => File.("../../images/icon.png", __FILE__)); sleep 0.2 puts "=> #{title}: #{text}" end |
#repos ⇒ Object
88 89 90 |
# File 'lib/githubwatcher.rb', line 88 def repos @_repos ||= [] end |
#resource_url(key) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/githubwatcher.rb', line 106 def resource_url(key) case @api_version when "v3" "/users/%s/repos" % key when "v2" "/api/v2/json/repos/show/%s" % key else raise "Unkown api version" end end |
#setup ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/githubwatcher.rb', line 19 def setup puts "Starting GitHub Watcher..." unless File.exist?(API) Dir.mkdir(File.dirname(API)) unless File.exist?(File.dirname(WATCH)) File.open(API, "w") { |f| f.write ["https://api.github.com", "v3"].to_yaml } end 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) @base_uri, @api_version = YAML.load_file(API) @_repos = YAML.load_file(DB) if File.exist?(DB) base_uri @base_uri end |
#start! ⇒ Object Also known as: run
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/githubwatcher.rb', line 40 def start! repos_was = repos.dup watch.each do |value| key, value = *value.split("/") r = get_repositories(key) r.each do |repo| next unless value.include?(repo["name"]) || value.include?("all") puts "Quering #{repo["git_url"]}..." found = repos_was.find { |r| r["name"] == repo["name"] } repo_fullname = [repo['owner']['login'],repo['name']].join('/') if !found notify(repo_fullname, "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_fullname, "Has new #{repo["watchers"]-repo_was["watchers"]} watchers") repo_was["watchers"] = repo["watchers"] end if repo_was["open_issues"] != repo["open_issues"] notify(repo_fullname, "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_fullname, "Was updated!") repo_was["pushed_at"] = repo["pushed_at"] end if repo_was["forks"] != repo["forks"] notify(repo_fullname, "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 } end |
#watch ⇒ Object
92 93 94 |
# File 'lib/githubwatcher.rb', line 92 def watch @_watch ||= [] end |