Module: GithubIssueMaker

Defined in:
lib/github_issue_maker.rb

Instance Method Summary collapse

Instance Method Details

#create_github_issue!Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/github_issue_maker.rb', line 6

def create_github_issue!
  set_config_variables

  file_name = "#{SecureRandom.hex}/issue.png"
  create_s3_object(file_name)
  github = Github.new oauth_token: @github_details[:access_token]
  issue_body = github_issue_body(file_name)
  issue = github.issues.create(user: @github_details[:user], repo: @github_details[:repo], body: issue_body,
                               title: @github_details[:issue_title], labels: @github_details[:labels])
  issue[:html_url]
end

#create_s3_object(file_name) ⇒ Object



18
19
20
21
22
# File 'lib/github_issue_maker.rb', line 18

def create_s3_object(file_name)
  s3 = Aws::S3::Client.new
  s3_body = decoded_issue_screenshot
  s3.put_object(bucket: @s3_details[:bucket], acl: 'public-read', key: file_name, body: s3_body, content_type: 'image/png')
end

#decoded_issue_screenshotObject



24
25
26
27
28
29
# File 'lib/github_issue_maker.rb', line 24

def decoded_issue_screenshot
  screenshot = self.send(@instance_details[:screenshot_column])
  base_64_data_regex = /^data:image\/\w+;base64,/
  screenshot.gsub!(base_64_data_regex, '')
  Base64.decode64(screenshot)
end

#description_sectionObject



41
42
43
# File 'lib/github_issue_maker.rb', line 41

def description_section
  self.send(@instance_details[:description_column])
end

#git_head_sectionObject



58
59
60
# File 'lib/github_issue_maker.rb', line 58

def git_head_section
  self.send(@instance_details[:git_hash_column])
end

#github_issue_body(screenshot_url) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/github_issue_maker.rb', line 31

def github_issue_body(screenshot_url)
  body = []
  body << "# Description \n #{description_section}"
  body << "# User \n #{user_section}"
  body << "# URL \n #{url_section}"
  body << "# Screenshot \n #{screenshot_section(screenshot_url)}"
  body << "# HEAD \n #{git_head_section}"
  body.join("\n \n")
end

#screenshot_section(screenshot_url) ⇒ Object



54
55
56
# File 'lib/github_issue_maker.rb', line 54

def screenshot_section(screenshot_url)
  "![Issue](https://s3-#{@s3_details[:region]}.amazonaws.com/#{@s3_details[:bucket]}/#{screenshot_url})"
end

#url_sectionObject



50
51
52
# File 'lib/github_issue_maker.rb', line 50

def url_section
  self.send(@instance_details[:url_column])
end

#user_sectionObject



45
46
47
48
# File 'lib/github_issue_maker.rb', line 45

def user_section
  user = self.send(@instance_details[:user_method])
  "#{user.try(:email) || user.try(:login)} - (#{user.try(:id)})"
end