Class: CollavreGithub::GithubPrChannel
- Inherits:
-
Collavre::Channel
- Object
- Collavre::Channel
- CollavreGithub::GithubPrChannel
- Defined in:
- app/models/collavre_github/github_pr_channel.rb
Constant Summary collapse
- PR_STATES =
PR lifecycle state used by the chip badge color. Defaults to “open” so freshly attached channels render the green badge before any close event has been received. Persisted in ‘config` to avoid a schema change for a channel-subtype-specific concern.
%w[open merged closed_without_merge].freeze
Instance Method Summary collapse
- #attached_message ⇒ Object
- #badge_state ⇒ Object
- #badge_title ⇒ Object
-
#default_label ⇒ Object
Chip fallbacks: derived directly from config so the chip can render the full “PR #N” + URL immediately on attach, without waiting for the first webhook event to populate latest_label / latest_link.
- #default_link ⇒ Object
- #handle(event:, payload:) ⇒ Object
- #label ⇒ Object
- #pr_number ⇒ Object
- #pr_state ⇒ Object
-
#pr_state=(value) ⇒ Object
Symmetric with the reader: refuse to persist values outside PR_STATES rather than silently downgrading to “open” at read time.
- #pr_url ⇒ Object
- #reopened_message ⇒ Object
- #repo_full_name ⇒ Object
Instance Method Details
#attached_message ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 61 def Collavre::Channel::InjectedMessage.new( speaker: channel_bot_user, message: t("attached_message", label: label, url: pr_url), label: label, link: pr_url ) end |
#badge_state ⇒ Object
32 33 34 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 32 def badge_state pr_state end |
#badge_title ⇒ Object
36 37 38 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 36 def badge_title I18n.t("collavre_github.channel.pr.badge.#{pr_state}", default: pr_state.to_s) end |
#default_label ⇒ Object
Chip fallbacks: derived directly from config so the chip can render the full “PR #N” + URL immediately on attach, without waiting for the first webhook event to populate latest_label / latest_link.
24 25 26 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 24 def default_label label end |
#default_link ⇒ Object
28 29 30 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 28 def default_link pr_url end |
#handle(event:, payload:) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 79 def handle(event:, payload:) case event when "issue_comment" handle_issue_comment(payload) when "pull_request_review_comment" handle_review_comment(payload) when "pull_request_review" handle_review_submitted(payload) when "pull_request" handle_pull_request(payload) end end |
#label ⇒ Object
17 18 19 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 17 def label t("label", number: pr_number) end |
#pr_number ⇒ Object
9 10 11 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 9 def pr_number config["pr_number"].to_i end |
#pr_state ⇒ Object
46 47 48 49 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 46 def pr_state state = config["pr_state"].to_s PR_STATES.include?(state) ? state : "open" end |
#pr_state=(value) ⇒ Object
Symmetric with the reader: refuse to persist values outside PR_STATES rather than silently downgrading to “open” at read time. Without this any caller that mistypes (e.g. “merged_”) would corrupt the badge color with no error surfaced.
55 56 57 58 59 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 55 def pr_state=(value) value = value.to_s raise ArgumentError, "Invalid pr_state: #{value.inspect}" unless PR_STATES.include?(value) self.config = config.merge("pr_state" => value) end |
#pr_url ⇒ Object
13 14 15 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 13 def pr_url "https://github.com/#{repo_full_name}/pull/#{pr_number}" end |
#reopened_message ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 70 def Collavre::Channel::InjectedMessage.new( speaker: channel_bot_user, message: t("reopened_message", label: label, url: pr_url), label: label, link: pr_url ) end |
#repo_full_name ⇒ Object
5 6 7 |
# File 'app/models/collavre_github/github_pr_channel.rb', line 5 def repo_full_name config["repo_full_name"] end |