Created
June 1, 2012 08:03
-
-
Save joker1007/2850118 to your computer and use it in GitHub Desktop.
Get github activity from atom feed, and notify to Skype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example | |
atom_url: "https://github.com/organizations/hogehoge/hogehoge.private.atom?token=xxxxxxx" | |
chat_id: "#fugafuga/$xxxxxxx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "actionpack" | |
gem "rype" | |
gem "awesome_print" | |
gem "simple-rss" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "bundler/setup" | |
require "action_view" | |
require "rype" | |
require "awesome_print" | |
require "simple-rss" | |
require "open-uri" | |
require "yaml" | |
class GithubSkypeNotifier | |
include ActionView::Helpers::SanitizeHelper | |
def initialize(atom_url, chat_id) | |
@atom_url = atom_url | |
@chat_id = chat_id | |
Rype.attach | |
Dir.chdir(File.dirname(__FILE__)) | |
unless File.exist?("notified_list.txt") | |
File.open("notified_list.txt", "w") {|file| puts "Create notified_list.txt"} | |
end | |
notified_list = File.open("notified_list.txt", "r") | |
@notified_items = notified_list.readlines.map{|l| l.chomp}.reduce({}) do |table, item_id| | |
table[item_id] = true | |
table | |
end | |
notified_list.close | |
end | |
def get_items | |
SimpleRSS.parse(open(@atom_url)).items.select {|item| !@notified_items[item.id]} | |
end | |
def notify(item) | |
message = <<EOM | |
==Github Activity Notify== | |
#{item.title} | |
#{item.link} | |
detail: | |
#{strip_tags(CGI.unescapeHTML(item.content)).gsub(/\s*\n/, "").gsub(/\s+/, " ")} | |
========================== | |
EOM | |
Rype.chat(@chat_id).send_message(message) | |
puts "send message following:\n#{message}" | |
log_item(item) | |
end | |
def log_item(item) | |
unless @notified_items[item.id] | |
@notified_items[item.id] = true | |
File.open("notified_list.txt", "a") {|file| file.write(item.id + "\n")} | |
end | |
end | |
end | |
def load_config | |
config = YAML.load_file("config.yml") | |
config | |
end | |
config = load_config | |
notifier = GithubSkypeNotifier.new(config["atom_url"], config["chat_id"]) | |
notifier.get_items.each do |item| | |
notifier.notify item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment