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

Do not create a PR if a dependency was not found #105

Merged
merged 2 commits into from
May 5, 2022
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
12 changes: 10 additions & 2 deletions Sources/SwiftDependencyUpdaterLibrary/Services/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,19 @@ class Git: GitProvider {
}

func doesRemoteBranchExist(_ name: String) -> Bool {
doesBranchExist(ref: "refs/remotes/\(remoteName)/\(name)")
let result = doesBranchExist(ref: "refs/remotes/\(remoteName)/\(name)")
if result {
print("Branch \(name) already exists on the remote.".yellow)
}
return result
}

func doesLocalBranchExist(_ name: String) -> Bool {
doesBranchExist(ref: "refs/heads/\(name)")
let result = doesBranchExist(ref: "refs/heads/\(name)")
if result {
print("Branch \(name) already exists locally.".yellow)
}
return result
}

private func doesBranchExist(ref: String) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ struct GitHubCommand: ParsableCommand {
let branchName = $0.branchNameForUpdate
let remoteBranchExist = git.doesRemoteBranchExist(branchName)
if remoteBranchExist {
print("Branch \(branchName) already exists on the remote.".yellow)
print("All changes in the branch will be overridden".yellow.bold)
}
if git.doesLocalBranchExist(branchName) {
print("Branch \(branchName) already exists locally.".yellow)
try git.removeLocalBranch(name: branchName)
}
try git.createBranch(name: branchName)
try $0.update(in: folder)
try git.commit(message: $0.changeDescription)
try git.pushBranch(name: branchName)
if !remoteBranchExist {
try gitHub.createPullRequest(branchName: branchName, title: $0.changeDescription)
do {
try $0.update(in: folder)
try git.commit(message: $0.changeDescription)
try git.pushBranch(name: branchName)
if !remoteBranchExist {
try gitHub.createPullRequest(branchName: branchName, title: $0.changeDescription)
}
try git.backToBaseBranch()
} catch let SwiftPackageError.resultCountMismatch(name, count) where count == 0 { // false positive, count is an integer swiftlint:disable:this empty_count
print("Warning: Could not find version requirement for \(name) in Package.swift - " +
"this could be due to the dependency only beeing required on a specific platform.".yellow)
} catch {
throw error
}
try git.backToBaseBranch()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ struct UpdateCommand: ParsableCommand {
print("Everything is already up-to-date!".green)
} else {
try dependencies.forEach {
try $0.update(in: folder)
do {
try $0.update(in: folder)
} catch let SwiftPackageError.resultCountMismatch(name, count) where count == 0 { // false positive, count is an integer swiftlint:disable:this empty_count
print("Warning: Could not find version requirement for \(name) in Package.swift - " +
"this could be due to the dependency only beeing required on a specific platform.".yellow)
} catch {
throw error
}
}
}
} catch {
Expand Down
24 changes: 8 additions & 16 deletions Sources/SwiftDependencyUpdaterLibrary/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,15 @@ enum Update: Equatable {
case let .withChangingRequirements(version):
print("Updating \(dependency.name): \(dependency.resolvedVersion.versionNumberOrRevision) -> \(version)".bold)
let swiftPackage = SwiftPackage(in: folder)
do {
let packageUpdate = try swiftPackage.performUpdate(self, of: dependency)
print("Updated Package.swift".green)
if packageUpdate {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name ])
print("Resolved to new version".green)
} else {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", "resolve", ])
print("Resolved Version".green)
}
} catch let SwiftPackageError.resultCountMismatch(name, count) where count == 0 { // false positive, count is an integer swiftlint:disable:this empty_count
print("Warning: Could not find version requirement for \(name) in Package.swift - " +
"this could be due to the dependency only beeing required on a specific platform.".yellow)
} catch {
throw error
let packageUpdate = try swiftPackage.performUpdate(self, of: dependency)
print("Updated Package.swift".green)
if packageUpdate {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name ])
print("Resolved to new version".green)
} else {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", "resolve", ])
print("Resolved Version".green)
}

case let .withoutChangingRequirements(version):
print("Updating \(dependency.name): \(dependency.resolvedVersion.versionNumberOrRevision) -> \(version)".bold)
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name, ])
Expand Down