relaton-logger 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d7fffb7e0193d66e22b213670ca709bffd1287073e7f4f3de1693b3fdde776d
4
- data.tar.gz: 6bb987f4c7602383e1057f31af7c434e5bb5dd02a76f6aa7895173400212906c
3
+ metadata.gz: 28114ca9f7bb92adec51c2321ff75193947ca8e6ccbc215829e4d7ea027da26f
4
+ data.tar.gz: b68d64026cf44d7bb0d6ffb74b4ec6d766aec5412f415a63b1491d7dde63e9f5
5
5
  SHA512:
6
- metadata.gz: 254877741b0be11d37bb412d497c2535a4f7ec28fe540949428392514a64a5d0a13ab5920328e30e718859c6ef2c89eddb74f4d23da491b636bebef0155d55bd
7
- data.tar.gz: e3488c4818408bc6b26447e54ab4a8f5df4c25023cd9d8de5159c83fb9fa66c5cf0d1637b45bb79297328f172dcaabe27ce00fb462c31f2a3db938543d155912
6
+ metadata.gz: 57e1f2d7eaf62c3f3e9b28d2d90a738ce0eb3ce7b4ff1e9f2f6bd821fa80971355283d8f820894d73fd25a158ce62cbb9c696ead8a3a6126e32b30a15397ba88
7
+ data.tar.gz: 6dbc4da30cdadfce5575589dd5bcc04c7b976dd28ca7bda5bd73df0d8f13fd71168929cc5f8f6f936c22f1074eb3852005e945009e00271b5dd52a52764d96b6
@@ -0,0 +1,78 @@
1
+ require "net/http"
2
+
3
+ module Relaton
4
+ module Logger
5
+ module Channels
6
+ #
7
+ # This class is used to create a GitHub issue with the log content.
8
+ # The issue will be created in the repository specified in the
9
+ # initializer.
10
+ # The log content is stored in the issue body. Only unique log messages
11
+ # are stored.
12
+ # Token is required to create an issue. It should be stored in the
13
+ # environment variable GITHUB_TOKEN.
14
+ # To create an issue, call the create_issue method after all log messages
15
+ # are written.
16
+ #
17
+ class GhIssue
18
+ #
19
+ # Create a new instance of the class.
20
+ #
21
+ # @param [String] repo owner/repo name
22
+ # @param [String] title title of the issue
23
+ #
24
+ def initialize(repo, title)
25
+ @repo = repo
26
+ @title = title
27
+ @log = Set.new
28
+ puts "GITHUB_TOKEN is not set!" if ENV["GITHUB_TOKEN"].nil?
29
+ end
30
+
31
+ def write(string)
32
+ @log << string
33
+ end
34
+
35
+ def close
36
+ end
37
+
38
+ def create_issue
39
+ return if @log.empty? || ENV["GITHUB_TOKEN"].nil?
40
+
41
+ responce = post_issue
42
+
43
+ if responce.code.to_i == 201
44
+ puts "Issue created!"
45
+ else
46
+ puts "Failed to create issue: #{responce.code} #{responce.message}"
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def post_issue
53
+ uri = URI("https://api.github.com/repos/#{@repo}/issues")
54
+ http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = true
56
+
57
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
58
+ request.body = issue_body.to_json
59
+
60
+ http.request(request)
61
+ end
62
+
63
+ def issue_body
64
+ { title: @title, body: @log.join("\n") }
65
+ end
66
+
67
+ def headers
68
+ {
69
+ "Content-Type" => "application/json",
70
+ "Accept" => "application/vnd.github+json",
71
+ "Authorization" => "Bearer #{ENV['GITHUB_TOKEN']}",
72
+ "X-GitHub-Api-Version" => "2022-11-28",
73
+ }
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Logger
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
@@ -9,6 +9,7 @@ require_relative "logger/pool"
9
9
  require_relative "logger/formatter_string"
10
10
  require_relative "logger/formatter_json"
11
11
  require_relative "logger/config"
12
+ require_relative "logger/channels/gh_issue"
12
13
 
13
14
  module Relaton
14
15
  def self.logger_pool
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger
@@ -37,6 +37,7 @@ files:
37
37
  - README.adoc
38
38
  - Rakefile
39
39
  - lib/relaton/logger.rb
40
+ - lib/relaton/logger/channels/gh_issue.rb
40
41
  - lib/relaton/logger/config.rb
41
42
  - lib/relaton/logger/formatter_json.rb
42
43
  - lib/relaton/logger/formatter_string.rb