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

Git.changedLines returns empty values for PullRequestChangedLines object #250

Open
IvanSanchez-uam opened this issue Jul 12, 2023 · 1 comment · May be fixed by #297
Open

Git.changedLines returns empty values for PullRequestChangedLines object #250

IvanSanchez-uam opened this issue Jul 12, 2023 · 1 comment · May be fixed by #297

Comments

@IvanSanchez-uam
Copy link

I have these lines in my Danger.df.kts file

 warn("Additions = ${git.changedLines.additions}")
 warn("Deletions = ${git.changedLines.deletions}")
 warn("Diff = ${git.changedLines.diff ?: ""}")

in my case I want to get the diff but when calling changedLines extension function just give me

Additions = 0
Deletions = 0
Diff = null

is this extension function really working?, is there another way to get the diff?

I also tried to use the github.pullRequest but there is no a diff value here.

I have the feeling that these lines are not working

val Git.changedLines: PullRequestChangedLines
    get() {
        ...
        val commandRawOutput = shellExecutor.execute("git diff --numstat $headSha $baseSha")
        ...
        val commandRawDiffOutput = shellExecutor.execute("git diff $headSha $baseSha")
        return PullRequestChangedLines(additions, deletions, commandRawDiffOutput)
    }
@grine4ka
Copy link

So, I investigate a bit more and here what I came to.

The whole git diff was a bit... reverted. What do I mean?
git.changedLines.diff didn't show anything because baseSha and headSha should be swapped.

To demonstrate current behaviour I've opened MR in my danger/kotlin fork: grine4ka#3.
As you can see git.changedLines.diff shows additions and deletions reverted. Compare it with GitHub's Files Changed tab.

@IvanSanchez-uam BTW, if you use GitHub you should change fetch-depth to your checkout github action. Because by default it checks out a shallow clone with no history in it. So some commits are not visible on CI.

grine4ka added a commit to grine4ka/kotlin that referenced this issue Dec 11, 2024
- Fix getting `baseSha` and `headSha`. Now I get `baseSha` from first commit, and `headSha` is got from the last commit. Need to sort commits by author date to be ordered chronologically
- Reverted `baseSha` and `headSha` when computing `git diff`
- Due to swapping `baseSha` and `headSha` also swapped additions and deletions in computation lambdas

Closes danger#250
@grine4ka grine4ka linked a pull request Dec 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants