Skip to content

Commit

Permalink
parse issues (body, assign, milestone)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Cichra committed Mar 21, 2012
1 parent 521a7cf commit 2e20a87
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion plugins/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Issues

def create(m, text)
Retryable.new(2) do |attempt|
issue = api.issues.create_issue(nil, nil, :title => text)
issue = api.issues.create_issue(nil, nil, IssueParser.new(text).to_hash)

if issue
m.reply "created issue #{issue.number} - #{issue.html_url}"
Expand Down Expand Up @@ -73,4 +73,52 @@ def run!
end
end

class IssueParser
def initialize(text)
@text = text
end

def tokens
@tokens ||= @text.split('|').map(&:strip)
end

def parse(name)
[tokens.find{ |t| t =~ /^#{name}:\s*(.+)$/ }, $1]
end

def attr(name)
parse(name).last
end

def token(name)
parse(name).first
end

def milestone
attr(:milestone)
end

def title
tokens.first
end

def body
except = [token(:milestone), token(/assigne{2}?/), title]
tokens.find {|t| not except.include?(t) }
end

def assignee
attr(/assigne{2}?/)
end

def to_hash
{
title: title,
body: body,
milestone: milestone,
assignee: assignee
}
end
end

end

0 comments on commit 2e20a87

Please sign in to comment.