Skip to content

Commit

Permalink
SPT-1990 ruby lint formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldilocks97 committed Mar 27, 2024
1 parent 4b7221a commit cb4f6f1
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 316 deletions.
12 changes: 7 additions & 5 deletions lib/spm_version_updates/local.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

def get_local_packages(where_to_search_local_packages)
get_manifests(where_to_search_local_packages)
.flat_map { |manifest| get_dependencies(manifest) }
Expand All @@ -12,7 +14,7 @@ def get_manifests(where_to_search_local_packages)
def get_dependencies(manifest)
content = File.read(manifest)
package_name = package_name(content)
get_requirement_kinds.each_with_object([]) { |kind, dependencies|
requirement_kinds.each_with_object([]) { |kind, dependencies|
regex = package_regex(kind)
content.scan(regex).each { |match|
url = match[0]
Expand All @@ -34,14 +36,14 @@ def package_name(content)
content.scan(/Package\(\s*name:\s*"([^"]+)"/).first.first
end

def get_requirement_kinds
def requirement_kinds
[
"revision",
"exact",
"branch",
"upToNextMajor",
"upToNextMinor",
"range"
"range",
]
end

Expand All @@ -57,14 +59,14 @@ def process_kind_for_hash(kind)
def package_regex(req_kind)
indent = '\s*'
dot = '\.'
less = '<'
less = "<"
lp = /\(#{indent}/
rp = /#{indent}\)/
req_val = /"([^"]+)"/

base = /#{dot}package#{lp}url:#{indent}#{req_val},#{indent}/

req_arg = /#{req_kind}:#{indent}#{req_val}/
req_arg = /#{req_kind}:#{indent}#{req_val}/

from = /from:#{indent}#{req_val}/
up_to_next = /#{dot}#{req_kind}#{lp}#{from}#{rp}/
Expand Down
37 changes: 18 additions & 19 deletions lib/spm_version_updates/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ def check_for_updates(xcodeproj_path, where_to_search_local_packages = ".")
resolved_versions = JSON.load_file!(resolved_path)["pins"]
.to_h { |pin|
[
pin["location"],
pin["location"],
[
pin["state"]["version"] || pin["state"]["revision"],
pin["state"]["branch"]
]
]
pin["state"]["version"] || pin["state"]["revision"],
pin["state"]["branch"],
],
]
}

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

name = "(#{requirement.fetch("package_name", "project")}) #{repo_name(repository_url)}"
name = "(#{requirement.fetch('package_name', 'project')}) #{repo_name(repository_url)}"
kind = requirement["kind"]

resolved_version = resolved_versions[repository_url]
Expand All @@ -69,16 +69,16 @@ def check_for_updates(xcodeproj_path, where_to_search_local_packages = ".")
end

# To show only versions not commit-hashes
if git_version(resolved_version[0])
resolved_version = resolved_version[0]
else
resolved_version = resolved_version[1]
end
resolved_version = if git_version(resolved_version[0])
resolved_version[0]
else
resolved_version[1]
end

# kind can be major, minor, range, exact, branch, revision

if kind == "revision" && !git_version(requirement["revision"])
warn("#{name}: non-version values in revision are not analyzed: #{requirement["revision"]}")
warn("#{name}: non-version values in revision are not analyzed: #{requirement['revision']}")
next
end

Expand All @@ -91,7 +91,7 @@ def check_for_updates(xcodeproj_path, where_to_search_local_packages = ".")
available_versions = git_versions(repository_url)
next if available_versions.first.to_s == resolved_version

if (kind == "exactVersion" || kind == "revision") && @check_when_exact
if ["exactVersion", "revision"].include?(kind) && @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)
Expand All @@ -103,7 +103,7 @@ def check_for_updates(xcodeproj_path, where_to_search_local_packages = ".")
}
end

# Extract a readable name for the repo given the url, generally org/repo
# Extract a readable name for the repo given the url, generally org/repo
# @return [String]
def repo_name(repo_url)
match = repo_url.match(%r{([\w-]+/[\w-]+)(.git)?$})
Expand Down Expand Up @@ -160,6 +160,7 @@ def warn_for_new_versions_range(available_versions, name, requirement, resolved_
}
warn("Newer version of #{name}: #{newest_meeting_reqs} ") unless newest_meeting_reqs.to_s == resolved_version
return unless report_above_maximum

newest_above_reqs = available_versions.find { |version|
report_pre_releases ? true : version.pre.nil?
}
Expand Down Expand Up @@ -192,13 +193,13 @@ def warn_for_new_versions(major_or_minor, available_versions, name, resolved_ver

# Assumed using only 3-levels digital version-notation
def git_version(input)
parts = input.split('.')
parts = input.split(".")

return nil if parts.length > 3
return nil unless parts.all? { |part| part.match?(/\A\d+\z/) }

(3 - parts.length).times { parts << "0" }
parts.join('.')
parts.join(".")
end

# Remove git call to list tags
Expand All @@ -211,10 +212,8 @@ def git_versions(repo_url)
begin
Semantic::Version.new(line)
rescue ArgumentError
if recovered_version = git_version(line)
if (recovered_version = git_version(line))
Semantic::Version.new(recovered_version)
else
nil
end
end
}
Expand Down
Loading

0 comments on commit cb4f6f1

Please sign in to comment.