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

Support version 1 of Package.resolved #4

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
danger-spm_version_updates (0.1.3)
danger-spm_version_updates (0.2.0)
danger-plugin-api (~> 1.0)
semantic (~> 1.6)
xcodeproj (~> 1.24)
Expand Down
2 changes: 1 addition & 1 deletion lib/spm_version_updates/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SpmVersionUpdates
VERSION = "0.1.3"
VERSION = "0.2.0"
end
12 changes: 8 additions & 4 deletions lib/spm_version_updates/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ def self.get_resolved_versions(xcodeproj_path)
raise(CouldNotFindResolvedFile) if resolved_paths.empty?

resolved_versions = resolved_paths.map { |resolved_path|
JSON.load_file!(resolved_path)["pins"]
.to_h { |pin|
[Git.trim_repo_url(pin["location"]), pin["state"]["version"] || pin["state"]["revision"]]
}
contents = JSON.load_file!(resolved_path)
pins = contents["pins"] || contents["object"]["pins"]
pins.to_h { |pin|
Comment on lines +33 to +35
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): Consider handling JSON parsing errors gracefully.

Directly using JSON.load_file! without any error handling might lead to uncaught exceptions if the JSON is malformed. It might be beneficial to wrap this in a begin-rescue block to handle potential parsing errors more gracefully, providing a clearer error message or a fallback mechanism.

[
Git.trim_repo_url(pin["location"] || pin["repositoryURL"]),
pin["state"]["version"] || pin["state"]["revision"],
]
}
}
resolved_versions.reduce(:merge!)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/spm_version_updates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ module Danger
"5e5c3f78ff25e7678ed7d3b25d7c60eeeee47e25"
)
end

it "Reports new versions for version=1 Package.resolved" do
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 a test case for empty or malformed Package.resolved files.

It's important to ensure the plugin gracefully handles scenarios where the Package.resolved file might be empty, malformed, or otherwise not as expected. This could help prevent runtime errors and improve the robustness of the plugin.

Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Add a test case for when no newer versions are available.

Testing the scenario where no newer versions are available would ensure that the plugin behaves as expected in such cases, potentially avoiding false positives or unnecessary warnings.

Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Verify the behavior when multiple newer versions are available.

It would be beneficial to test how the plugin reports when multiple newer versions of a dependency are available. This can help ensure that the reporting is clear and actionable for the user.

allow(Git).to receive(:version_tags)
.and_return [
Semantic::Version.new("3.1.3"),
]

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

expect(@dangerfile.status_report[:warnings]).to eq(
[
"Newer version of gonzalezreal/NetworkImage: 3.1.3",
]
)
end
end
end
end
80 changes: 80 additions & 0 deletions spec/support/fixtures/PackageV1.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 "Nuke" */,
);
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 "Nuke" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/gonzalezreal/NetworkImage";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.1.0;
};
};
/* End XCRemoteSwiftPackageReference section */
};
rootObject = F1465EF523AA94BF0055F7C3 /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"object": {
"pins": [
{
"package": "AttributedText",
"repositoryURL": "https://github.com/gonzalezreal/AttributedText",
"state": {
"branch": null,
"revision": "c345033e22d5a1cd0e9fe0ec405cc809a8349586",
"version": "0.3.1"
}
},
{
"package": "combine-schedulers",
"repositoryURL": "https://github.com/pointfreeco/combine-schedulers",
"state": {
"branch": null,
"revision": "11973960af9c5426f22d337628cec4342c5e660d",
"version": "0.7.4"
}
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher",
"state": {
"branch": null,
"revision": "d06df9adf50ed8cde5786d935836a5f445f780ba",
"version": "6.3.1"
}
},
{
"package": "MarkdownUI",
"repositoryURL": "https://github.com/gonzalezreal/MarkdownUI",
"state": {
"branch": null,
"revision": "29d94710545952dd4c724cc2ca901848eef54ded",
"version": "0.5.2"
}
},
{
"package": "NetworkImage",
"repositoryURL": "https://github.com/gonzalezreal/NetworkImage",
"state": {
"branch": null,
"revision": "04167e81ed89a14b5da9b856ead306b969bb5abd",
"version": "3.1.2"
}
},
{
"package": "cmark",
"repositoryURL": "https://github.com/SwiftDocOrg/swift-cmark.git",
"state": {
"branch": null,
"revision": "9c8096a23f44794bde297452d87c455fc4f76d42",
"version": "0.29.0+20210102.9c8096a"
}
},
{
"package": "SwiftCommonMark",
"repositoryURL": "https://github.com/gonzalezreal/SwiftCommonMark",
"state": {
"branch": null,
"revision": "ed60da54305c244d0f77bc8d08495e04161e96a4",
"version": "0.1.2"
}
},
{
"package": "xctest-dynamic-overlay",
"repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state": {
"branch": null,
"revision": "38bc9242e4388b80bd23ddfdf3071428859e3260",
"version": "0.4.0"
}
}
]
},
"version": 1
}