Class: Cinch::Plugins::Sentry::GitHub
- Inherits:
-
Object
- Object
- Cinch::Plugins::Sentry::GitHub
- Includes:
- ActionView::Helpers::DateHelper, Cinch::Plugin, Twitter::Extractor
- Defined in:
- lib/cinch/plugins/sentry/github.rb
Instance Method Summary collapse
-
#initialize ⇒ GitHub
constructor
A new instance of GitHub.
- #listen(m) ⇒ Object
Constructor Details
#initialize ⇒ GitHub
Returns a new instance of GitHub.
19 20 21 22 |
# File 'lib/cinch/plugins/sentry/github.rb', line 19 def initialize(*) super @bot = bot end |
Instance Method Details
#listen(m) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 |
# File 'lib/cinch/plugins/sentry/github.rb', line 24 def listen(m) # Exctract urls urls = extract_urls(m.) # Go through all links urls.each do |url| # Parse the url uri = URI.parse(URI.escape(url.to_url)) # We only handle GitHub links case uri.host when "www.github.com", "github.com" begin if not uri.path.to_s.empty? # Split the path by forward slash split = uri.path.split "/" # Check if we got a repository name in the link if split[2].nil? then # Fetch the user information user = Ocotkit.user split[1] # Reply with the information m.reply("[%s] %s (repos: %s)" % [ Format(:green, "GitHub"), Format(:bold, user.name.nil? ? user.login : user.name), Format(:teal, user.public_repos.to_s), ]) else # Fetch the repository information repo = Octokit.repo split[1] + "/" + split[2] # Fetch the latest commit = repo.rels[:commits].get.data.first.commit. # Reply with the information m.reply("[%s][%s] %s (commit: %s) (last update: %s) (stars: %s) (forks: %s)" % [ Format(:green, "GitHub"), Format(:blue, repo.owner.login), Format(:bold, repo.name), Format(:orange, .gsub(%r{[\n]+}," ")), Format(:orange, time_ago_in_words(repo.pushed_at).gsub(%r{(about[\s]+)?}, "") + " ago"), Format(:teal, repo.stargazers_count.to_s), Format(:teal, repo.forks.to_s) ]) end end rescue Exception => e # Log the exception puts e # Send back error message m.reply("[%s] %s" % [ Format(:green, "GitHub"), Format(:bold, "Invalid GitHub link") ]) end end end end |