Class: Txgh::ResourceCommitter

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh/resource_committer.rb

Constant Summary collapse

DEFAULT_COMMIT_MESSAGE =
"Updating %{language} translations in %{file_name}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, repo, logger = nil) ⇒ ResourceCommitter

Returns a new instance of ResourceCommitter.



7
8
9
10
11
# File 'lib/txgh/resource_committer.rb', line 7

def initialize(project, repo, logger = nil)
  @project = project
  @repo = repo
  @logger = logger || Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/txgh/resource_committer.rb', line 5

def logger
  @logger
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/txgh/resource_committer.rb', line 5

def project
  @project
end

#repoObject (readonly)

Returns the value of attribute repo.



5
6
7
# File 'lib/txgh/resource_committer.rb', line 5

def repo
  @repo
end

Instance Method Details

#commit_resource(tx_resource, branch, language) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/txgh/resource_committer.rb', line 13

def commit_resource(tx_resource, branch, language)
  return if prevent_commit_on?(branch)
  return if language == tx_resource.source_lang

  file_name, translations = download(tx_resource, branch, language)
  message = commit_message_for(language, file_name)

  return unless translations

  repo.api.update_contents(
    branch, [{ path: file_name, contents: translations }], message
  )

  Txgh.events.publish(
    'github.resource.committed', {
      project: project, repo: repo, resource: tx_resource,
      language: language, branch: branch
    }
  )
end