Class: Danger::DangerSpmVersionUpdates

Inherits:
Plugin
  • Object
show all
Defined in:
lib/spm_version_updates/plugin.rb

Overview

A Danger plugin for checking if there are versions upgrades available for SPM dependencies

Examples:

Check if MyApp’s SPM dependencies are up to date

spm_version_updates.check_for_updates("MyApp.xcodeproj")

See Also:

  • hbmartin/danger-spm_version_updates

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#check_when_exactBoolean

Whether to check when dependencies are exact versions or commits, default false

Returns:

  • (Boolean)


19
20
21
# File 'lib/spm_version_updates/plugin.rb', line 19

def check_when_exact
  @check_when_exact
end

#ignore_reposArray<String>

A list of repository URLs for packages to ignore entirely

Returns:

  • (Array<String>)


31
32
33
# File 'lib/spm_version_updates/plugin.rb', line 31

def ignore_repos
  @ignore_repos
end

#report_above_maximumBoolean

Whether to report versions above the maximum version range, default false

Returns:

  • (Boolean)


23
24
25
# File 'lib/spm_version_updates/plugin.rb', line 23

def report_above_maximum
  @report_above_maximum
end

#report_pre_releasesBoolean

Whether to report pre-release versions, default false

Returns:

  • (Boolean)


27
28
29
# File 'lib/spm_version_updates/plugin.rb', line 27

def report_pre_releases
  @report_pre_releases
end

Instance Method Details

#check_for_updates(xcodeproj_path) ⇒ void

This method returns an undefined value.

A method that you can call from your Dangerfile

Parameters:

  • xcodeproj_path (String)

    The path to your Xcode project

Raises:

  • (XcodeprojPathMustBeSet)

    if the xcodeproj_path is blank



38
39
40
41
42
43
44
45
46
47
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
76
77
# File 'lib/spm_version_updates/plugin.rb', line 38

def check_for_updates(xcodeproj_path)
  remote_packages = Xcode.get_packages(xcodeproj_path)
  resolved_versions = Xcode.get_resolved_versions(xcodeproj_path)
  $stderr.puts("Found resolved versions for #{resolved_versions.size} packages")

  self.ignore_repos = self.ignore_repos&.map! { |repo| Git.trim_repo_url(repo) }

  remote_packages.each { |repository_url, requirement|
    next if self.ignore_repos&.include?(repository_url)

    name = Git.repo_name(repository_url)
    resolved_version = resolved_versions[repository_url]
    kind = requirement["kind"]

    if resolved_version.nil?
      $stderr.puts("Unable to locate the current version for #{name} (#{repository_url})")
      next
    end

    if kind == "branch"
      branch = requirement["branch"]
      last_commit = Git.branch_last_commit(repository_url, branch)
      warn("Newer commit available for #{name} (#{branch}): #{last_commit}") unless last_commit == resolved_version
      next
    end

    available_versions = Git.version_tags(repository_url)
    next if available_versions.first.to_s == resolved_version

    if kind == "exactVersion" && @check_when_exact
      warn_for_new_versions_exact(available_versions, name, resolved_version)
    elsif kind == "upToNextMajorVersion"
      warn_for_new_versions(:major, available_versions, name, resolved_version)
    elsif kind == "upToNextMinorVersion"
      warn_for_new_versions(:minor, available_versions, name, resolved_version)
    elsif kind == "versionRange"
      warn_for_new_versions_range(available_versions, name, requirement, resolved_version)
    end
  }
end