Sha256: 796e771d90a8a3b1c3b94b7fcd8b1ad52c8a674fc0dc009a552f38f59247b3a3
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
module Gitmine class Issue CONFIG_FILE = './.gitmine.yml' attr_reader :id, :subject, :status # Config from .gitmine.yml def self.config @@config ||= YAML.load_file(CONFIG_FILE) end # Extract the issue_id from a commit message. # Examples: # CommitMsgToIssueId.parse("Message for Issue #123.") # => 123 # CommitMsgToIssueId.parse("#123.") # => nil # def self.parse_for_issue_id(msg) match = msg.match(/Issue #(\d+)/) match ? match[1] : nil end # Parse the commit_message and get the associated issue if any. def self.get_for_commit(commit_message) issue_id = parse_for_issue_id(commit_message) issue_id ? Issue.find(issue_id) : nil end # Get the issue from redmine def self.find(issue_id) Issue.new.tap { |issue| issue.build_via_issue_id(issue_id) } end # Get attributes from redmine and set them all def build_via_issue_id(issue_id) @id = issue_id data = http_get(issue_id).parsed_response['issue'] @subject = data['subject'] @status = data['status']['name'] end # Add a note to the Issue def add_note(note) p self.class.put(url(self.id), :query => {:notes => note}, :body => "") # nginx reject requests without body end include HTTParty base_uri "#{config['host']}/issues/" basic_auth config['api_key'], '' # username is api_key, password is empty headers 'Content-type' => 'text/xml' # by-pass rails authenticity token mechanism protected # Url to redmine/issues def url(id) "/#{id}.xml" end def http_get(issue_id) self.class.get(url(issue_id)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gitmine-0.1.4.pre.1 | lib/gitmine/issue.rb |
gitmine-0.1.4.pre | lib/gitmine/issue.rb |