- def url_addr(email)
- mail_body = @mail_content.part[0].body.decoded
- mail_content = mail_body.gsub(/=/, '').split(/\r|\n|=/).join
- url = %x(echo '#{mail_content}' |grep -o -E "https?://[^/]*/[^/]*/[^/]*/[^/]*/[0-9a-zA-Z]{40}").split(/\n/)[0]
Why use grep in ruby?
Looks you didn't check "my oss commit: " prefix.
for different email, the email content may in quite different format it is very difficult to get the commit url with ruby, it may need much split, join, gsub to get the url, and many times it still didnit suit for all cases
but use 'grep -o -E ' can resolve this problem.
Do something like this
@my_commit_url = ''
def append_url(line) @my_commit_url += line @in_url = false if @my_commit_url is complete end
each_body_line.do |line| if line =~ /^my oss commit: (.*)$/ @in_url = true append_url $1 elsif @in_url append_url line fi end
Thanks, Fengguang