Class: SpmChecker

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

Overview

Core SPM version checking logic (migrated from Danger plugin)

Defined Under Namespace

Classes: DisallowedRepositoryHost

Constant Summary collapse

VERSION_TAG_WORKER_COUNT =
8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpmChecker

Returns a new instance of SpmChecker.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spm_version_updates/spm_checker.rb', line 54

def initialize
  @check_when_exact = @check_revisions = @report_above_maximum = @report_pre_releases = false
  @check_branches = true
  @lookup_failure_handler = @malformed_resolved_handler = nil
  @ignore_repos = []
  @repository_update_rules = RepositoryUpdateRules.empty
  @allow_hosts = []
  @warnings = []
  @warning_details = []
  @version_tags_cache = {}
  @version_tag_lookup_errors = {}
  @reported_lookup_failures = {}
  @version_tags_cache_dir = nil
  @version_tags_cache_ttl_seconds = VersionTagsPersistentCache::DEFAULT_TTL_SECONDS
end

Instance Attribute Details

#allow_hostsObject

Returns the value of attribute allow_hosts.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def allow_hosts
  @allow_hosts
end

#check_branchesObject

Returns the value of attribute check_branches.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def check_branches
  @check_branches
end

#check_revisionsObject

Returns the value of attribute check_revisions.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def check_revisions
  @check_revisions
end

#check_when_exactObject

Returns the value of attribute check_when_exact.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def check_when_exact
  @check_when_exact
end

#ignore_reposObject

Returns the value of attribute ignore_repos.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def ignore_repos
  @ignore_repos
end

#lookup_failure_handlerObject

Optional callable ‘(package, error)` invoked instead of raising when a git lookup fails, so callers like the Danger plugin can warn and keep checking the remaining packages. When nil (the default), lookup failures raise one combined GitOperations::LsRemoteError exactly as before.



43
44
45
# File 'lib/spm_version_updates/spm_checker.rb', line 43

def lookup_failure_handler
  @lookup_failure_handler
end

#malformed_resolved_handlerObject

Optional callable ‘(resolved_path, error)` invoked instead of raising when a Package.resolved file is malformed; the file is skipped. When nil (the default), PackageResolved::MalformedFileError is raised.



48
49
50
# File 'lib/spm_version_updates/spm_checker.rb', line 48

def malformed_resolved_handler
  @malformed_resolved_handler
end

#report_above_maximumObject

Returns the value of attribute report_above_maximum.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def report_above_maximum
  @report_above_maximum
end

#report_pre_releasesObject

Returns the value of attribute report_pre_releases.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def report_pre_releases
  @report_pre_releases
end

#repository_update_rulesObject

Returns the value of attribute repository_update_rules.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def repository_update_rules
  @repository_update_rules
end

#version_tags_cache_dirObject

Returns the value of attribute version_tags_cache_dir.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def version_tags_cache_dir
  @version_tags_cache_dir
end

#version_tags_cache_ttl_secondsObject

Returns the value of attribute version_tags_cache_ttl_seconds.



28
29
30
# File 'lib/spm_version_updates/spm_checker.rb', line 28

def version_tags_cache_ttl_seconds
  @version_tags_cache_ttl_seconds
end

#warning_detailsObject (readonly)

Structured facts about each warning, used by the GitHub Action comment renderer. ‘check_for_updates` and `check_manifests` still return the legacy string warnings for compatibility with existing plugin-style callers.



26
27
28
# File 'lib/spm_version_updates/spm_checker.rb', line 26

def warning_details
  @warning_details
end

Class Method Details

.redact_credentials(value) ⇒ Object



50
51
52
# File 'lib/spm_version_updates/spm_checker.rb', line 50

def self.redact_credentials(value)
  CredentialRedactor.redact(value)
end

Instance Method Details

#check_for_updates(xcodeproj_path) ⇒ Array<String>

Check for SPM updates using an Xcode project as the source of dependencies.

Parameters:

  • xcodeproj_path (String)

    The path to your Xcode project

Returns:

  • (Array<String>)

    Array of warning messages



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/spm_version_updates/spm_checker.rb', line 74

def check_for_updates(xcodeproj_path)
  clear_warnings
  reset_version_tags_cache
  normalize_ignore_repos
  normalize_allow_hosts

  remote_packages = XcodeParser.get_packages(xcodeproj_path)
  resolved_versions = XcodeParser.get_resolved_versions(xcodeproj_path, &@malformed_resolved_handler)
  puts("Found resolved versions for #{resolved_versions.size} packages")
  warn_for_empty_xcode_project(remote_packages, resolved_versions, xcodeproj_path)

  check_packages(remote_packages, resolved_versions)
  @warnings
end

#check_manifests(manifest_paths, resolved_paths = nil) ⇒ Array<String>

Check for SPM updates using one or more ‘Package.swift` manifests as the source of dependencies.

Resolved pins from every ‘Package.resolved` are merged by normalized repository URL into a single lookup. Each manifest’s direct dependencies are then compared against that lookup, and the originating manifest is attached to every warning so multi-manifest repos can tell where an update applies.

Parameters:

  • manifest_paths (Array<String>)

    Paths to one or more ‘Package.swift`

  • resolved_paths (Array<String>, nil) (defaults to: nil)

    Optional explicit ‘Package.resolved` paths. When omitted, a `Package.resolved` next to each manifest is used.

Returns:

  • (Array<String>)

    Array of warning messages

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/spm_version_updates/spm_checker.rb', line 103

def check_manifests(manifest_paths, resolved_paths = nil)
  clear_warnings
  reset_version_tags_cache
  normalize_ignore_repos
  normalize_allow_hosts

  resolved_versions = merged_resolved_versions(manifest_paths, resolved_paths)
  puts("Found resolved versions for #{resolved_versions.size} packages")

  manifest_paths.each { |manifest_path|
    remote_packages = ManifestParser.get_packages(manifest_path)
    check_packages(remote_packages, resolved_versions, manifest_path)
  }
  @warnings
end