Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore packages with commit instead of version #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/spm_version_updates/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def self.trim_repo_url(repo_url)
# @return [String]
def self.repo_name(repo_url)
match = repo_url.match(%r{([\w-]+/[\w-]+)(.git)?$})

if match
match[1] || match[0]
else
Expand All @@ -36,8 +35,7 @@ def self.version_tags(repo_url)
nil
end
}
versions.sort!
versions.reverse!
versions.sort!.reverse!
versions
end

Expand Down
23 changes: 18 additions & 5 deletions lib/spm_version_updates/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
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
warn_for_branch(requirement["branch"], name, repository_url, resolved_version)
next
end

Expand All @@ -80,6 +78,11 @@

private

def warn_for_branch(branch, name, repository_url, resolved_version)
last_commit = Git.branch_last_commit(repository_url, branch)
warn("Newer commit available for #{name} (#{branch}): #{last_commit}") unless last_commit == resolved_version
end
hbmartin marked this conversation as resolved.
Show resolved Hide resolved

def warn_for_new_versions_exact(available_versions, name, resolved_version)
newest_version = available_versions.find { |version|
report_pre_releases ? true : version.pre.nil?
Expand All @@ -92,7 +95,12 @@
end

def warn_for_new_versions_range(available_versions, name, requirement, resolved_version)
max_version = Semantic::Version.new(requirement["maximumVersion"])
begin
max_version = Semantic::Version.new(requirement["maximumVersion"])
rescue ArgumentError => e
$stderr.puts("Unable to extract semver from #{requirement} for #{name} (#{e})")
return

Check warning on line 102 in lib/spm_version_updates/plugin.rb

View check run for this annotation

Codecov / codecov/patch

lib/spm_version_updates/plugin.rb#L101-L102

Added lines #L101 - L102 were not covered by tests
end
if available_versions.first < max_version
warn("Newer version of #{name}: #{available_versions.first}")
else
Expand All @@ -109,7 +117,12 @@
end

def warn_for_new_versions(major_or_minor, available_versions, name, resolved_version_string)
resolved_version = Semantic::Version.new(resolved_version_string)
begin
resolved_version = Semantic::Version.new(resolved_version_string)
rescue ArgumentError => e
$stderr.puts("Unable to extract semver from #{resolved_version_string} for #{name} (#{e})")
return
end
newest_meeting_reqs = available_versions.find { |version|
(version.send(major_or_minor) == resolved_version.send(major_or_minor)) && (report_pre_releases ? true : version.pre.nil?)
}
Expand Down
6 changes: 6 additions & 0 deletions spec/spm_version_updates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ module Danger
expect(@dangerfile.status_report[:warnings]).to eq([])
end

it "Up to next major but null version" do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Test case 'Up to next major but null version' lacks assertions for specific warnings.

Please add assertions to verify that the correct warnings are generated when the version is null. This will ensure that the new logic in warn_for_new_versions_range and warn_for_new_versions is correctly handling null or invalid versions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding more test cases for error handling in version parsing.

Given the changes in error handling for version parsing in warn_for_new_versions_range and warn_for_new_versions, it would be beneficial to include tests that trigger and verify the handling of ArgumentError.

Suggested change
it "Up to next major but null version" do
it "Up to next major but null version" do
expect { @my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/PackageV1Commit.xcodeproj") }.to_not raise_error
expect(@dangerfile.status_report[:warnings]).to eq([])
end
it "Does not crash or warn when resolved version is missing from xcodeproj" do
expect { @my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/NoResolvedVersion.xcodeproj") }.to_not raise_error
end

@my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/PackageV1Commit.xcodeproj")

expect(@dangerfile.status_report[:warnings]).to eq([])
end

it "Does not crash or warn when resolved version is missing from xcodeproj" do
@my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/NoResolvedVersion.xcodeproj")

Expand Down
80 changes: 80 additions & 0 deletions spec/support/fixtures/PackageV1Commit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objects = {
/* Begin PBXGroup section */
F1465EF423AA94BF0055F7C3 = {
isa = PBXGroup;
children = (
F1465EFF23AA94BF0055F7C3 /* Demo */,
);
sourceTree = "<group>";
};
F1465EFF23AA94BF0055F7C3 /* Demo */ = {
isa = PBXGroup;
children = ();
path = Demo;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXProject section */
F1465EF523AA94BF0055F7C3 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1420;
TargetAttributes = {
F1465EFC23AA94BF0055F7C3 = {
CreatedOnToolsVersion = 11.2.1;
};
};
};
buildConfigurationList = F1465EF823AA94BF0055F7C3 /* Build configuration list for PBXProject "Demo" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
es,
"zh-Hans",
fr,
);
mainGroup = F1465EF423AA94BF0055F7C3;
packageReferences = (
11BBD37629C1571400F7A968 /* XCRemoteSwiftPackageReference "OHHTTPStubs" */,
);
productRefGroup = F1465EFE23AA94BF0055F7C3 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = ();
};
/* End PBXProject section */

/* Begin XCConfigurationList section */
F1465EF823AA94BF0055F7C3 /* Build configuration list for PBXNativeTarget "Demo" */ = {
isa = XCConfigurationList;
buildConfigurations = ();
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
11BBD37629C1571400F7A968 /* XCRemoteSwiftPackageReference "OHHTTPStubs" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/AliSoftware/OHHTTPStubs";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 9.1.0;
};
};
/* End XCRemoteSwiftPackageReference section */
};
rootObject = F1465EF523AA94BF0055F7C3 /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "OHHTTPStubs",
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs",
"state": {
"branch": "9.1.0",
"revision": "12f19662426d0434d6c330c6974d53e2eb10ecd9",
"version": null
}
}
]
},
"version": 1
}