Class: Soba::Services::SlackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/soba/services/slack_notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url:) ⇒ SlackNotifier

Returns a new instance of SlackNotifier.



9
10
11
# File 'lib/soba/services/slack_notifier.rb', line 9

def initialize(webhook_url:)
  @webhook_url = webhook_url
end

Class Method Details

.from_configObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/soba/services/slack_notifier.rb', line 69

def self.from_config
  config = Soba::Configuration.config
  return unless config.slack.notifications_enabled

  webhook_url = config.slack.webhook_url
  # 環境変数形式の場合は展開
  if webhook_url&.match?(/\$\{([^}]+)\}/)
    var_name = webhook_url.match(/\$\{([^}]+)\}/)[1]
    webhook_url = ENV[var_name]
  end

  new(webhook_url: webhook_url)
end

.from_envObject



65
66
67
# File 'lib/soba/services/slack_notifier.rb', line 65

def self.from_env
  new(webhook_url: ENV["SLACK_WEBHOOK_URL"])
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/soba/services/slack_notifier.rb', line 61

def enabled?
  @webhook_url.present?
end

#notify_issue_merged(merge_data) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/soba/services/slack_notifier.rb', line 37

def notify_issue_merged(merge_data)
  return false unless enabled?

  logger.debug "Starting Slack notification for merged issue ##{merge_data[:issue_number]}"

  begin
    message = build_merged_message(merge_data)
    logger.debug "Sending notification to Slack webhook"

    response = send_notification(message)

    if response.success?
      logger.debug "Slack notification sent successfully (HTTP #{response.status})"
      true
    else
      logger.warn("Failed to send Slack notification: HTTP #{response.status}")
      false
    end
  rescue StandardError => e
    logger.warn("Error sending Slack notification: #{e.message}")
    false
  end
end

#notify_phase_start(issue_data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/soba/services/slack_notifier.rb', line 13

def notify_phase_start(issue_data)
  return false unless enabled?

  logger.debug "Starting Slack notification for issue ##{issue_data[:number]}, phase: #{issue_data[:phase]}"

  begin
    message = build_message(issue_data)
    logger.debug "Sending notification to Slack webhook"

    response = send_notification(message)

    if response.success?
      logger.debug "Slack notification sent successfully (HTTP #{response.status})"
      true
    else
      logger.warn("Failed to send Slack notification: HTTP #{response.status}")
      false
    end
  rescue StandardError => e
    logger.warn("Error sending Slack notification: #{e.message}")
    false
  end
end