github issue watcher
# intended for heroku daily scheduler | |
require "open-uri" | |
require "json" | |
require "pushover" | |
require "pry" | |
repos = { | |
"user/repo" => "tag" | |
} | |
query = { | |
state: :open, | |
since: (Time.now.utc - (60*60*24)).to_s.split(" ").zip(["T", ""]).flatten.join | |
} | |
base_url = "https://api.github.com/repos/OWNER/REPO/issues?" | |
issues = [] | |
repos.each do |repo, label| | |
url = [base_url.gsub("OWNER/REPO", repo), URI.encode_www_form(query.merge(labels: label))].join | |
data = JSON.parse open(url).read | |
issues += data.map do |issue| | |
[ | |
"<b>" + repo + "</b>", | |
"<a href=\"#{issue["html_url"]}\">#{issue["title"]}</a>", | |
issue["labels"].reject { |l| l["name"] == label } | |
.map { |label| "<font color=\"##{label["color"]}\">#{label["name"]}</font>" } | |
.join(", "), | |
((Time.now.utc - Time.parse(issue["created_at"])) / (60*60*24)).round.to_s + " days ago" | |
] | |
end | |
end | |
message_title = "#{issues.size} issues" | |
message_body = issues.map { |i| i.join("\n ") }.join("\n\n") | |
if issues.size > 0 | |
Pushover.notification(message: message_body, | |
title: message_title, | |
html: 1, | |
user: ENV["PUSHOVER_USER"], | |
token: ENV["PUSHOVER_TOKEN"]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment