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 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
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
28 changes: 23 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,16 @@

private

# Warns if the branch has a newer commit than the resolved version.
# @param branch [String] the branch name
# @param name [String] the dependency name
# @param repository_url [String] the Git repository URL
# @param resolved_version [String] the currently resolved version of the branch
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 +100,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 107 in lib/spm_version_updates/plugin.rb

View check run for this annotation

Codecov / codecov/patch

lib/spm_version_updates/plugin.rb#L106-L107

Added lines #L106 - L107 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 +122,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
23 changes: 22 additions & 1 deletion spec/spm_version_updates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,26 @@ module Danger
expect(@dangerfile.status_report[:warnings]).to eq([])
end

it "Prints to stderr when resolved version is unexpectedly null" do
expect {
@my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/PackageV1Commit.xcodeproj")
}.to output(
%r{Unable to extract semver from 12f19662426d0434d6c330c6974d53e2eb10ecd9 for AliSoftware/OHHTTPStubs.*}
).to_stderr
end

it "Does not fail when resolved version is unexpectedly null" do
@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")

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

it "Does print to stderr when resolved version is missing from xcodeproj" do
it "Prints to stderr when resolved version is missing from xcodeproj" do
expect {
@my_plugin.check_for_updates("#{File.dirname(__FILE__)}/support/fixtures/NoResolvedVersion.xcodeproj")
}.to output(
Expand Down Expand Up @@ -290,6 +303,14 @@ module Danger
)
end

it "Extracts repo name from URL" do
expect(Git.repo_name("https://github.com/hbmartin/danger-spm_version_updates")).to eq("hbmartin/danger-spm_version_updates")
end

it "Returns repo name from param when not URL" do
expect(Git.repo_name("hbmartin/danger-spm_version_updates")).to eq("hbmartin/danger-spm_version_updates")
end

it "Reports new versions for version=1 Package.resolved" do
allow(Git).to receive(:version_tags)
.and_return [
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
}