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.
@@ -1,22 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Init
4
- # A helper method for initializing the IssueDB library when .new is called
5
- # Everything in this method should be idempotent and safe to call multiple times
6
- def init!
7
- begin
8
- @client.add_label(
9
- @repo.full_name,
10
- @label,
11
- "000000",
12
- { description: "This issue is managed by the issue-db Ruby library. Please do not remove this label." },
13
- disable_retry: true
14
- )
15
- rescue StandardError => e
16
- if e.message.include?("already_exists")
17
- @log.debug("label #{@label} already exists")
18
- else
19
- @log.error("error creating label: #{e.message}") unless ENV.fetch("ENV", nil) == "acceptance"
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
@@ -1,40 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ParseError < StandardError; end
3
+ module IssueDB
4
+ class ParseError < StandardError; end
4
5
 
5
- module Parse
6
- # Parses the issue body
7
- # This method returns a hash that contains the following fields:
8
- # - body_before: the body of the issue before the data
9
- # - data: the parsed data as a hash
10
- # - body_after: the body of the issue after the data
11
- # :param body [String] the body of the issue to parse data from
12
- # :param guard_start [String] the guard start string which is used to identify the start of the data
13
- # :param guard_end [String] the guard end string which is used to identify the end of the data
14
- # :return [Hash] the parsed issue body
15
- def parse(body, guard_start: "<!--- issue-db-start -->", guard_end: "<!--- issue-db-end -->")
16
- body_array = body.split("\n")
17
- start_index = body_array.index(guard_start)
18
- end_index = body_array.index(guard_end)
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
- if start_index.nil? || end_index.nil?
21
- raise ParseError, "issue body is missing a guard start or guard end"
22
- end
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
- # remove the first and last line if they contain triple backticks (codeblock)
25
- data = body_array[start_index + 1...end_index]
26
- data.shift if data.first.include?("```")
27
- data.pop if data.last.include?("```")
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
- # rejoins the data into a string
30
- data = data.join("\n")
31
- # parse the data
32
- data = JSON.parse(data)
30
+ # rejoins the data into a string
31
+ data = data.join("\n")
32
+ # parse the data
33
+ data = JSON.parse(data)
33
34
 
34
- return {
35
- body_before: body_array[0...start_index].join("\n"),
36
- data: data,
37
- body_after: body_array[end_index + 1..-1].join("\n"),
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
- class IssueDB
12
- include Version
13
- include Authentication
14
- include Init
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
- attr_reader :log
17
- attr_reader :version
18
+ class Client
19
+ include Version
20
+ include Authentication
21
+ include Init
18
22
 
19
- # Create a new IssueDB object
20
- # :param repo: The GitHub repository to use as the datastore (org/repo format) [required]
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
- def create(key, data, options = {})
38
- db.create(key, data, options)
39
- end
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
- def read(key, options = {})
42
- db.read(key, options)
43
- end
48
+ def create(key, data, options = {})
49
+ db.create(key, data, options)
50
+ end
44
51
 
45
- def update(key, data, options = {})
46
- db.update(key, data, options)
47
- end
52
+ def read(key, options = {})
53
+ db.read(key, options)
54
+ end
48
55
 
49
- def delete(key, options = {})
50
- db.delete(key, options)
51
- end
56
+ def update(key, data, options = {})
57
+ db.update(key, data, options)
58
+ end
52
59
 
53
- def list(options = {})
54
- db.list(options)
55
- end
60
+ def delete(key, options = {})
61
+ db.delete(key, options)
62
+ end
56
63
 
57
- def list_keys(options = {})
58
- db.list_keys(options)
59
- end
64
+ def list(options = {})
65
+ db.list(options)
66
+ end
60
67
 
61
- def refresh!
62
- db.refresh!
63
- end
68
+ def list_keys(options = {})
69
+ db.list_keys(options)
70
+ end
71
+
72
+ def refresh!
73
+ db.refresh!
74
+ end
64
75
 
65
- protected
76
+ protected
66
77
 
67
- def db
68
- @db ||= Database.new(@log, @client, @repo, @label, @cache_expiry)
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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Version
4
- VERSION = "1.1.0"
3
+ module IssueDB
4
+ module Version
5
+ VERSION = "1.2.0"
6
+ end
5
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: issue-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - runwaylab