module Pghub::Lgtm
Constants
- VERSION
Public Class Methods
post(issue_path)
click to toggle source
# File lib/pghub/lgtm.rb, line 11 def post(issue_path) comment_client = GithubAPI.new(issue_path) comment_client.post(get_md_link) end
Private Class Methods
get_md_link()
click to toggle source
# File lib/pghub/lgtm.rb, line 18 def get_md_link agent = Mechanize.new img_url = '' 3.times do |i| page = agent.get('http://lgtm.in/g') raise MarkdownUrlNotFound, 'Markdown URL is not found in http://lgtm.in/g.' unless page.at('input#dataUrl') img_url = page.at('input#dataUrl')[:value].gsub(%r{\/i\/}, '/p/') break if valid_redirect_link?(img_url) raise ManyInvalidUrls, "Many invalid URLs in #{url}" if i == 2 end "" end
get_response(url)
click to toggle source
# File lib/pghub/lgtm.rb, line 44 def get_response(url) Net::HTTP.get_response(URI.parse(url)) end
valid_redirect_link?(url)
click to toggle source
# File lib/pghub/lgtm.rb, line 36 def valid_redirect_link?(url) redirect_url = get_response(url)['location'] response = get_response(redirect_url) return response.code == '200' ? true : false rescue URI::InvalidURIError return false end