Module: UpgradeSuggestion
- Defined in:
- lib/spm_version_updates/upgrade_suggestion.rb
Overview
Derives per-update upgrade guidance from a package’s requirement kind and the available version: the SwiftPM identity, a ready-to-run ‘swift package update` command (manifest mode only), and the manifest requirement change needed when the new version is outside the declared constraint. Shared between the GitHub Action reporters and the Danger plugin.
Class Method Summary collapse
-
.command(package) ⇒ Object
‘swift package update` only applies to Package.swift-managed dependencies (never Xcode projects, where source is nil) and cannot move a revision pin.
-
.fields(package, available_version, type) ⇒ Hash
Package_identity / requirement_kind / suggested_command / suggested_requirement, with inapplicable entries nil.
-
.identity(normalized_url) ⇒ Object
SwiftPM’s default package identity: the last path component of the repository URL, lowercased (the normalized URL already has no ‘.git`).
-
.requirement_change(package, available, type) ⇒ Object
The Package.swift requirement text needed before ‘swift package update` can reach the suggested version.
Class Method Details
.command(package) ⇒ Object
‘swift package update` only applies to Package.swift-managed dependencies (never Xcode projects, where source is nil) and cannot move a revision pin.
31 32 33 34 35 36 |
# File 'lib/spm_version_updates/upgrade_suggestion.rb', line 31 def self.command(package) return nil unless package.source return nil if package.kind == "revision" "swift package update #{identity(package.normalized_url)}" end |
.fields(package, available_version, type) ⇒ Hash
Returns package_identity / requirement_kind / suggested_command / suggested_requirement, with inapplicable entries nil.
20 21 22 23 24 25 26 27 |
# File 'lib/spm_version_updates/upgrade_suggestion.rb', line 20 def self.fields(package, available_version, type) { package_identity: identity(package.normalized_url), requirement_kind: package.kind, suggested_command: command(package), suggested_requirement: requirement_change(package, available_version.to_s, type) } end |
.identity(normalized_url) ⇒ Object
SwiftPM’s default package identity: the last path component of the repository URL, lowercased (the normalized URL already has no ‘.git`).
11 12 13 |
# File 'lib/spm_version_updates/upgrade_suggestion.rb', line 11 def self.identity(normalized_url) normalized_url.to_s.split("/").last.to_s.downcase end |
.requirement_change(package, available, type) ⇒ Object
The Package.swift requirement text needed before ‘swift package update` can reach the suggested version. In-range updates, branch pins, and revision pins need no manifest change.
41 42 43 44 45 |
# File 'lib/spm_version_updates/upgrade_suggestion.rb', line 41 def self.requirement_change(package, available, type) return above_maximum_change(package, available) if type == :above_maximum %(exact: "#{available}") if package.kind == "exactVersion" end |