Skip to content

Instantly share code, notes, and snippets.

@topray
Last active August 29, 2015 14:13
Show Gist options
  • Save topray/526dd9d131bb6f3e3281 to your computer and use it in GitHub Desktop.
Save topray/526dd9d131bb6f3e3281 to your computer and use it in GitHub Desktop.
git hook for redmine
#!/usr/bin/env ruby
require "redmine"
Redmine.configure do |config|
config.api_key = "<api_key>"
config.site = "<site_url>"
# if you need, you can define default values.
config.resources[:issue] = {
project_id: 1,
tracker_id: 1,
status_id: 1,
priority_id: 2,
category_id: 1
}
config.resources[:time_entry] = {
activity_id: 9
}
end
# "#<ticket>:<status>:<hours> <message>"
MESSAGE_FORMAT = /(\#([\d]+))?((\:)?([\d]))?(\:([\d|\.]+))?[\s]?(.+)/m
message = File.read(ARGV[0]).strip
matches = message.match(MESSAGE_FORMAT)
ticket_id = matches[2]
status_id = matches[5]
hours = matches[7]
message = matches[8]
issue = nil
if ticket_id
issue = Redmine::Issue.find(ticket_id)
issue.status_id = status_id
issue.notes = message
issue.save
else
if status_id
issue = Redmine::Issue.create(
subject: message,
status_id: status_id
)
end
end
if issue and hours
Redmine::TimeEntry.create(
issue_id: issue.id,
hours: hours,
comments: message
)
end
@topray
Copy link
Author

topray commented Jan 20, 2015

If you are using SSL

Redmine::Base.ssl_options = {
:verify_mode => OpenSSL::SSL::VERIFY_PEER
}

Here is more information.
http://api.rubyonrails.org/v3.2.1/classes/ActiveResource/Base.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment