issue-db 1.0.0 → 1.2.0
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/README.md +34 -6
- data/issue-db.gemspec +1 -1
- data/lib/issue_db/authentication.rb +36 -28
- data/lib/issue_db/cache.rb +28 -20
- data/lib/issue_db/database.rb +194 -170
- data/lib/issue_db/models/record.rb +25 -23
- data/lib/issue_db/models/repository.rb +15 -13
- data/lib/issue_db/utils/generate.rb +38 -36
- data/lib/issue_db/utils/github.rb +285 -268
- data/lib/issue_db/utils/init.rb +19 -16
- data/lib/issue_db/utils/parse.rb +33 -31
- data/lib/issue_db.rb +59 -47
- data/lib/version.rb +4 -2
- metadata +1 -1
@@ -2,34 +2,36 @@
|
|
2
2
|
|
3
3
|
require_relative "../utils/parse"
|
4
4
|
|
5
|
-
|
5
|
+
module IssueDB
|
6
|
+
class IssueParseError < StandardError; end
|
6
7
|
|
7
|
-
class Record
|
8
|
-
|
8
|
+
class Record
|
9
|
+
include Parse
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
attr_reader :body_before, :data, :body_after, :source_data, :key
|
12
|
+
def initialize(data)
|
13
|
+
@key = data.title
|
14
|
+
@source_data = data
|
15
|
+
parse!
|
16
|
+
end
|
16
17
|
|
17
18
|
protected
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def parse!
|
21
|
+
if @source_data.body.nil? || @source_data.body.strip == ""
|
22
|
+
raise IssueParseError, "issue body is empty for issue number #{@source_data.number}"
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
parsed = parse(@source_data.body)
|
27
|
+
rescue JSON::ParserError => e
|
28
|
+
message = "failed to parse issue body data contents for issue number: #{@source_data.number} - #{e.message}"
|
29
|
+
raise IssueParseError, message
|
30
|
+
end
|
31
|
+
|
32
|
+
@body_before = parsed[:body_before]
|
33
|
+
@data = parsed[:data]
|
34
|
+
@body_after = parsed[:body_after]
|
22
35
|
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
parsed = parse(@source_data.body)
|
26
|
-
rescue JSON::ParserError => e
|
27
|
-
message = "failed to parse issue body data contents for issue number: #{@source_data.number} - #{e.message}"
|
28
|
-
raise IssueParseError, message
|
29
|
-
end
|
30
|
-
|
31
|
-
@body_before = parsed[:body_before]
|
32
|
-
@data = parsed[:data]
|
33
|
-
@body_after = parsed[:body_after]
|
34
36
|
end
|
35
37
|
end
|
@@ -1,22 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module IssueDB
|
4
|
+
class RepoFormatError < StandardError; end
|
4
5
|
|
5
|
-
class Repository
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
class Repository
|
7
|
+
attr_reader :owner, :repo, :full_name
|
8
|
+
def initialize(repo)
|
9
|
+
@repo = repo
|
10
|
+
validate!
|
11
|
+
end
|
11
12
|
|
12
13
|
protected
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def validate!
|
16
|
+
if @repo.nil? || !@repo.include?("/")
|
17
|
+
raise RepoFormatError, "repository #{@repo} is invalid - valid format: <owner>/<repo>"
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
@full_name = @repo.strip
|
21
|
+
@owner, @repo = @full_name.split("/")
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,45 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module IssueDB
|
4
|
+
class GenerateError < StandardError; end
|
4
5
|
|
5
|
-
module Generate
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
module Generate
|
7
|
+
# Generates the issue body with embedded data
|
8
|
+
# :param data [Hash] the data to embed in the issue body
|
9
|
+
# :param body_before [String] the body of the issue before the data (optional)
|
10
|
+
# :param body_after [String] the body of the issue after the data (optional)
|
11
|
+
# :param guard_start [String] the guard start string which is used to identify the start of the data
|
12
|
+
# :param guard_end [String] the guard end string which is used to identify the end of the data
|
13
|
+
# :return [String] the issue body with the embedded data
|
14
|
+
def generate(
|
15
|
+
data,
|
16
|
+
body_before: nil,
|
17
|
+
body_after: nil,
|
18
|
+
guard_start: "<!--- issue-db-start -->",
|
19
|
+
guard_end: "<!--- issue-db-end -->"
|
20
|
+
)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
# json formatting options
|
23
|
+
opts = {
|
24
|
+
indent: " ",
|
25
|
+
space: " ",
|
26
|
+
object_nl: "\n",
|
27
|
+
array_nl: "\n",
|
28
|
+
allow_nan: true,
|
29
|
+
max_nesting: false
|
30
|
+
}
|
30
31
|
|
31
|
-
|
32
|
+
json_data = JSON.pretty_generate(data, opts)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
# construct the body
|
35
|
+
body = ""
|
36
|
+
body += "#{body_before}\n" unless body_before.nil? # the first part of the body
|
37
|
+
body += "#{guard_start}\n" # the start of the data
|
38
|
+
body += "```json\n" # the start of the json codeblock
|
39
|
+
body += "#{json_data}\n" # the data
|
40
|
+
body += "```\n" # the end of the json codeblock
|
41
|
+
body += "#{guard_end}\n" # the end of the data
|
42
|
+
body += body_after unless body_after.nil? # the last part of the body
|
42
43
|
|
43
|
-
|
44
|
+
return body
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|