relaton-logger 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/relaton/logger/channels/gh_issue.rb +76 -0
- data/lib/relaton/logger/version.rb +1 -1
- data/lib/relaton/logger.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56155023be9761bf409a576e22703b1b2f2cc1ef9ef2290d264c29c7ad875549
|
|
4
|
+
data.tar.gz: a3cd75358fc69210004a40ad4081e8942db2313a260daf1a0e36754e8b42c273
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a868f415f0be67022bb18a4192f031c875cb42be1a698fb8b160d2154b95165cedd3b4417aea2070b3ff514bddd62cba01173a70dfaa157536242f4a589fb36
|
|
7
|
+
data.tar.gz: 921e56e9526a7f1ad6e3fac4205d042ef21a996ab9c4bbbfd7e6841b5e6ad99bc44a9a3243252e529017809b73249d02ee1f46e32942e42ed91865b1eb93d783
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
"Authorization" => "token #{ENV['GITHUB_TOKEN']}",
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/lib/relaton/logger.rb
CHANGED
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.
|
|
4
|
+
version: 0.2.1
|
|
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-
|
|
11
|
+
date: 2024-08-04 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
|