Class: Dependabot::PullRequestCreator::CommitSigner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
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.



38
39
40
41
42
43
44
45
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 38

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.



15
16
17
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 15

def author_details
  @author_details
end

#commit_messageObject (readonly)

Returns the value of attribute commit_message.



18
19
20
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 18

def commit_message
  @commit_message
end

#parent_shaObject (readonly)

Returns the value of attribute parent_sha.



24
25
26
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 24

def parent_sha
  @parent_sha
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key.



27
28
29
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 27

def signature_key
  @signature_key
end

#tree_shaObject (readonly)

Returns the value of attribute tree_sha.



21
22
23
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 21

def tree_sha
  @tree_sha
end

Instance Method Details

#signatureObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dependabot/pull_request_creator/commit_signer.rb', line 48

def signature
  begin
    require "gpgme"
  rescue LoadError
    raise LoadError, "Please add `gpgme` to your Gemfile or gemspec " \
                     "enable commit signatures"
  end

  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(T.must(dir), true)
  # This appears to be a Ruby bug which occurs very rarely
  raise if @retrying

  @retrying = T.let(true, T.nilable(T::Boolean))
  retry
ensure
  FileUtils.remove_entry(T.must(dir), true)
end