Class: TxghServer::Webhooks::Git::PushHandler

Inherits:
Object
  • Object
show all
Includes:
ResponseHelpers
Defined in:
lib/txgh-server/webhooks/git/push_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, repo, logger, attributes) ⇒ PushHandler

Returns a new instance of PushHandler.



12
13
14
15
16
17
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 12

def initialize(project, repo, logger, attributes)
  @project = project
  @repo = repo
  @logger = logger
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 10

def attributes
  @attributes
end

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 10

def logger
  @logger
end

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 10

def project
  @project
end

#repoObject (readonly)

Returns the value of attribute repo.



10
11
12
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 10

def repo
  @repo
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/txgh-server/webhooks/git/push_handler.rb', line 19

def execute
  # Check if the branch in the hook data is the configured branch we want
  logger.info("request git branch: #{branch}")
  logger.info("config git branch: #{repo.git_config_branch}")

  if should_process?
    logger.info('found branch in git request')

    pusher.push_resources(added_and_modified_resources) do |tx_resource|
      # block should return categories for the passed-in resource
      { 'author' => attributes.author }
    end

    status_updater.update_status
  end

  respond_with(200, true)
rescue => e
  status_updater.report_error_and_update_status(e)
  respond_with_error(500, "Internal server error: #{e.message}", e)
end