Class: CollavreGithub::WebhookProvisioner
- Inherits:
-
Object
- Object
- CollavreGithub::WebhookProvisioner
- Defined in:
- app/services/collavre_github/webhook_provisioner.rb
Constant Summary collapse
- CHANNEL_EVENTS =
PR channel webhooks need every event GithubPrChannel handles. Without ‘issue_comment` / `pull_request_review` / `pull_request_review_comment` GitHub never delivers the relevant deliveries, so pr_monitor would attach a channel that silently misses comments. `pull_request` is required by the auto-attach + close detection paths.
%w[issue_comment pull_request_review pull_request_review_comment].freeze
- EVENTS =
(%w[pull_request] + CHANNEL_EVENTS).freeze
- EVENTS_WITH_PUSH =
(%w[pull_request push] + CHANNEL_EVENTS).freeze
- CONTENT_TYPE =
"json".freeze
Class Method Summary collapse
- .ensure_for_links(account:, links:, webhook_url:) ⇒ Object
- .remove_for_repositories(account:, repositories:, webhook_url:) ⇒ Object
Instance Method Summary collapse
-
#ensure_for_links(links) ⇒ Object
Returns [[link, status], …] so callers can detect silent GitHub rejections.
-
#initialize(account:, webhook_url:, client: CollavreGithub::Client.new(account)) ⇒ WebhookProvisioner
constructor
A new instance of WebhookProvisioner.
- #remove_for_repositories(repositories) ⇒ Object
Constructor Details
#initialize(account:, webhook_url:, client: CollavreGithub::Client.new(account)) ⇒ WebhookProvisioner
Returns a new instance of WebhookProvisioner.
21 22 23 24 |
# File 'app/services/collavre_github/webhook_provisioner.rb', line 21 def initialize(account:, webhook_url:, client: CollavreGithub::Client.new(account)) @client = client @webhook_url = webhook_url end |
Class Method Details
.ensure_for_links(account:, links:, webhook_url:) ⇒ Object
13 14 15 |
# File 'app/services/collavre_github/webhook_provisioner.rb', line 13 def self.ensure_for_links(account:, links:, webhook_url:) new(account: account, webhook_url: webhook_url).ensure_for_links(Array(links)) end |
.remove_for_repositories(account:, repositories:, webhook_url:) ⇒ Object
17 18 19 |
# File 'app/services/collavre_github/webhook_provisioner.rb', line 17 def self.remove_for_repositories(account:, repositories:, webhook_url:) new(account: account, webhook_url: webhook_url).remove_for_repositories(Array(repositories)) end |
Instance Method Details
#ensure_for_links(links) ⇒ Object
Returns [[link, status], …] so callers can detect silent GitHub rejections. status is one of:
:created - new hook created
:updated - existing hook patched (events/url/secret)
:secret_aligned - non-primary link with existing hook; only the local
RepositoryLink secret was aligned. No GitHub call.
:failed - Octokit/Faraday error OR Client returned nil
33 34 35 |
# File 'app/services/collavre_github/webhook_provisioner.rb', line 33 def ensure_for_links(links) links.map { |link| [ link, ensure_webhook(link) ] } end |
#remove_for_repositories(repositories) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/collavre_github/webhook_provisioner.rb', line 37 def remove_for_repositories(repositories) # Batch-query to avoid N+1: find all repo names that still have links linked_names = CollavreGithub::RepositoryLink .where(repository_full_name: repositories) .distinct .pluck(:repository_full_name) .to_set repositories.each do |repository_full_name| next if linked_names.include?(repository_full_name) remove_webhook(repository_full_name) end end |