question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

structuredDiffForFile function returns incorrect results

See original GitHub issue

Hi there, I am using structuredDiffForFile method from GitDSL. I am using this function within the following code snippet:

function claimsToUpdateDocumentation() {
  let claimsToUpdateDocumentation = false
  danger.git.structuredDiffForFile(`${docsFolder}/CHANGEPLAN.md`)
    .then((diff) => {
      diff.chunks.forEach(chunk => {
        chunk.changes.forEach(change => {
          if (change.type === "add") {
            const offence = regexPattern.exec(change.content)
            if (offence) {
              claimsToUpdateDocumentation = true;
            }
          }
        })
      })
      return claimsToUpdateDocumentation;
    })
}

I got inspired about the usage of this method from metaphysics dangerfile.ts. Every-time danger is run on our CI (on premise BitBucket server) against a PR it gets the diff for CHANGEPLAN.md from previous PR. Example:

danger pr https://company.merck.com/projects/foo/repos/boo/pull-requests/2607

structuredDiffForFile returns me the diff of CHANGEPLAN.md from PR #2606 instead of returning diff from PR #2607.

Am I using structuredDiffForFile incorrectly? Or is it a bug?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
platancommented, Oct 8, 2019

Version 9.2.1 (node_modules/.bin/danger --version: 9.2.1) works properly with my simple project:

DANGER_BITBUCKETSERVER_HOST=http://localhost:7990/bitbucket DANGER_BITBUCKETSERVER_USERNAME=admin DANGER_BITBUCKETSERVER_TOKEN=ODIyNDUyOTIxMDAwOt5F4JwwCowf7nCX1ogkY9ybm+bd node_modules/.bin/danger pr http://localhost:7990/bitbucket/projects/PROJECT_1/repos/rep_1/pull-requests/2/overview
Starting Danger PR on projects/PROJECT_1/repos/rep_1#2
{ changes: 
   [ { type: 'normal',
       content: 'basic branching scenario',
       sourceLine: 1,
       destinationLine: 1 },
     { type: 'add',
       content: 'commit 1',
       sourceLine: 2,
       destinationLine: 2 },
     { type: 'add',
       content: 'commit 2',
       sourceLine: 2,
       destinationLine: 3 } ] }


Danger: ✓ passed review, received no feedback.

dangerfile.js:

danger.git.modified_files.forEach(file =>
  danger.git.structuredDiffForFile(file).then(diff => {
    console.log(diff.chunks[0]);
  })
);

I will try to test it on an instance of Bitbucket in my company.

1reaction
pajaprocommented, Oct 19, 2019

@platan I figured out that the problem was in our code 🤦‍♀️, so yes v9.2.1 with #871 solves the problem indeed! Sorry for confusion and thank you for help with resolving this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function returning wrong value - Stack Overflow
When i == 6 is not true , then execution reaches the end of func without encountering a return statement. This causes the...
Read more >
CHANGELOG - Danger.systems
Now a subprocess can pass a JSON URL for Danger JS by looking in STDOUT for the regex /danger-results:\/\/*.+json/ . There is now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found