review_request 0.2.0 → 0.3.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: 3807da4c709a72063fe999f4f5022cb5bc7ac6a354153b980db93502294fe62d
4
- data.tar.gz: 812756a3715c710624a8d3fbd95264955ccc6286a0320c954ffb0c29fe8b48bc
3
+ metadata.gz: 9b9bf004dc03f8df7375243f875688dcd4eb08ee5fd2b5002d900cada221349d
4
+ data.tar.gz: 9e7525c51654e9dd6815183626b7d4d45988f9ba09d046b078c237367f9bddf4
5
5
  SHA512:
6
- metadata.gz: fe0cf997434f0aeaea128bba17e612651fb14ff7b5280a202e4ab56e7d4174d440b17655b856ca314c7d17ecc1f6876138f8a53002a7b34b594b170a33f38c08
7
- data.tar.gz: 25596db07aeb7b223caa731e95b8b202f9bcf80180484309e02c8c1ab7cf39b74de3476961cad6ef669580e464371b0e95cf2140ebc62cc9af7aed29462ff791
6
+ metadata.gz: 2439810b6e7840718b0775f97966bf24938f2afe543124792efed8cc3362bc8c12f2a46a68d1881ce4bc5d724411b6c6930dcbacf7d9e05777e62608ca15423b
7
+ data.tar.gz: 8db09e6f6bba16707410a110c7642d441b3bbd425293d28a8f60c2a35fd99ccc50f93c788acc57fe42c336d554b20570e03037eeeea2c236d49c9fd2973c8f59
data/CHANGELOG.md CHANGED
@@ -4,15 +4,26 @@ 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.3.0] - 2026-11-20
8
+
9
+ ### Changed
10
+
11
+ - Slack API calls now use the [`slack-ruby-client`](https://github.com/slack-ruby/slack-ruby-client) gem. The public interface, retry policy, and error behavior are unchanged.
12
+
13
+ ### Added
14
+
15
+ - `slack-ruby-client` (`~> 3.3`) runtime dependency.
16
+
7
17
  ## [0.2.0] - 2026-11-20
8
18
 
9
19
  ### Changed
10
20
 
11
21
  - 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.
22
+ - Requires Ruby 3.3 or newer (was 3.2). A RuboCop dependency needs Ruby 3.3, so 3.2 can no longer install the gem's dependencies.
12
23
 
13
24
  ### Added
14
25
 
15
- - `octokit` runtime dependency (`~> 10.0`).
26
+ - `octokit` (`~> 10.0`) runtime dependency.
16
27
 
17
28
  ## [0.1.0] - 2026-11-20
18
29
 
data/CLAUDE.md CHANGED
@@ -21,7 +21,8 @@ The gem lives in `lib/review_request/`. It has no web framework dependency. Call
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
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
+ - `slack.rb`: Slack client built on the `slack-ruby-client` gem. It keeps the retry policy, maps the gem's exceptions onto this gem's error classes, and converts responses to plain string-keyed hashes.
25
+ - `jira.rb`: Jira client on top of `http_client.rb` (`Net::HTTP`, no extra gems).
25
26
  - `messages.rb` and `message_templates.rb`: Slack text. Templates use `{placeholder}` syntax, and `Messages.render` raises on unknown placeholders.
26
27
  - `retry.rb`: retries transient `APIError`s with back-off. Tests set `ReviewRequest::Retry.sleeper` to a no-op.
27
28
  - `cache.rb`: thread-safe TTL cache used by GitHub (300 s) and Slack usergroups (24 h).
data/README.md CHANGED
@@ -22,7 +22,7 @@ gem "review_request"
22
22
  gem install review_request
23
23
  ```
24
24
 
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`.
25
+ Runtime dependencies are `octokit` (GitHub API, GitHub's official Ruby client), `slack-ruby-client` (Slack Web API), `dotenv` (used by the CLI), and `logger`. Jira calls use the standard library's `Net::HTTP`.
26
26
 
27
27
  ## Configuration
28
28
 
@@ -1,46 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "slack-ruby-client"
3
4
  require "time"
4
5
  require_relative "errors"
5
- require_relative "http_client"
6
6
  require_relative "retry"
7
7
  require_relative "support"
8
8
 
9
9
  module ReviewRequest
10
- # Slack Web API client. Every call retries transient failures (see Retry).
10
+ # Slack client built on the slack-ruby-client gem. Every call retries transient failures (see Retry).
11
+ # Responses are returned as plain string-keyed hashes. Gem errors are translated into this gem's
12
+ # error classes, so callers keep the same rescue behavior.
11
13
  class Slack
12
- API_URL = "https://slack.com/api"
14
+ OPEN_TIMEOUT = 10
15
+ READ_TIMEOUT = 20
13
16
  # Asia/Bangkok is UTC+7 year-round (no DST), so a fixed offset is exact.
14
17
  SCHEDULE_OFFSET = "+0700"
15
18
 
16
19
  attr_reader :token, :channel_ids
17
20
 
18
- def initialize(token:, channel_ids: [], http: HTTPClient.new)
21
+ # `client:` lets tests inject a Slack::Web::Client. By default one is built from `token`.
22
+ def initialize(token:, channel_ids: [], client: nil)
19
23
  @token = token
20
24
  @channel_ids = Array(channel_ids)
21
- @http = http
25
+ @client = client || ::Slack::Web::Client.new(token:, timeout: READ_TIMEOUT, open_timeout: OPEN_TIMEOUT)
22
26
  end
23
27
 
24
28
  # Maps "@handle" => usergroup ID for every usergroup in the workspace.
25
29
  def usergroups
26
- data = api("usergroups.list")
30
+ data = api(:usergroups_list)
27
31
  data.fetch("usergroups", []).to_h { |group| ["@#{group["handle"]}", group["id"]] }
28
32
  end
29
33
 
30
34
  def user_info(user_id)
31
- api("users.info", user: user_id).fetch("user")
35
+ api(:users_info, user: user_id).fetch("user")
32
36
  end
33
37
 
34
38
  # Returns the Slack user ID for an email, or nil if it can't be found.
35
39
  def lookup_user_by_email(email)
36
- api("users.lookupByEmail", email:).dig("user", "id")
40
+ api(:users_lookupByEmail, email:).dig("user", "id")
37
41
  rescue APIError => e
38
42
  ReviewRequest.logger.warn("Failed to lookup user by email '#{email}': #{e.message}")
39
43
  nil
40
44
  end
41
45
 
42
46
  def usergroup_members(usergroup_id)
43
- api("usergroups.users.list", usergroup: usergroup_id).fetch("users", [])
47
+ api(:usergroups_users_list, usergroup: usergroup_id).fetch("users", [])
44
48
  rescue APIError => e
45
49
  ReviewRequest.logger.error("Failed to get usergroup members for #{usergroup_id}: #{e.message}")
46
50
  []
@@ -49,7 +53,7 @@ module ReviewRequest
49
53
  # Posts `text` to every configured channel. Returns one response per channel.
50
54
  def post_message(text, username: nil, icon_url: nil, icon_emoji: nil)
51
55
  each_channel do |channel|
52
- api("chat.postMessage", channel:, text:, username:, icon_url:, icon_emoji:)
56
+ api(:chat_postMessage, channel:, text:, username:, icon_url:, icon_emoji:)
53
57
  end
54
58
  end
55
59
 
@@ -58,7 +62,7 @@ module ReviewRequest
58
62
  def schedule_message_with_timezone(text, scheduled_date)
59
63
  post_at = self.class.scheduled_timestamp(scheduled_date)
60
64
  each_channel do |channel|
61
- api("chat.scheduleMessage", channel:, text:, post_at:)
65
+ api(:chat_scheduleMessage, channel:, text:, post_at:)
62
66
  end
63
67
  end
64
68
 
@@ -85,35 +89,34 @@ module ReviewRequest
85
89
  results
86
90
  end
87
91
 
92
+ # Calls the gem method `method` with `payload` (nil values dropped), retrying transient failures.
88
93
  def api(method, payload = {})
89
94
  body = payload.compact
90
95
  Retry.with_retries do
91
- response = @http.post_json(
92
- "#{API_URL}/#{method}",
93
- body:,
94
- headers: { "Authorization" => "Bearer #{token}" }
95
- )
96
- handle_response(method, response, body)
96
+ translate_errors(body) { plain(@client.public_send(method, **body)) }
97
97
  end
98
98
  end
99
99
 
100
- def handle_response(method, response, body)
101
- unless response.ok?
102
- raise SlackError.new("Slack #{method} returned HTTP #{response.status}", status: response.status)
103
- end
104
-
105
- data = response.json
106
- raise SlackError, "Slack #{method} returned a non-JSON response" unless data.is_a?(Hash)
107
- return data if data["ok"]
108
-
109
- code = data["error"].to_s
110
- if code == "channel_not_found"
111
- raise ChannelNotFoundError,
112
- "Channel #{body[:channel]} not found. For private channels, invite the bot first " \
113
- "(e.g. /invite @bot-name)."
114
- end
100
+ # Converts the gem's response (a Hashie::Mash) into a plain Hash with string keys.
101
+ def plain(response)
102
+ response.respond_to?(:to_hash) ? response.to_hash : response
103
+ end
115
104
 
116
- raise SlackError.new("Slack #{method} failed: #{code}", code:)
105
+ # Maps slack-ruby-client exceptions onto this gem's error classes.
106
+ def translate_errors(body)
107
+ yield
108
+ rescue ::Slack::Web::Api::Errors::ChannelNotFound
109
+ raise ChannelNotFoundError,
110
+ "Channel #{body[:channel]} not found. For private channels, invite the bot first " \
111
+ "(e.g. /invite @bot-name)."
112
+ rescue ::Slack::Web::Api::Errors::TooManyRequestsError => e
113
+ raise SlackError.new("Slack rate limit reached; retry after #{e.retry_after} seconds", status: 429)
114
+ rescue ::Slack::Web::Api::Errors::SlackError => e
115
+ # The API answered ok: false. e.message holds the Slack error code, e.g. "not_in_channel".
116
+ raise SlackError.new("Slack request failed: #{e.message}", code: e.message)
117
+ rescue ::Faraday::Error => e
118
+ # 5xx responses (ServerError), timeouts, and connection failures. No status is set, so these are transient.
119
+ raise SlackError.new("Slack request failed: #{e.class}: #{e.message}", status: nil)
117
120
  end
118
121
  end
119
122
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReviewRequest
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Nguyen
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '10.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: slack-ruby-client
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.3'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.3'
54
68
  description: Send Slack review requests for GitHub pull requests, post daily digests
55
69
  of PRs awaiting a team's review, and alert on overdue or closed Jira sprints.
56
70
  executables: