Swiftpack.co - el-hoshino/DangerSwiftHammer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
el-hoshino/DangerSwiftHammer
"Everything can be fixed with a hammer." - Jeremy Clarkson
.package(url: "https://github.com/el-hoshino/DangerSwiftHammer.git", from: "0.1.2")

DangerSwiftHammer

Handy properties and methods for Danger-Swift!

*Currently this package only have 2 methods, one to get patch text for a file, and one to get additions and deletions lines for a file.

Install DangerSwiftHammer

Marathon

  • Add this to your Dangerfile.swift
import DangerSwiftHammer // package: https://github.com/el-hoshino/DangerSwiftHammer.git
  • Run danger-swift edit from project directory and it should resolve the dependencies automatically.

  • (Recommended) Cache the ~/.danger-swift folder

Usage

let danger = Danger()
danger.hammer.//...

Get patch text for file

let danger = Danger()
//...

let file = pathToFile
let patch = danger.hammer.diffPatch(for: file)
/*
 index 4888aaa..4c293b9 100644
 --- a/Package.swift
 +++ b/Package.swift
 @@ -1,4 +1,4 @@
 -// swift-tools-version:5.2
 +// swift-tools-version:5.1
  // The swift-tools-version declares the minimum version of Swift required to build this package.
  
  import PackageDescription
 @@ -14,13 +14,14 @@ let package = Package(
      dependencies: [
          // Dependencies declare other packages that this package depends on.
          // .package(url: /* package url */, from: "1.0.0"),
 +        .package(url: "https://github.com/danger/swift.git", from: "3.0.0"),
      ],
      targets: [
          // Targets are the basic building blocks of a package. A target can define a module or a test suite.
          // Targets can depend on other targets in this package, and on products in packages which this package depends on.
          .target(
              name: "DangerSwiftHammer",
 -            dependencies: []),
 +            dependencies: ["Danger"]),
          .testTarget(
              name: "DangerSwiftHammerTests",
              dependencies: ["DangerSwiftHammer"]),
 */
// Do something with your patch

Get additions and deletions lines for file

let danger = Danger()
//...

let file = pathToFile
let lines = danger.hammer.diffLines(in: file)
let additions = lines.additions
/*
 [
     #"-// swift-tools-version:5.2"#,
     #"-            dependencies: []),"#,
 ],
 */
let deletions = lines.deletions
/*
 [
     #"+// swift-tools-version:5.1"#,
     #"+        .package(url: "https://github.com/danger/swift.git", from: "3.0.0"),"#,
     #"+            dependencies: ["Danger"]),"#,
 ]
 */
// Do something with your additions and deletions

Having suggestions?

Open an issue!

Why is this package called "DangerSwiftHammer"?

"Everything can be fixed with a hammer." - Jeremy Clarkson

GitHub

link
Stars: 2
Last commit: 22 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

0.1.1
1 year ago

Fixed

  • File diff parsing is now against base branch.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics