Class: Writefully::Tools::Hammer

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/writefully/tools/hammer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Hammer

Returns a new instance of Hammer.



8
9
10
11
# File 'lib/writefully/tools/hammer.rb', line 8

def initialize message
  @message = message
  @api = Github.new oauth_token: message[:auth_token]
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



6
7
8
# File 'lib/writefully/tools/hammer.rb', line 6

def api
  @api
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/writefully/tools/hammer.rb', line 6

def message
  @message
end

Instance Method Details

#add_hook_for(repo_name) ⇒ Object



32
33
34
35
36
37
# File 'lib/writefully/tools/hammer.rb', line 32

def add_hook_for repo_name
  Writefully.logger.info "Adding hook for #{message[:site_slug]}"
  api.repos.hooks.create message[:user_name], repo_name, hook_config
rescue Exception => e
  raise e
end

#forgeObject



25
26
27
28
29
30
# File 'lib/writefully/tools/hammer.rb', line 25

def forge
  Writefully.logger.info "Forging #{message[:site_slug]}"
  api.repos.create name: message[:site_slug], auto_init: true
rescue Exception => e
  raise e
end

#hook_configObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/writefully/tools/hammer.rb', line 13

def hook_config
  { name: 'web',
    events: ["push", "member"],
    active: true,
    config: { 
      url: "#{message[:domain]}/writefully/hook", 
      content_type: 'json',
      secret: Writefully.options[:hook_secret]
    } 
  }
end