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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f4349ba13a8c9f2971aae3c557c6bcd8d0b1b3fc51ecb4a901e3db2a30538db
4
- data.tar.gz: a59e1724a2f9068bd4596a311b051224ad48a8df158e0607f5dc51374f096033
3
+ metadata.gz: 740a1a64de7f9ab45fd7932682999972139392b4c8d8f48105cde4f49e9474b1
4
+ data.tar.gz: 6219653cb7f2303482e039f906ae788e4d9f9a89131df12e750ef35cc0f8a976
5
5
  SHA512:
6
- metadata.gz: e64935039edab751270a2fe8d924d32fff52035364baaa0a6455cf2fd0931fd4c51d39164b283435646c44cde628d3fb5cd98908673d8a1c0138a028855750d3
7
- data.tar.gz: 28e242676837588f0dbadf5dc831569bc26e703d2533938daebe62e0eb45d59c3d243d8678d4f91dd03baeba371f40cc3272a4290d23af6b6bafd88aac8b2976
6
+ metadata.gz: 743c37f2ca18320e7ce68f4c5f88b2275a19c93f2239d10c7a1b5102ffb089444fb79ca947efef6dd47792bfeeafe82ead49812e92605f2ccafa0b351ce9ac43
7
+ data.tar.gz: cb0eb761ee2dfa89c3fc0f8d096957269905052778756a09fc755c3a5975264c690e725e38f707e4a10be618e8255f6b2cde26d1755d4ddac3d06c919e7499b7
data/README.md CHANGED
@@ -65,9 +65,12 @@ gem install issue-db --version "X.X.X"
65
65
 
66
66
  ## Usage 💻
67
67
 
68
- The following CRUD operations are available for the `issue-db` gem:
68
+ This section goes into details on the following CRUD operations are available for the `issue-db` gem.
69
69
 
70
- > Note: All methods return the `IssueDB::Record` of the object which was involved in the operation
70
+ Note: All methods return the `IssueDB::Record` of the object which was involved in the operation
71
+
72
+ > [!IMPORTANT]
73
+ > The key for the record is the title of the GitHub issue. This means that the key **must be unique** within the database. If you try to do any sort of duplicate operation on a key that already exists (like creating it again), the `issue-db` gem will return the existing record without modifying it. Here is an example log message where someone calls `db.create("order_number_123", { location: "London", items: [ "cookies", "espresso" ] })` but the key already exists: `skipping issue creation and returning existing issue - an issue already exists with the key: order_number_123`. Additionally, if there are duplicates (same issue titles), then the latest issue will be returned (ex: issue 15 will be returned instead of issue 14). Basically, if you use fully unique keys, you won't ever run into this issue so please make sure to use unique keys for your records!
71
74
 
72
75
  ### `db.create(key, data, options = {})`
73
76
 
@@ -194,13 +197,14 @@ This section will go into detail around how you can configure the `issue-db` gem
194
197
 
195
198
  ## Authentication 🔒
196
199
 
197
- The `issue-db` gem uses the [`Octokit.rb`](https://github.com/octokit/octokit.rb) library under the hood for interactions with the GitHub API. You have three options for authentication when using the `issue-db` gem:
200
+ The `issue-db` gem uses the [`Octokit.rb`](https://github.com/octokit/octokit.rb) library under the hood for interactions with the GitHub API. You have four options for authentication when using the `issue-db` gem:
198
201
 
199
202
  > Note: The order displayed below is also the order of priority that this Gem uses to authenticate.
200
203
 
201
204
  1. Pass in your own authenticated `Octokit.rb` instance to the `IssueDB.new` method
202
- 2. Use a GitHub App by setting the `ISSUE_DB_GITHUB_APP_ID`, `ISSUE_DB_GITHUB_APP_INSTALLATION_ID`, and `ISSUE_DB_GITHUB_APP_KEY` environment variables
203
- 3. Use a GitHub personal access token by setting the `ISSUE_DB_GITHUB_TOKEN` environment variable
205
+ 2. Pass GitHub App authentication parameters directly to the `IssueDB.new` method
206
+ 3. Use a GitHub App by setting the `ISSUE_DB_GITHUB_APP_ID`, `ISSUE_DB_GITHUB_APP_INSTALLATION_ID`, and `ISSUE_DB_GITHUB_APP_KEY` environment variables
207
+ 4. Use a GitHub personal access token by setting the `ISSUE_DB_GITHUB_TOKEN` environment variable
204
208
 
205
209
  > Using a GitHub App is the suggested method
206
210
 
@@ -215,7 +219,31 @@ require "issue_db"
215
219
  db = IssueDB.new("<org>/<repo>") # THAT'S IT! 🎉
216
220
  ```
217
221
 
218
- ### Using a GitHub App
222
+ ### Using GitHub App Parameters Directly
223
+
224
+ You can now pass GitHub App authentication parameters directly to the `IssueDB.new` method. This is especially useful when you want to manage authentication credentials in your application code or when you have multiple GitHub Apps for different purposes:
225
+
226
+ ```ruby
227
+ require "issue_db"
228
+
229
+ # Pass GitHub App credentials directly to IssueDB.new
230
+ db = IssueDB.new(
231
+ "<org>/<repo>",
232
+ app_id: 12345, # Your GitHub App ID
233
+ installation_id: 56789, # Your GitHub App Installation ID
234
+ app_key: "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----", # Your GitHub App private key
235
+ app_algo: "RS256" # Optional: defaults to RS256
236
+ )
237
+ ```
238
+
239
+ **Parameters:**
240
+
241
+ - `app_id` (Integer) - Your GitHub App ID (found on the App's settings page)
242
+ - `installation_id` (Integer) - Your GitHub App Installation ID (found in the installation URL: `https://github.com/organizations/<org>/settings/installations/<installation_id>`)
243
+ - `app_key` (String) - Your GitHub App private key (can be the key content as a string or a file path ending in `.pem`)
244
+ - `app_algo` (String, optional) - The algorithm to use for JWT signing (defaults to "RS256")
245
+
246
+ ### Using a GitHub App with Environment Variables
219
247
 
220
248
  This is the single best way to use the `issue-db` gem because GitHub Apps have increased rate limits, fine-grained permissions, and are more secure than using a personal access token. All you have to do is provide three environment variables and the `issue-db` gem will take care of the rest:
221
249
 
data/issue-db.gemspec CHANGED
@@ -4,7 +4,7 @@ require_relative "lib/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "issue-db"
7
- spec.version = Version::VERSION
7
+ spec.version = IssueDB::Version::VERSION
8
8
  spec.authors = ["runwaylab", "GrantBirki"]
9
9
  spec.license = "MIT"
10
10
 
@@ -3,37 +3,45 @@
3
3
  require "octokit"
4
4
  require_relative "utils/github"
5
5
 
6
- class AuthenticationError < StandardError; end
6
+ module IssueDB
7
+ class AuthenticationError < StandardError; end
7
8
 
8
- module Authentication
9
- def self.login(client = nil, log = nil)
10
- # if the client is not nil, use the pre-provided client
11
- unless client.nil?
12
- log.debug("using pre-provided client") if log
13
- return client
14
- end
9
+ module Authentication
10
+ def self.login(client = nil, log = nil, app_id: nil, installation_id: nil, app_key: nil, app_algo: nil)
11
+ # if the client is not nil, use the pre-provided client
12
+ unless client.nil?
13
+ log.debug("using pre-provided client") if log
14
+ return client
15
+ end
15
16
 
16
- # if the client is nil, check for GitHub App env vars first
17
- # first, check if all three of the following env vars are set and have values
18
- # ISSUE_DB_GITHUB_APP_ID, ISSUE_DB_GITHUB_APP_INSTALLATION_ID, ISSUE_DB_GITHUB_APP_KEY
19
- app_id = ENV.fetch("ISSUE_DB_GITHUB_APP_ID", nil)
20
- installation_id = ENV.fetch("ISSUE_DB_GITHUB_APP_INSTALLATION_ID", nil)
21
- app_key = ENV.fetch("ISSUE_DB_GITHUB_APP_KEY", nil)
22
- if app_id && installation_id && app_key
23
- log.debug("using github app authentication") if log
24
- return GitHub.new(log:, app_id:, installation_id:, app_key:)
25
- end
17
+ # if GitHub App parameters are provided, use them first
18
+ if app_id && installation_id && app_key
19
+ log.debug("using provided github app authentication parameters") if log
20
+ return IssueDB::Utils::GitHub.new(log:, app_id:, installation_id:, app_key:, app_algo:)
21
+ end
26
22
 
27
- # if the client is nil and no GitHub App env vars were found, check for the ISSUE_DB_GITHUB_TOKEN
28
- token = ENV.fetch("ISSUE_DB_GITHUB_TOKEN", nil)
29
- if token
30
- log.debug("using github token authentication") if log
31
- octokit = Octokit::Client.new(access_token: token, page_size: 100)
32
- octokit.auto_paginate = true
33
- return octokit
34
- end
23
+ # if the client is nil, check for GitHub App env vars
24
+ # first, check if all three of the following env vars are set and have values
25
+ # ISSUE_DB_GITHUB_APP_ID, ISSUE_DB_GITHUB_APP_INSTALLATION_ID, ISSUE_DB_GITHUB_APP_KEY
26
+ env_app_id = ENV.fetch("ISSUE_DB_GITHUB_APP_ID", nil)
27
+ env_installation_id = ENV.fetch("ISSUE_DB_GITHUB_APP_INSTALLATION_ID", nil)
28
+ env_app_key = ENV.fetch("ISSUE_DB_GITHUB_APP_KEY", nil)
29
+ if env_app_id && env_installation_id && env_app_key
30
+ log.debug("using github app authentication from environment variables") if log
31
+ return IssueDB::Utils::GitHub.new(log:, app_id: env_app_id, installation_id: env_installation_id, app_key: env_app_key)
32
+ end
35
33
 
36
- # if we make it here, no valid auth method succeeded
37
- raise AuthenticationError, "No valid GitHub authentication method was provided"
34
+ # if the client is nil and no GitHub App env vars were found, check for the ISSUE_DB_GITHUB_TOKEN
35
+ token = ENV.fetch("ISSUE_DB_GITHUB_TOKEN", nil)
36
+ if token
37
+ log.debug("using github token authentication") if log
38
+ octokit = Octokit::Client.new(access_token: token, page_size: 100)
39
+ octokit.auto_paginate = true
40
+ return octokit
41
+ end
42
+
43
+ # if we make it here, no valid auth method succeeded
44
+ raise AuthenticationError, "No valid GitHub authentication method was provided"
45
+ end
38
46
  end
39
47
  end
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Cache
4
- # A helper method to update all issues in the cache
5
- # :return: The updated issue cache as a list of issues
6
- def update_issue_cache!
7
- @log.debug("updating issue cache")
3
+ module IssueDB
4
+ module Cache
5
+ # A helper method to update all issues in the cache
6
+ # :return: The updated issue cache as a list of issues
7
+ def update_issue_cache!
8
+ @log.debug("updating issue cache")
8
9
 
9
- # find all issues in the repo that were created by this library
10
- query = "repo:#{@repo.full_name} label:#{@label}"
10
+ # find all issues in the repo that were created by this library
11
+ query = "repo:#{@repo.full_name} label:#{@label}"
11
12
 
12
- search_response = nil
13
- begin
14
- # issues structure: { "total_count": 0, "incomplete_results": false, "items": [<issues>] }
15
- search_response = @client.search_issues(query)
16
- rescue StandardError => e
17
- retry_err_msg = "error search_issues() call: #{e.message}"
18
- @log.error(retry_err_msg)
19
- raise StandardError, retry_err_msg
20
- end
13
+ search_response = nil
14
+ begin
15
+ # issues structure: { "total_count": 0, "incomplete_results": false, "items": [<issues>] }
16
+ search_response = @client.search_issues(query)
17
+ rescue StandardError => e
18
+ retry_err_msg = "error search_issues() call: #{e.message}"
19
+ @log.error(retry_err_msg)
20
+ raise StandardError, retry_err_msg
21
+ end
21
22
 
22
- # Safety check to ensure search_response and items are not nil
23
- if search_response.nil? || search_response.items.nil?
24
- @log.error("search_issues returned nil response or nil items")
25
- raise StandardError, "search_issues returned invalid response"
26
- end
23
+ # Safety check to ensure search_response and items are not nil
24
+ if search_response.nil? || search_response.items.nil?
25
+ @log.error("search_issues returned nil response or nil items")
26
+ raise StandardError, "search_issues returned invalid response"
27
+ end
27
28
 
28
- @log.debug("issue cache updated - cached #{search_response.total_count} issues")
29
- @issues = search_response.items
30
- @issues_last_updated = Time.now
31
- return @issues
29
+ @log.debug("issue cache updated - cached #{search_response.total_count} issues")
30
+ @issues = search_response.items
31
+ @issues_last_updated = Time.now
32
+ return @issues
33
+ end
32
34
  end
33
35
  end