review_request 0.1.0 → 0.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/CHANGELOG.md +10 -0
- data/CLAUDE.md +2 -1
- data/README.md +3 -3
- data/lib/review_request/github.rb +52 -29
- data/lib/review_request/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3807da4c709a72063fe999f4f5022cb5bc7ac6a354153b980db93502294fe62d
|
|
4
|
+
data.tar.gz: 812756a3715c710624a8d3fbd95264955ccc6286a0320c954ffb0c29fe8b48bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe0cf997434f0aeaea128bba17e612651fb14ff7b5280a202e4ab56e7d4174d440b17655b856ca314c7d17ecc1f6876138f8a53002a7b34b594b170a33f38c08
|
|
7
|
+
data.tar.gz: 25596db07aeb7b223caa731e95b8b202f9bcf80180484309e02c8c1ab7cf39b74de3476961cad6ef669580e464371b0e95cf2140ebc62cc9af7aed29462ff791
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@ All notable changes to this project are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.2.0] - 2026-11-20
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- GitHub API calls now use the official [`octokit`](https://github.com/octokit/octokit.rb) gem. The TTL cache, retry policy, and PR filtering are unchanged.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `octokit` runtime dependency (`~> 10.0`).
|
|
16
|
+
|
|
7
17
|
## [0.1.0] - 2026-11-20
|
|
8
18
|
|
|
9
19
|
Initial release. A Ruby port of the review-request Python package.
|
data/CLAUDE.md
CHANGED
|
@@ -20,7 +20,8 @@ The gem lives in `lib/review_request/`. It has no web framework dependency. Call
|
|
|
20
20
|
|
|
21
21
|
- `send_message.rb` (`SendMessage`): parses a Slack slash-command payload, fetches the PR, and posts or schedules the message.
|
|
22
22
|
- `pr_reminder_service.rb`, `jira_overdue_reminder_service.rb`, `jira_sprint_notification_service.rb`: the three scheduled and webhook features.
|
|
23
|
-
- `github.rb
|
|
23
|
+
- `github.rb`: GitHub client built on the official `octokit` gem. It adds the TTL cache, the retry policy, and the PR filtering. It converts Octokit's Sawyer resources to plain string-keyed hashes, and it translates Octokit and Faraday errors into `GitHubError`.
|
|
24
|
+
- `slack.rb`, `jira.rb`: API clients on top of `http_client.rb` (`Net::HTTP`, no extra gems).
|
|
24
25
|
- `messages.rb` and `message_templates.rb`: Slack text. Templates use `{placeholder}` syntax, and `Messages.render` raises on unknown placeholders.
|
|
25
26
|
- `retry.rb`: retries transient `APIError`s with back-off. Tests set `ReviewRequest::Retry.sleeper` to a no-op.
|
|
26
27
|
- `cache.rb`: thread-safe TTL cache used by GitHub (300 s) and Slack usergroups (24 h).
|
data/README.md
CHANGED
|
@@ -11,7 +11,7 @@ There is no web framework dependency. Call the services from any Ruby applicatio
|
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
Requires Ruby 3.
|
|
14
|
+
Requires Ruby 3.3+.
|
|
15
15
|
|
|
16
16
|
```ruby
|
|
17
17
|
# Gemfile
|
|
@@ -22,7 +22,7 @@ gem "review_request"
|
|
|
22
22
|
gem install review_request
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Runtime dependencies are `dotenv` (used by the CLI) and `logger`.
|
|
25
|
+
Runtime dependencies are `octokit` (GitHub API, GitHub's official Ruby client), `dotenv` (used by the CLI), and `logger`. Slack and Jira calls use the standard library's `Net::HTTP`.
|
|
26
26
|
|
|
27
27
|
## Configuration
|
|
28
28
|
|
|
@@ -229,7 +229,7 @@ bundle exec rubocop # lint only
|
|
|
229
229
|
|
|
230
230
|
Tests use Minitest and WebMock. Real network calls are blocked, and retry back-off is disabled.
|
|
231
231
|
|
|
232
|
-
CI runs on every pull request when it is opened, marked ready for review, or reopened. It runs the tests and RuboCop on Ruby 3.
|
|
232
|
+
CI runs on every pull request when it is opened, marked ready for review, or reopened. It runs the tests and RuboCop on Ruby 3.3, 3.4, and 4.0. See `.github/workflows/ci.yml`.
|
|
233
233
|
|
|
234
234
|
## Releasing
|
|
235
235
|
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "octokit"
|
|
4
|
+
require "sawyer"
|
|
3
5
|
require "time"
|
|
4
|
-
require "uri"
|
|
5
6
|
require_relative "cache"
|
|
6
7
|
require_relative "errors"
|
|
7
|
-
require_relative "http_client"
|
|
8
8
|
require_relative "retry"
|
|
9
9
|
require_relative "support"
|
|
10
10
|
|
|
11
11
|
module ReviewRequest
|
|
12
|
-
# GitHub
|
|
12
|
+
# GitHub client for pull requests and team review requests. HTTP is handled by the official
|
|
13
|
+
# Octokit client. This class adds the TTL cache, the retry policy (see Retry), and the
|
|
14
|
+
# filtering rules. Responses are returned as plain string-keyed hashes, not Sawyer resources.
|
|
13
15
|
class GitHub
|
|
14
|
-
API_URL = "https://api.github.com"
|
|
15
16
|
IGNORED_AUTHORS = ["dependabot[bot]"].freeze
|
|
16
17
|
SECONDS_PER_DAY = 86_400
|
|
18
|
+
OPEN_TIMEOUT = 10
|
|
19
|
+
READ_TIMEOUT = 20
|
|
17
20
|
|
|
18
21
|
# Shared across instances, like the Python package's class-level cache.
|
|
19
22
|
CACHE = Cache.new(max_size: 200, ttl: 300)
|
|
20
23
|
|
|
21
24
|
attr_reader :token, :organization, :repo, :pull_request_number
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
# `client:` lets tests inject an Octokit::Client. By default one is built from `token`.
|
|
27
|
+
def initialize(token:, organization:, repo:, pull_request_number: nil, use_cache: true, client: nil)
|
|
24
28
|
if [token, organization, repo].any? { |value| Support.blank?(value) }
|
|
25
29
|
raise GitHubError, "Missing required parameters"
|
|
26
30
|
end
|
|
@@ -30,20 +34,24 @@ module ReviewRequest
|
|
|
30
34
|
@repo = repo
|
|
31
35
|
@pull_request_number = pull_request_number
|
|
32
36
|
@use_cache = use_cache
|
|
33
|
-
@
|
|
37
|
+
@client = client || Octokit::Client.new(
|
|
38
|
+
access_token: token,
|
|
39
|
+
connection_options: { request: { open_timeout: OPEN_TIMEOUT, timeout: READ_TIMEOUT } }
|
|
40
|
+
)
|
|
34
41
|
end
|
|
35
42
|
|
|
36
|
-
def
|
|
37
|
-
"#{
|
|
43
|
+
def full_name
|
|
44
|
+
"#{organization}/#{repo}"
|
|
38
45
|
end
|
|
39
46
|
|
|
40
47
|
def pr_details
|
|
41
|
-
|
|
48
|
+
number = require_pull_request_number
|
|
49
|
+
fetch([:pull_request, full_name, number]) { @client.pull_request(full_name, number) }
|
|
42
50
|
end
|
|
43
51
|
|
|
44
52
|
# Comma-separated "@team" names of teams requested as reviewers, or "" on failure.
|
|
45
53
|
def pr_reviewers
|
|
46
|
-
teams =
|
|
54
|
+
teams = review_requests(require_pull_request_number).fetch("teams", [])
|
|
47
55
|
teams.map { |team| "@#{team["name"]}" }.join(", ")
|
|
48
56
|
rescue APIError => e
|
|
49
57
|
ReviewRequest.logger.error("Failed to get PR reviewers: #{e.message}")
|
|
@@ -51,8 +59,10 @@ module ReviewRequest
|
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
def open_prs(base_branch: "main")
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
data = fetch([:open_prs, full_name, base_branch]) do
|
|
63
|
+
@client.pull_requests(full_name, state: "open", base: base_branch, sort: "updated", direction: "desc",
|
|
64
|
+
per_page: 100)
|
|
65
|
+
end
|
|
56
66
|
data.is_a?(Array) ? data : []
|
|
57
67
|
rescue APIError => e
|
|
58
68
|
ReviewRequest.logger.error("Failed to get open PRs: #{e.message}")
|
|
@@ -116,14 +126,18 @@ module ReviewRequest
|
|
|
116
126
|
|
|
117
127
|
private
|
|
118
128
|
|
|
119
|
-
def
|
|
129
|
+
def require_pull_request_number
|
|
120
130
|
raise GitHubError, "pull_request_number is required for this call" if Support.blank?(pull_request_number)
|
|
121
131
|
|
|
122
|
-
|
|
132
|
+
pull_request_number
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def review_requests(number)
|
|
136
|
+
fetch([:review_requests, full_name, number]) { @client.pull_request_review_requests(full_name, number) }
|
|
123
137
|
end
|
|
124
138
|
|
|
125
139
|
def team_requested?(number, team_slug)
|
|
126
|
-
teams =
|
|
140
|
+
teams = review_requests(number).fetch("teams", [])
|
|
127
141
|
teams.any? { |team| team["slug"] == team_slug }
|
|
128
142
|
rescue APIError => e
|
|
129
143
|
ReviewRequest.logger.warn("Failed to get reviewers for PR ##{number}: #{e.message}")
|
|
@@ -131,34 +145,43 @@ module ReviewRequest
|
|
|
131
145
|
end
|
|
132
146
|
|
|
133
147
|
def reviews(number)
|
|
134
|
-
data =
|
|
148
|
+
data = fetch([:reviews, full_name, number]) { @client.pull_request_reviews(full_name, number) }
|
|
135
149
|
data.is_a?(Array) ? data : []
|
|
136
150
|
rescue APIError => e
|
|
137
151
|
ReviewRequest.logger.warn("Failed to get reviews for PR ##{number}: #{e.message}")
|
|
138
152
|
[]
|
|
139
153
|
end
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
# Returns a cached response when one is fresh. Otherwise runs the Octokit call under the retry policy,
|
|
156
|
+
# converts the result to plain hashes, and caches it. Errors are raised as GitHubError (an APIError).
|
|
157
|
+
def fetch(key)
|
|
142
158
|
if @use_cache
|
|
143
|
-
cached = CACHE.get(
|
|
159
|
+
cached = CACHE.get(key)
|
|
144
160
|
return cached unless cached.nil?
|
|
145
161
|
end
|
|
146
162
|
|
|
147
|
-
data = Retry.with_retries {
|
|
148
|
-
CACHE.set(
|
|
163
|
+
data = Retry.with_retries { translate_errors { plain(yield) } }
|
|
164
|
+
CACHE.set(key, data) if @use_cache
|
|
149
165
|
data
|
|
150
166
|
end
|
|
151
167
|
|
|
152
|
-
def
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
end
|
|
168
|
+
def translate_errors
|
|
169
|
+
yield
|
|
170
|
+
rescue Octokit::Error => e
|
|
171
|
+
raise GitHubError.new("GitHub API error: #{e.response_status} #{e.message}", status: e.response_status)
|
|
172
|
+
rescue Faraday::Error => e
|
|
173
|
+
raise GitHubError.new("GitHub request failed: #{e.class}: #{e.message}", status: nil)
|
|
174
|
+
end
|
|
160
175
|
|
|
161
|
-
|
|
176
|
+
# Converts Sawyer resources and Time values into plain Hash/Array/String data with string keys.
|
|
177
|
+
def plain(value)
|
|
178
|
+
case value
|
|
179
|
+
when Sawyer::Resource then plain(value.to_attrs)
|
|
180
|
+
when Hash then value.to_h { |key, item| [key.to_s, plain(item)] }
|
|
181
|
+
when Array then value.map { |item| plain(item) }
|
|
182
|
+
when Time then value.getutc.iso8601
|
|
183
|
+
else value
|
|
184
|
+
end
|
|
162
185
|
end
|
|
163
186
|
end
|
|
164
187
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: review_request
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bradley Nguyen
|
|
@@ -37,6 +37,20 @@ dependencies:
|
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '1.6'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: octokit
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '10.0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '10.0'
|
|
40
54
|
description: Send Slack review requests for GitHub pull requests, post daily digests
|
|
41
55
|
of PRs awaiting a team's review, and alert on overdue or closed Jira sprints.
|
|
42
56
|
executables:
|
|
@@ -84,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
84
98
|
requirements:
|
|
85
99
|
- - ">="
|
|
86
100
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '3.
|
|
101
|
+
version: '3.3'
|
|
88
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
103
|
requirements:
|
|
90
104
|
- - ">="
|