Module: GithubIssueMaker

Defined in:
lib/github_issue_maker.rb

Instance Method Summary collapse

Instance Method Details

#create_github_issue!Object



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

def create_github_issue!
  set_config_variables

  s3 = Aws::S3::Client.new
  s3_body = Base64.decode64(self.send(@instance_details[:screenshot_column]).gsub(/^data:image\/\w+;base64,/, ''))
  s3.put_object(bucket: @s3_details[:bucket], acl: 'public-read', key: file_name, body: s3_body,
                content_type: 'image/png')

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

#description_sectionObject



28
29
30
# File 'lib/github_issue_maker.rb', line 28

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

#git_head_sectionObject



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

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

#github_issue_body(screenshot_url) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/github_issue_maker.rb', line 18

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



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

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

#url_sectionObject



37
38
39
# File 'lib/github_issue_maker.rb', line 37

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

#user_sectionObject



32
33
34
35
# File 'lib/github_issue_maker.rb', line 32

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