Skip to content

Instantly share code, notes, and snippets.

@neckhair
Last active March 28, 2019 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neckhair/e88966cf859340593f040fabd7a54fc4 to your computer and use it in GitHub Desktop.
Save neckhair/e88966cf859340593f040fabd7a54fc4 to your computer and use it in GitHub Desktop.
BitBar Redmine Plugin

Redmine Bitbar Plugin

This is a Redmine plugin for BitBar.

It lists all issues which are assigned to you and groups them by status. It also indicates overdue issues and shows which issues have been changed today.

Installation

  1. Copy the source into your plugin folder.
  2. Change the Redmine URL (line 7)
  3. Change your API key (line 8) which you can find in your Redmine account page.
#!/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='
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment