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.


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

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


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

def author_details
  @author_details
end

#commit_messageObject (readonly)

Returns the value of attribute commit_message


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

def commit_message
  @commit_message
end

#parent_shaObject (readonly)

Returns the value of attribute parent_sha


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

def parent_sha
  @parent_sha
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key


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

def signature_key
  @signature_key
end

#tree_shaObject (readonly)

Returns the value of attribute tree_sha


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

def tree_sha
  @tree_sha
end

Instance Method Details

#signatureObject


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

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(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