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) rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: DisallowedRepositoryHost, Result

Constant Summary collapse

DEFAULT_VERSION_LOOKUP_WORKERS =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpmChecker

Returns a new instance of SpmChecker.



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/spm_version_updates/spm_checker.rb', line 212

def initialize
  @check_when_exact = @check_revisions = @report_above_maximum = @report_pre_releases = false
  @check_branches = true
  @lookup_failure_handler = @malformed_resolved_handler = @missing_resolved_handler = nil
  @ignore_repos = []
  @repository_update_rules = RepositoryUpdateRules.empty
  @allow_hosts = []
  @version_lookup_workers = DEFAULT_VERSION_LOOKUP_WORKERS
  @updates = []
  @parse_warnings = []
  @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.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def allow_hosts
  @allow_hosts
end

#check_branchesObject

Returns the value of attribute check_branches.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def check_branches
  @check_branches
end

#check_revisionsObject

Returns the value of attribute check_revisions.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def check_revisions
  @check_revisions
end

#check_when_exactObject

Returns the value of attribute check_when_exact.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def check_when_exact
  @check_when_exact
end

#ignore_reposObject

Returns the value of attribute ignore_repos.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

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.



195
196
197
# File 'lib/spm_version_updates/spm_checker.rb', line 195

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.



200
201
202
# File 'lib/spm_version_updates/spm_checker.rb', line 200

def malformed_resolved_handler
  @malformed_resolved_handler
end

#missing_resolved_handlerObject

Optional callable ‘(missing_paths)` invoked instead of raising when expected Package.resolved files are missing. Missing paths are dropped and packages without a resolved version keep the existing “Unable to locate…” behavior: no warning record is created and no version tags are fetched for them.



206
207
208
# File 'lib/spm_version_updates/spm_checker.rb', line 206

def missing_resolved_handler
  @missing_resolved_handler
end

#report_above_maximumObject

Returns the value of attribute report_above_maximum.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def report_above_maximum
  @report_above_maximum
end

#report_pre_releasesObject

Returns the value of attribute report_pre_releases.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def report_pre_releases
  @report_pre_releases
end

#repository_update_rulesObject

Returns the value of attribute repository_update_rules.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def repository_update_rules
  @repository_update_rules
end

#version_lookup_workersObject

Returns the value of attribute version_lookup_workers.



178
179
180
# File 'lib/spm_version_updates/spm_checker.rb', line 178

def version_lookup_workers
  @version_lookup_workers
end

#version_tags_cache_dirObject

Returns the value of attribute version_tags_cache_dir.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

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.



180
181
182
# File 'lib/spm_version_updates/spm_checker.rb', line 180

def version_tags_cache_ttl_seconds
  @version_tags_cache_ttl_seconds
end

Class Method Details

.redact_credentials(value) ⇒ Object



208
209
210
# File 'lib/spm_version_updates/spm_checker.rb', line 208

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

Instance Method Details

#check_for_updates(xcodeproj_path) ⇒ Result

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

Parameters:

  • xcodeproj_path (String)

    The path to your Xcode project

Returns:

  • (Result)

    Structured update records and parse warnings



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/spm_version_updates/spm_checker.rb', line 240

def check_for_updates(xcodeproj_path)
  prepare_run

  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)
  result
end

#check_manifests(manifest_paths, resolved_paths = nil) ⇒ Result

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:

  • (Result)

    Structured update records and parse warnings

Raises:



266
267
268
269
270
271
272
273
274
275
276
# File 'lib/spm_version_updates/spm_checker.rb', line 266

def check_manifests(manifest_paths, resolved_paths = nil)
  prepare_run

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

  manifest_paths.each { |manifest_path|
    check_packages(manifest_packages(manifest_path), resolved_versions, manifest_path)
  }
  result
end

#check_resolved(resolved_paths) ⇒ Result

Check for SPM updates using one or more ‘Package.resolved` files as the source of dependencies. Version pins are compared directly with available tags; revision-only pins are reported only when check_revisions is enabled.

Parameters:

  • resolved_paths (Array<String>)

    Paths to one or more Package.resolved files

Returns:

  • (Result)

    Structured update records and parse warnings

Raises:



285
286
287
288
289
290
291
292
# File 'lib/spm_version_updates/spm_checker.rb', line 285

def check_resolved(resolved_paths)
  prepare_run
  paths = normalized_resolved_paths(resolved_paths)
  raise(SpmVersionUpdates::ConfigurationError, "package-resolved-paths must be set") if paths.empty?

  check_existing_resolved_paths(paths)
  result
end