|
#!/usr/bin/ruby |
|
|
|
require 'net/http' |
|
require 'json' |
|
require 'date' |
|
|
|
REDMINE_DOMAIN = "<replace me>".freeze |
|
REDMINE_API_TOKEN = "<replace me>".freeze |
|
|
|
class String |
|
# borrowed from Rails: activesupport/lib/active_support/core_ext/string/filters.rb |
|
def truncate(truncate_at, options = {}) |
|
return dup unless length > truncate_at |
|
|
|
omission = options[:omission] || '...' |
|
length_with_room_for_omission = truncate_at - omission.length |
|
stop = if options[:separator] |
|
rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission |
|
else |
|
length_with_room_for_omission |
|
end |
|
|
|
"#{self[0, stop]}#{omission}" |
|
end |
|
end |
|
|
|
uri = URI("https://#{REDMINE_DOMAIN}/issues.json?utf8=%E2%9C%93&set_filter=1&f%5B%5D=status_id&op%5Bstatus_id%5D=o&f%5B%5D=assigned_to_id&op%5Bassigned_to_id%5D=%3D&v%5Bassigned_to_id%5D%5B%5D=me&f%5B%5D=&c%5B%5D=project&c%5B%5D=tracker&c%5B%5D=category&c%5B%5D=priority&c%5B%5D=status&c%5B%5D=subject&c%5B%5D=assigned_to&c%5B%5D=updated_on&c%5B%5D=due_date&group_by=status&t%5B%5D=") |
|
|
|
issues = [] |
|
|
|
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| |
|
request = Net::HTTP::Get.new uri |
|
request.add_field "X-Redmine-API-Key", REDMINE_API_TOKEN |
|
|
|
response = http.request request # Net::HTTPResponse object |
|
|
|
issues = JSON.parse(response.body)['issues'] |
|
end |
|
|
|
puts ":gem: #{issues.count}" |
|
puts '---' |
|
puts "Redmine | href=https://#{REDMINE_DOMAIN}" |
|
issues.group_by { |issue| issue['status']['name'] }.each do |status, issues| |
|
puts '---' |
|
puts "[#{status}] | color=blue" |
|
issues.each do |issue| |
|
color = 'red' if issue['due_date'] && Date.parse(issue['due_date']) < Date.today |
|
|
|
subject = issue['subject'].to_s.truncate(50, separator: /\s/) |
|
changed_today = DateTime.strptime(issue['updated_on']).to_date == Date.today ? "☀️" : "" |
|
line = "• #{changed_today} " |
|
line += "##{issue['id']}: #{subject} | " |
|
line += "href=https://#{REDMINE_DOMAIN}/issues/#{issue['id']} " |
|
line += "color=#{color}" if color |
|
puts line |
|
end |
|
end |
|
puts '---' |
|
puts 'Refresh | refresh=' |