lib/agig/session.rb in agig-0.1.1 vs lib/agig/session.rb in agig-0.1.2
- old
+ new
@@ -52,15 +52,17 @@
entries = client.notifications
entries.sort_by(&:updated_at).reverse_each do |entry|
updated_at = Time.parse(entry.updated_at).utc
next if updated_at <= @notification_last_retrieved
- post entry.repository.owner.login, PRIVMSG, "#notification", "\0035#{entry.subject.title}\017 \00314#{entry.subject.latest_comment_url}\017"
+ reachable_url = reachable_url_for(entry.subject.latest_comment_url)
+
+ post entry.repository.owner.login, PRIVMSG, "#notification", "\0035#{entry.subject.title}\017 \00314#{reachable_url}\017"
@notification_last_retrieved = updated_at
end
- events = client.received_events('hsbt')
+ events = client.received_events(@nick)
events.sort_by(&:created_at).reverse_each do |event|
next if event.type != "WatchEvent"
created_at = Time.parse(event.created_at).utc
next if created_at <= @watch_last_retrieved
@@ -77,8 +79,22 @@
@log.error "\t#{l}"
end
sleep 10
end
end
+ end
+ end
+
+ def reachable_url_for(latest_comment_url)
+ repos_owner = latest_comment_url.match(/repos\/(.+?\/.+?)\//)[1]
+ if issue_match = latest_comment_url.match(/(?:issues|pulls)\/(\d+?)$/)
+ issue_id = issue_match[1]
+ latest_comment = client.issue_comments(repos_owner, issue_id).last
+ latest_comment ? latest_comment['html_url'] : latest_comment_url.sub(/api\./, '').sub(/repos\//, '')
+ elsif comment_match = latest_comment_url.match(/comments\/(\d+?)$/)
+ comment_id = comment_match[1]
+ client.issue_comment(repos_owner, comment_id)['html_url']
+ else
+ nil
end
end
end