Class: Dependabot::MetadataFinders::Base::CommitsFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/metadata_finders/base/commits_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, dependency:, credentials:) ⇒ CommitsFinder

Returns a new instance of CommitsFinder.


17
18
19
20
21
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 17

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

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.


15
16
17
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 15

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.


15
16
17
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 15

def dependency
  @dependency
end

#sourceObject (readonly)

Returns the value of attribute source.


15
16
17
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 15

def source
  @source
end

Instance Method Details

#commitsObject


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 38

def commits
  return [] unless source
  return [] unless new_tag && previous_tag

  case source.provider
  when "github" then fetch_github_commits
  when "bitbucket" then fetch_bitbucket_commits
  when "gitlab" then fetch_gitlab_commits
  when "azure" then [] # TODO: Fetch Azure commits
  else raise "Unexpected source provider '#{source.provider}'"
  end
end

#commits_urlObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 23

def commits_url
  return unless source
  return if source.provider == "azure" # TODO: Fetch Azure commits

  path =
    case source.provider
    when "github" then github_compare_path(new_tag, previous_tag)
    when "bitbucket" then bitbucket_compare_path(new_tag, previous_tag)
    when "gitlab" then gitlab_compare_path(new_tag, previous_tag)
    else raise "Unexpected source provider '#{source.provider}'"
    end

  "#{source.url}/#{path}"
end

#new_tagObject


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dependabot/metadata_finders/base/commits_finder.rb', line 51

def new_tag
  new_version = dependency.version

  return new_version if git_source?(dependency.requirements) && git_sha?(new_version)

  return new_ref if new_ref && ref_changed?

  tags = dependency_tags.
         select { |tag| tag_matches_version?(tag, new_version) }.
         sort_by(&:length)

  tags.find { |t| t.include?(dependency.name) } || tags.first
end