swift icon indicating copy to clipboard operation
swift copied to clipboard

How to get fileDiff from danger-swift?

Open antranapp opened this issue 7 years ago • 5 comments

I see that danger-js can get the the diffs for git here https://github.com/danger/danger-js/blob/8f55336f0c0c5443d29cc0d886123c365e5f225b/source/dsl/GitDSL.ts But I don't know if it is available in danger-swift. Or anyone knows how to get the file diffs with danger-swift?

antranapp avatar Mar 19 '19 14:03 antranapp

This would need to be re-implemented in Swift I'm afraid, the same data is available - so it could be a matter of copy&pasting then making syntax work

orta avatar Mar 19 '19 14:03 orta

Is there a chance this was addressed / there is a plan to address this? I am hoping to have Danger set a limit for how many insertions and deletions a PR can be, but I want this limit to exclude some file types (.xib files for example).

ethan-riback avatar Apr 15 '20 18:04 ethan-riback

This would need to be re-implemented in Swift I'm afraid, the same data is available - so it could be a matter of copy&pasting then making syntax work

@orta could you point me out which file should be re written to support the diffs? So that I can work on that.

erkekin avatar Apr 18 '20 22:04 erkekin

I’m not sure anymore been a few years since I looked, you take the incoming JSON and and do work with that. The codebase is small, you can find it

orta avatar Apr 18 '20 22:04 orta

I made a little helper which might help anyone else looking into getting line diff counts with excluded files, as I couldn't see anything natively in danger-swift: https://gist.github.com/ceeK/1e9623b2e86478bd68ad12082a5b1a35

Callsite:

let excludedFiles = [
    ".generated.swift",
]
let diff = ExcludedDiff.diff(withExcludedFiles: excludedFiles, sourceBranch: "origin/master")
// diff.totalAdditions
// diff.totalDeletions

Luckily the file diff function was added towards the end of 2020 :)

ceeK avatar Jun 15 '21 20:06 ceeK