Class: Tutter
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Tutter
- Defined in:
- lib/tutter.rb
Overview
Modular sinatra app Tutter
Instance Method Summary collapse
-
#actions_for_event(event, config) ⇒ Object
Return actions for event from config.
- #octokit_client(config) ⇒ Object
- #prepare_actions(project, event, data, config) ⇒ Object
-
#project_settings(project) ⇒ Object
Return project settings from config.
- #try_actions(event, data, project, config) ⇒ Object
- #verify_signature(payload_body, secret_token) ⇒ Object
Instance Method Details
#actions_for_event(event, config) ⇒ Object
Return actions for event from config
41 42 43 44 45 |
# File 'lib/tutter.rb', line 41 def actions_for_event(event, config) config['actions'][event] || error(404, "No Actions for #{event} in tutter.conf" ) end |
#octokit_client(config) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tutter.rb', line 47 def octokit_client(config) Octokit.configure do |c| c.api_endpoint = config['github_api_endpoint'] c.web_endpoint = config['github_site'] c.auto_paginate = config['github_api_auto_paginate'] or false end if config['access_token_env_var'] access_token = ENV[config['access_token_env_var']] || '' else access_token = config['access_token'] || '' end Octokit::Client.new access_token: access_token end |
#prepare_actions(project, event, data, config) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tutter.rb', line 63 def prepare_actions(project, event, data, config) client = octokit_client(config) actions_for_event(event, config).each do |a| yield Action.create(a, config['action_settings'], client, project, event, data), a end end |
#project_settings(project) ⇒ Object
Return project settings from config
33 34 35 36 37 38 |
# File 'lib/tutter.rb', line 33 def project_settings(project) settings.config['projects'].each do |p| return p if p['name'] == project end error(404, 'Project does not exist in tutter.conf') end |
#try_actions(event, data, project, config) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tutter.rb', line 75 def try_actions(event, data, project, config) responses = { event: event, responses: {} } prepare_actions(project, event, data, config) do |action, name| status_code, = action.run responses[:responses][name] = { status_code: status_code, message: } break if status_code != 200 end [responses[:responses].values.last[:status_code], responses.to_json] end |
#verify_signature(payload_body, secret_token) ⇒ Object
27 28 29 30 |
# File 'lib/tutter.rb', line 27 def verify_signature(payload_body, secret_token) signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret_token, payload_body) return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE']) end |