Class: Relaton::Logger::Channels::GhIssue

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/logger/channels/gh_issue.rb

Overview

This class is used to create a GitHub issue with the log content. The issue will be created in the repository specified in the initializer. The log content is stored in the issue body. Only unique log messages are stored. Token is required to create an issue. It should be stored in the environment variable GITHUB_TOKEN. To create an issue, call the create_issue method after all log messages are written.

Instance Method Summary collapse

Constructor Details

#initialize(repo, title) ⇒ GhIssue

Create a new instance of the class.

Parameters:

  • repo (String)

    owner/repo name

  • title (String)

    title of the issue



24
25
26
27
28
29
# File 'lib/relaton/logger/channels/gh_issue.rb', line 24

def initialize(repo, title)
  @repo = repo
  @title = title
  @log = Set.new
  puts "GITHUB_TOKEN is not set!" if ENV["GITHUB_TOKEN"].nil?
end

Instance Method Details

#closeObject



35
36
# File 'lib/relaton/logger/channels/gh_issue.rb', line 35

def close
end

#create_issueObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/relaton/logger/channels/gh_issue.rb', line 38

def create_issue
  return if @log.empty? || ENV["GITHUB_TOKEN"].nil?

  responce = post_issue

  if responce.code.to_i == 201
    puts "Issue created!"
  else
    puts "Failed to create issue: #{responce.code} #{responce.message}"
  end
end

#write(string) ⇒ Object



31
32
33
# File 'lib/relaton/logger/channels/gh_issue.rb', line 31

def write(string)
  @log << string
end