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

Fix: [git] JSONDiffForFile when passed the path of a JSON File that was moved, crashes #1197

Merged
merged 2 commits into from
Jan 15, 2022

Conversation

fbartho
Copy link
Member

@fbartho fbartho commented Jan 14, 2022

Don't crash when danger.git.JSONDiffForFile encounters a moved JSON file

Notably affects danger-plugin-yarn; when a package.json is moved, it slips by a test in JSONPatchForFile that filters for danger.git.modified_files, and I couldn't figure out how to fix getFileContents so it could look up the old file's contents using the new file path.

Note: I also couldn't figure out how to generate the right fixtures, or how to mock JSONPatchForFile

Fixes: #1181
Related: #481

Some useful test data
const diff = {
  before: null,
  after: {
    name: '@fbartho/something',
    description: 'this is irrelevant',
    version: '1.0.0',
    private: true,
    main: './dist/main.js',
    dependencies: { express: '^4.17.1' }
  },
}

const outerDiff = [
    { op: 'add', path: '/name', value: '@fbartho/something' },
    {
      op: 'add',
      path: '/description',
      value: 'this is irrelevant'
    },
    { op: 'add', path: '/version', value: '1.0.0' },
    { op: 'add', path: '/private', value: true },
    { op: 'add', path: '/main', value: './dist/main.js' },
    { op: 'add', path: '/dependencies', value: [Object] },
  ]

Notably affects danger-plugin-yarn, when a package.json is moved

Fixes: #1181
Related: #481
@fbartho fbartho requested a review from orta January 14, 2022 21:30
source/platforms/git/gitJSONToGitDSL.ts Outdated Show resolved Hide resolved
Co-authored-by: Orta Therox <orta.therox@gmail.com>
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 this pull request may close these issues.

[BUG] Github/Git JSON DSL Parse Error -- when moving Folders/Files
2 participants