Skip to content

Commit

Permalink
Merge branch 'master' into drop-swift-5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
f-meloni authored Sep 15, 2024
2 parents 8260ca0 + d99c795 commit 172603d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- Drop Swift 5.7 [@417-72KI][] - [#620](https://github.com/danger/swift/pull/620)
- Fix pattern for detecting SwiftLint in package [@417-72KI][] - [#616](https://github.com/danger/swift/pull/616)
- Allow optional GitLab MR description [@kvvzr][] - [#609](https://github.com/danger/swift/pull/609)

## 3.18.1

Expand Down
3 changes: 2 additions & 1 deletion Sources/Danger/GitLabDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public extension GitLab {
public let changesCount: String
public let closedAt: Date?
public let closedBy: User?
public let description: String
public let description: String?
public let diffRefs: DiffRefs
public let downvotes: Int
public let firstDeployedToProductionAt: Date?
Expand Down Expand Up @@ -273,6 +273,7 @@ public extension GitLab {
case active
case blocked
case deactivated
case ldapBlocked = "ldap_blocked"
}

public let avatarUrl: String?
Expand Down
24 changes: 12 additions & 12 deletions Sources/DangerDependenciesResolver/InlineDependenciesFinder.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import Foundation
import Version

struct InlineDependenciesFinder {
let fileReader: FileReading
let config: ScriptManager.Config

init(fileReader: FileReading = FileReader(),
config: ScriptManager.Config) {
config: ScriptManager.Config)
{
self.fileReader = fileReader
self.config = config
}

func resolveInlineDependencies(fromPath path: String,
dangerSwiftVersion: String) throws -> [InlineDependency] {
dangerSwiftVersion: Version) throws -> [InlineDependency]
{
let lines = try fileReader.readText(atPath: path).components(separatedBy: .newlines)

var result: [InlineDependency] = [.dangerSwift(version: dangerSwiftVersion)]
Expand Down Expand Up @@ -45,7 +48,8 @@ struct InlineDependenciesFinder {

result.append(InlineDependency(url: url, major: majorVersion))
} else if let firstCharacter = line.unicodeScalars.first,
!CharacterSet.alphanumerics.contains(firstCharacter) {
!CharacterSet.alphanumerics.contains(firstCharacter)
{
break
}
}
Expand All @@ -70,15 +74,11 @@ extension InlineDependenciesFinder {
}

extension InlineDependenciesFinder.InlineDependency {
static func dangerSwift(version: String) -> Self {
let components = version.split(separator: ".")
.compactMap { Int($0) }
precondition(components.count == 3)

return .init(url: dangerSwiftRepoURL,
major: components[0],
minor: components[1],
patch: components[2])
static func dangerSwift(version: Version) -> Self {
.init(url: dangerSwiftRepoURL,
major: version.major,
minor: version.minor,
patch: version.patch)
}
}

Expand Down
21 changes: 15 additions & 6 deletions Sources/DangerDependenciesResolver/Script.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DangerShellExecutor
import Foundation
import Logger
import Version

public struct ScriptManager {
public struct Config {
Expand All @@ -10,7 +11,8 @@ public struct ScriptManager {

public init(prefix: String = "package: ",
file: String = "Dangerplugins",
major: String = "~> ") {
major: String = "~> ")
{
dependencyPrefix = prefix
dependencyFile = file
majorVersionPrefix = major
Expand All @@ -22,6 +24,7 @@ public struct ScriptManager {
case invalidInlineDependencyURL(String)
case failedToAddDependencyScript(String)
case scriptNotFound(String)
case invalidDangerSwiftVersion
}

private let config = Config()
Expand All @@ -36,7 +39,8 @@ public struct ScriptManager {
public init(folder: String,
dangerSwiftVersion: String,
packageManager: PackageManager,
logger: Logger) throws {
logger: Logger) throws
{
self.dangerSwiftVersion = dangerSwiftVersion
self.folder = folder
self.logger = logger
Expand All @@ -56,6 +60,10 @@ public struct ScriptManager {
}

private func script(fromPath path: String) throws -> Script {
guard let dangerSwiftVersion = Version(dangerSwiftVersion) else {
throw Errors.invalidDangerSwiftVersion
}

let identifier = scriptIdentifier(fromPath: path)
let folder = try createFolderIfNeededForScript(withIdentifier: identifier, filePath: path)
let script = Script(name: path.nameExcludingExtension, folder: folder, logger: logger)
Expand Down Expand Up @@ -95,9 +103,9 @@ public struct ScriptManager {

let moduleFolder = try sourcesFolder.createSubfolder(withName: filePath.nameExcludingExtension)

FileManager.default.createFile(atPath: moduleFolder.appendingPath("main.swift"),
contents: Data(try String(contentsOfFile: filePath).utf8),
attributes: [:])
try FileManager.default.createFile(atPath: moduleFolder.appendingPath("main.swift"),
contents: Data(String(contentsOfFile: filePath).utf8),
attributes: [:])

return scriptFolder
}
Expand Down Expand Up @@ -215,7 +223,8 @@ public final class Script {
func executeSwiftCommand(_ command: String,
onFolder folder: String? = nil,
arguments: [String] = [],
executor: ShellExecutor) throws -> String {
executor: ShellExecutor) throws -> String
{
func resolveSwiftPath() -> String {
#if os(Linux)
return "swift"
Expand Down
1 change: 0 additions & 1 deletion Sources/Runner/Commands/Edit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func editDanger(version dangerSwiftVersion: String, logger: Logger) throws {
separator: "\n")
exit(1)
}

absoluteLibPath = libPath.fullPath
libsImport = ["-l Danger"]
}
Expand Down

0 comments on commit 172603d

Please sign in to comment.