Open source

Utility tools

Danger.js

Danger.js is a tool that we use to automate certain aspects of our code review process.

Checks that we automate include:

  • Ensuring that the package.json has been updated so that the package can be successfully published to NPM
  • Making sure that each code change has an entry in the packages CHANGELOG so that the history is kept up to date.

We automate Danger.js checks through Travis once a package is moved from being private to public.


Setting up Danger.js on a repository

To setup Danger.js to run checks automatically on your repositories PRs, follow these steps:

  • In the root folder of your project, run yarn add danger --dev in the terminal to add Danger.js as a development dependency.
  • Ensure you have a .travis.yml in your project root and that it has the script setting – yarn danger ci – such as it's shown in generator-fozzie.
  • Add a dangerfile.js to the root of your repository and make sure it matches the one in the generator.
  • Ensure you have a .babelrc file in the root of your project and that it contains at least an empty object {}. This is because of an issue with babel-jest which needs to be worked around for now.
  • Once the above is done, you need to allow fozzie-bot (our Github bot account) to post on your project PRs on behalf of Danger.js.
    • First of all, your repository will need to be public (see the Web Wiki for details on the steps to do this).
    • Once public, go to https://travis-ci.org/justeat/ and find your module in the list of repositories (you may need to click on the "Sync account" button in your profile to update your list of Github packages and make sure the package is ticked in the list of packages displayed).
    • Then go to "More Options > Settings" for your repository in Travis (see image below). Then add the following environment variable:
       
      DANGER_GITHUB_API_TOKEN = {FOZZIEBOT_API_TOKEN}
       
      {FOZZIEBOT_API_TOKEN} can simply be copied from the Travis build settings that already has this token set (i.e. any Fozzie package already setup on Travis).
      Once set, make sure you switch the option to "Display value in build log" to On – this is so that the module can also run the checks on PRs submitted from a fork of your Github repo.
      Travis Settings
  • Make a PR and merge the above changes into your repository.