issue-db 1.1.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 +27 -25
- data/lib/issue_db/database.rb +191 -189
- 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 +282 -280
- data/lib/issue_db/utils/init.rb +19 -17
- 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
data/lib/issue_db/utils/init.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
module IssueDB
|
4
|
+
module Init
|
5
|
+
# A helper method for initializing the IssueDB library when .new is called
|
6
|
+
# Everything in this method should be idempotent and safe to call multiple times
|
7
|
+
def init!
|
8
|
+
begin
|
9
|
+
@client.add_label(
|
10
|
+
@repo.full_name,
|
11
|
+
@label,
|
12
|
+
"000000",
|
13
|
+
{ description: "This issue is managed by the issue-db Ruby library. Please do not remove this label." },
|
14
|
+
disable_retry: true
|
15
|
+
)
|
16
|
+
rescue StandardError => e
|
17
|
+
if e.message.include?("already_exists")
|
18
|
+
@log.debug("label #{@label} already exists")
|
19
|
+
else
|
20
|
+
@log.error("error creating label: #{e.message}") unless ENV.fetch("ENV", nil) == "acceptance"
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/issue_db/utils/parse.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module IssueDB
|
4
|
+
class ParseError < StandardError; end
|
4
5
|
|
5
|
-
module Parse
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
module Parse
|
7
|
+
# Parses the issue body
|
8
|
+
# This method returns a hash that contains the following fields:
|
9
|
+
# - body_before: the body of the issue before the data
|
10
|
+
# - data: the parsed data as a hash
|
11
|
+
# - body_after: the body of the issue after the data
|
12
|
+
# :param body [String] the body of the issue to parse data from
|
13
|
+
# :param guard_start [String] the guard start string which is used to identify the start of the data
|
14
|
+
# :param guard_end [String] the guard end string which is used to identify the end of the data
|
15
|
+
# :return [Hash] the parsed issue body
|
16
|
+
def parse(body, guard_start: "<!--- issue-db-start -->", guard_end: "<!--- issue-db-end -->")
|
17
|
+
body_array = body.split("\n")
|
18
|
+
start_index = body_array.index(guard_start)
|
19
|
+
end_index = body_array.index(guard_end)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
if start_index.nil? || end_index.nil?
|
22
|
+
raise ParseError, "issue body is missing a guard start or guard end"
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# remove the first and last line if they contain triple backticks (codeblock)
|
26
|
+
data = body_array[start_index + 1...end_index]
|
27
|
+
data.shift if data.first.include?("```")
|
28
|
+
data.pop if data.last.include?("```")
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# rejoins the data into a string
|
31
|
+
data = data.join("\n")
|
32
|
+
# parse the data
|
33
|
+
data = JSON.parse(data)
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
return {
|
36
|
+
body_before: body_array[0...start_index].join("\n"),
|
37
|
+
data: data,
|
38
|
+
body_after: body_array[end_index + 1..-1].join("\n"),
|
39
|
+
}
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/issue_db.rb
CHANGED
@@ -8,63 +8,75 @@ require_relative "issue_db/authentication"
|
|
8
8
|
require_relative "issue_db/models/repository"
|
9
9
|
require_relative "issue_db/database"
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
module IssueDB
|
12
|
+
# Module-level constructor that delegates to Client.new for convenience
|
13
|
+
# This allows users to call IssueDB.new instead of IssueDB::Client.new
|
14
|
+
def self.new(*args, **kwargs, &block)
|
15
|
+
Client.new(*args, **kwargs, &block)
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
class Client
|
19
|
+
include Version
|
20
|
+
include Authentication
|
21
|
+
include Init
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
# :param log: An optional logger - created for you by default
|
22
|
-
# :param octokit_client: An optional pre-hydrated Octokit::Client object
|
23
|
-
# :param label: The label to use for issues managed in the datastore by this library
|
24
|
-
# :param cache_expiry: The number of seconds to cache issues in memory (default: 60)
|
25
|
-
# :param init: Whether or not to initialize the database on object creation (default: true) - idempotent
|
26
|
-
# :return: A new IssueDB object
|
27
|
-
def initialize(repo, log: nil, octokit_client: nil, label: nil, cache_expiry: nil, init: true)
|
28
|
-
@log = log || RedactingLogger.new($stdout, level: ENV.fetch("LOG_LEVEL", "INFO").upcase)
|
29
|
-
@version = VERSION
|
30
|
-
@client = Authentication.login(octokit_client, @log)
|
31
|
-
@repo = Repository.new(repo)
|
32
|
-
@label = label || ENV.fetch("ISSUE_DB_LABEL", "issue-db")
|
33
|
-
@cache_expiry = cache_expiry || ENV.fetch("ISSUE_DB_CACHE_EXPIRY", 60).to_i
|
34
|
-
init! if init
|
35
|
-
end
|
23
|
+
attr_reader :log
|
24
|
+
attr_reader :version
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
# Create a new IssueDB::Client object
|
27
|
+
# :param repo: The GitHub repository to use as the datastore (org/repo format) [required]
|
28
|
+
# :param log: An optional logger - created for you by default
|
29
|
+
# :param octokit_client: An optional pre-hydrated Octokit::Client object
|
30
|
+
# :param label: The label to use for issues managed in the datastore by this library
|
31
|
+
# :param cache_expiry: The number of seconds to cache issues in memory (default: 60)
|
32
|
+
# :param init: Whether or not to initialize the database on object creation (default: true) - idempotent
|
33
|
+
# :param app_id: GitHub App ID (for GitHub App authentication)
|
34
|
+
# :param installation_id: GitHub App Installation ID (for GitHub App authentication)
|
35
|
+
# :param app_key: GitHub App private key (for GitHub App authentication)
|
36
|
+
# :param app_algo: GitHub App algorithm (for GitHub App authentication, defaults to RS256)
|
37
|
+
# :return: A new IssueDB::Client object
|
38
|
+
def initialize(repo, log: nil, octokit_client: nil, label: nil, cache_expiry: nil, init: true, app_id: nil, installation_id: nil, app_key: nil, app_algo: nil)
|
39
|
+
@log = log || RedactingLogger.new($stdout, level: ENV.fetch("LOG_LEVEL", "INFO").upcase)
|
40
|
+
@version = VERSION
|
41
|
+
@client = Authentication.login(octokit_client, @log, app_id:, installation_id:, app_key:, app_algo:)
|
42
|
+
@repo = Repository.new(repo)
|
43
|
+
@label = label || ENV.fetch("ISSUE_DB_LABEL", "issue-db")
|
44
|
+
@cache_expiry = cache_expiry || ENV.fetch("ISSUE_DB_CACHE_EXPIRY", 60).to_i
|
45
|
+
init! if init
|
46
|
+
end
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
def create(key, data, options = {})
|
49
|
+
db.create(key, data, options)
|
50
|
+
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
52
|
+
def read(key, options = {})
|
53
|
+
db.read(key, options)
|
54
|
+
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
def update(key, data, options = {})
|
57
|
+
db.update(key, data, options)
|
58
|
+
end
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
def delete(key, options = {})
|
61
|
+
db.delete(key, options)
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
def list(options = {})
|
65
|
+
db.list(options)
|
66
|
+
end
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
def list_keys(options = {})
|
69
|
+
db.list_keys(options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def refresh!
|
73
|
+
db.refresh!
|
74
|
+
end
|
64
75
|
|
65
|
-
|
76
|
+
protected
|
66
77
|
|
67
|
-
|
68
|
-
|
78
|
+
def db
|
79
|
+
@db ||= Database.new(@log, @client, @repo, @label, @cache_expiry)
|
80
|
+
end
|
69
81
|
end
|
70
82
|
end
|
data/lib/version.rb
CHANGED