Class: Dependabot::PullRequestCreator::CommitSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/pull_request_creator/commit_signer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(author_details:, commit_message:, tree_sha:, parent_sha:, signature_key:) ⇒ CommitSigner

Returns a new instance of CommitSigner.



14
15
16
17
18
19
20
21
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 14

def initialize(author_details:, commit_message:, tree_sha:, parent_sha:,
               signature_key:)
  @author_details = author_details
  @commit_message = commit_message
  @tree_sha = tree_sha
  @parent_sha = parent_sha
  @signature_key = signature_key
end

Instance Attribute Details

#author_detailsObject (readonly)

Returns the value of attribute author_details.



11
12
13
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 11

def author_details
  @author_details
end

#commit_messageObject (readonly)

Returns the value of attribute commit_message.



11
12
13
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 11

def commit_message
  @commit_message
end

#parent_shaObject (readonly)

Returns the value of attribute parent_sha.



11
12
13
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 11

def parent_sha
  @parent_sha
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key.



11
12
13
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 11

def signature_key
  @signature_key
end

#tree_shaObject (readonly)

Returns the value of attribute tree_sha.



11
12
13
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 11

def tree_sha
  @tree_sha
end

Instance Method Details

#signatureObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 23

def signature
  email = author_details[:email]

  dir = Dir.mktmpdir

  GPGME::Engine.home_dir = dir
  GPGME::Key.import(signature_key)

  crypto = GPGME::Crypto.new(armor: true)
  opts = { mode: GPGME::SIG_MODE_DETACH, signer: email }
  crypto.sign(commit_object, opts).to_s
rescue Errno::ENOTEMPTY
  FileUtils.remove_entry(dir, true)
  # This appears to be a Ruby bug which occurs very rarely
  raise if @retrying

  @retrying = true
  retry
ensure
  FileUtils.remove_entry(dir, true)
end