Skip to content

Adds support for using Danger on PRs #2508

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

Merged
merged 9 commits into from
Jan 7, 2017
Merged

Adds support for using Danger on PRs #2508

merged 9 commits into from
Jan 7, 2017

Conversation

orta
Copy link
Member

@orta orta commented Jan 5, 2017

Summary

Adds Danger.

With initial Danger rules:

  • Warns on No new un-flowed JS file
  • Fails build when FB Copyright header is not included

Test plan

This Dangerfile does not have the FB Copyright Header, so once Danger is set up she should fail this build.

Discussion

  • I based this on looking through a few PRs, will dig through a few more now that I've got something to show
  • Danger relies on Jest's packages, should/can I make the deps local paths inside yarn? So there's no duplication confusion

Setup

This requires a bit of config by @cpojer - you will need to go through the "creating a bot account" - as this is OSS, it should be a new account with zero privileges to any repos.

After that you'll need to add a token to travis for DANGER_GITHUB_API_TOKEN.

// ("/href/thing", "name") to "<a href="/href/thing">name</a>"
const createLink = (href: string, text: string): string =>
`<a href='${href}'>${text}</a>`;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these ^ are functions from Danger RB, in the future I should probably move them into DangerJS too - the use case seems pretty universal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah please do!

@orta
Copy link
Member Author

orta commented Jan 5, 2017

I think these CI fails are from our usage of jest-transform in Danger, so, this question becomes more important

Danger relies on Jest's packages, should/can I make the deps local paths inside yarn? So there's no duplication confusion


// ["1", "2", "3"] to "1, 2 and 3"
const toSentence = (array: Array<string>) : string =>
array.slice(0, array.length - 1).join(', ') + ' and ' + array.pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where the array has a length of 1? In that case this will return and 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, definitely! Good catch.

// New JS files should have the FB copyright header
const noFBCopyrightFiles = newJsFiles.filter(filepath => {
const content = fs.readFileSync(filepath).toString();
return !content.includes('Facebook, Inc. All rights reserved');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we make this more complete and check that the first thing in the file is the full FB copyright header?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, might need to be a regex ( the year is variable ) this was the constant part, I can build on this

@@ -43,7 +45,7 @@
"postinstall": "node ./scripts/postinstall.js && node ./scripts/build.js",
"publish": "yarn run build-clean && yarn run build && lerna publish",
"test": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest && yarn run test-examples",
"test-ci": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest-coverage -- -i && yarn run test-examples && node scripts/mapCoverage.js && codecov",
"test-ci": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest-coverage -- -i && yarn run test-examples && node scripts/mapCoverage.js && codecov && yarn run danger",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda wish danger could replace codecov.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume codecov reads some pre-existing files to derive output? It's totally feasible ( we have ruby Danger parsing JUnit files in our iOS app )

However, as you noted below, it's the state that doesn't necessarily work. In ruby Danger, there is a plugin for persistence (https://github.com/dbgrandi/danger-mcbrain) which could get replicated as a free heroku mongo somewhere or something to keep state

@cpojer
Copy link
Member

cpojer commented Jan 5, 2017

I'll get the access data for the jest-bot and will report back when I added the token.

A few things that would be nice (I will add more ideas some time):

  • Fails if there are merge commits in the PR.
  • Fails if there are changes to package.json without changes to yarn.lock.

Does Danger have any form of state? Can we potentially use it to compare the performance of the test run to master?

@orta
Copy link
Member Author

orta commented Jan 5, 2017

  • Added a stricter rule check for the copyright header
  • Added the package.json to yarn.lock check, but I made it warn, not fail, a version bump or changes to the scripts would trigger a fail.
  • Turns out danger needs support for reading the commits, they're not in the raw diff, which makes sense considering you need an API for commit comments etc [DSL] Add support for pulling in all the commits for a PR danger/danger-js#81

@cpojer
Copy link
Member

cpojer commented Jan 5, 2017

@orta I added the token to travis using jest-bot. Is there anything else I need to do?

@orta
Copy link
Member Author

orta commented Jan 5, 2017

The master CI is broken, I'm gonna test without running ESLinter et al

@orta orta force-pushed the danger branch 2 times, most recently from 069bdb9 to c7ede40 Compare January 5, 2017 21:19
@orta
Copy link
Member Author

orta commented Jan 5, 2017

@cpojer is it possible that you didn't give the github account access token the public scope? I'm getting a 403 when I use the one in travis, but it works fine with a random Artsy OSS one

@@ -0,0 +1,72 @@
// @flow

// const { danger, fail, warn } = require('danger');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on a release with danger/danger-js#82 to support having this uncommented ( Danger normally comments out these requires and injects the deps in at runtime. It's only there for tooling support )

@cpojer
Copy link
Member

cpojer commented Jan 5, 2017

I set the "Display value in build log" to "on". Is there something else I need to do?

@orta
Copy link
Member Author

orta commented Jan 5, 2017

I mean at this point:

screen shot 2017-01-05 at 5 37 35 pm

Everything else seems 👍

@cpojer
Copy link
Member

cpojer commented Jan 6, 2017

done!

@jest-bot
Copy link
Contributor

jest-bot commented Jan 6, 2017

Fails
🚫 New JS files do not have the Facebook copyright header: dangerfile.js
Warnings
⚠️ Please ensure that @flow and 'use strict' are enabled on: dangerfile.js

Generated by 🚫 dangerJS

@orta
Copy link
Member Author

orta commented Jan 6, 2017

Rock, that looks good to me. Will see if I can get enough time today to ship the commits API, otherwise might look over the weekend for that 👍

@cpojer
Copy link
Member

cpojer commented Jan 6, 2017

Awesome! Let me know when it's ready and doesn't spam people so much any more ;)

@rogeliog
Copy link
Contributor

rogeliog commented Jan 6, 2017

@orta the Flow link warning has a link to @flow => https://github.com/flow.... should it be in backticks instead? or should it link to the Flow website?

@cpojer cpojer merged commit 2b81d21 into jestjs:master Jan 7, 2017
cpojer added a commit to cpojer/jest that referenced this pull request Jan 7, 2017
cpojer added a commit that referenced this pull request Jan 7, 2017
)

* Cleanup travis install. We don’t need the latest npm3 any longer.

* Revert "Adds support for using Danger on PRs  (#2508)"

This reverts commit 2b81d21.
macklinu added a commit to danger/danger-js that referenced this pull request Jan 17, 2017
macklinu added a commit to danger/danger-js that referenced this pull request Jan 17, 2017
skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
* Initial Dangerfile, adds a rule for including flow and the FB header

* [Danger] Use a local path for jest-runtime instead of the downloaded NPM package

* [Danger] Makes the FB copyright header check correct

* just run danger

* Update Danger
skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
…stjs#2525)

* Cleanup travis install. We don’t need the latest npm3 any longer.

* Revert "Adds support for using Danger on PRs  (jestjs#2508)"

This reverts commit 2b81d21.
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* Initial Dangerfile, adds a rule for including flow and the FB header

* [Danger] Use a local path for jest-runtime instead of the downloaded NPM package

* [Danger] Makes the FB copyright header check correct

* just run danger

* Update Danger
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
…stjs#2525)

* Cleanup travis install. We don’t need the latest npm3 any longer.

* Revert "Adds support for using Danger on PRs  (jestjs#2508)"

This reverts commit 2b81d21.
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants