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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 740a1a64de7f9ab45fd7932682999972139392b4c8d8f48105cde4f49e9474b1
|
4
|
+
data.tar.gz: 6219653cb7f2303482e039f906ae788e4d9f9a89131df12e750ef35cc0f8a976
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
68
|
+
This section goes into details on the following CRUD operations are available for the `issue-db` gem.
|
69
69
|
|
70
|
-
|
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
|
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.
|
203
|
-
3. Use a GitHub
|
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
|
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
@@ -3,37 +3,45 @@
|
|
3
3
|
require "octokit"
|
4
4
|
require_relative "utils/github"
|
5
5
|
|
6
|
-
|
6
|
+
module IssueDB
|
7
|
+
class AuthenticationError < StandardError; end
|
7
8
|
|
8
|
-
module Authentication
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
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
|
data/lib/issue_db/cache.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
10
|
+
# find all issues in the repo that were created by this library
|
11
|
+
query = "repo:#{@repo.full_name} label:#{@label}"
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|