Class: Dependabot::GithubActions::FileUpdater::WorkflowUpdater::VersionCommenter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, credentials:) ⇒ VersionCommenter

Returns a new instance of VersionCommenter.



19
20
21
22
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 19

def initialize(dependency:, credentials:)
  @dependency = dependency
  @credentials = credentials
end

Instance Method Details

#comment_for_ref(ref) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 50

def comment_for_ref(ref)
  return unless sha?(ref)

  version_tag = git_checker.most_specific_version_tag_for_sha(ref)
  return unless version_tag

  " # #{version_tag}"
end

#new_comment(old_ref, new_ref) ⇒ Object



43
44
45
46
47
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 43

def new_comment(old_ref, new_ref)
  return unless tag_to_sha?(old_ref, new_ref)

  comment_for_ref(new_ref)
end

#recognized_comment?(comment, old_ref, new_ref) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 38

def recognized_comment?(comment, old_ref, new_ref)
  !previous_version_from_comment(comment.rstrip, old_ref, new_ref).nil?
end

#sha?(ref) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 60

def sha?(ref)
  git_checker.ref_looks_like_commit_sha?(ref)
end

#updated_comment(comment, old_ref, new_ref) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/version_commenter.rb', line 25

def updated_comment(comment, old_ref, new_ref)
  comment = comment.rstrip
  previous_version = previous_version_from_comment(comment, old_ref, new_ref)
  return unless previous_version

  new_version_tag = git_checker.most_specific_version_tag_for_sha(new_ref)
  return unless new_version_tag

  new_version = version_class.new(new_version_tag).to_s
  comment.gsub(previous_version, new_version)
end