Skip to content

Commit

Permalink
Do not create a PR if a dependency was not found (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 authored May 5, 2022
1 parent df6e696 commit 1730135
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
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

0 comments on commit 1730135

Please sign in to comment.