Class: Agents::GithubNotificationsAgent
- Inherits:
-
Agent
- Object
- Agent
- Agents::GithubNotificationsAgent
- Defined in:
- lib/huginn_github_notifications_agent/github_notifications_agent.rb
Instance Method Summary collapse
-
#check ⇒ Object
TODO: Fix rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
- #default_options ⇒ Object
- #validate_options ⇒ Object
- #working? ⇒ Boolean
Instance Method Details
#check ⇒ Object
TODO: Fix rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/huginn_github_notifications_agent/github_notifications_agent.rb', line 57 def check response = HTTParty.get base_url, # If there are no new notifications, you will get a "304 Not Modified" return if response.code == 304 notifications = JSON.parse(response.body) if response.code > 400 error("Error during http request: #{response.body}") return end notifications.each do |notif| data = notif['subject'].merge( repo_name: notif['repository']['full_name'] ) subject = ::HuginnGithubNotificationsAgent::Subject.new(data) notif['subject'] = subject.to_h end if emit_single_event? create_event payload: { notifications: notifications } else notifications.each { |notification| create_event payload: notification } end memory[:last_modified] = response.headers['last-modified'] end |
#default_options ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/huginn_github_notifications_agent/github_notifications_agent.rb', line 31 def { 'access_token' => 'my_gh_access_token', 'events' => 'multiple', 'last_modified' => true } end |
#validate_options ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/huginn_github_notifications_agent/github_notifications_agent.rb', line 39 def unless ['access_token'].present? errors.add(:base, 'access_token is required ') end # rubocop:disable Style/GuardClause if last_modified.present? && boolify(last_modified).nil? errors.add(:base, 'last_modified must be a boolean value') end # rubocop:enable Style/GuardClause end |
#working? ⇒ Boolean
50 51 52 |
# File 'lib/huginn_github_notifications_agent/github_notifications_agent.rb', line 50 def working? !recent_error_logs? end |