Skip to content

Commit

Permalink
Merge remote-tracking branch 'original/master' into file_line_api
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinejr committed Mar 18, 2018
2 parents d3eadca + 26793f1 commit c13ecb7
Show file tree
Hide file tree
Showing 51 changed files with 381 additions and 170 deletions.
14 changes: 8 additions & 6 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[ignore]
distribution
.*/_tests/.*
.*dangerfile.js
node_modules/jest*/**/**
.*/source/.*
.*/node_modules/.*

[include]
dangerfile.flow.js

[libs]
flow-typed/
distribution/danger.js.flow

[lints]

[options]
unsafe.enable_getters_and_setters=true

[strict]
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ docs/js_ref_dsl_docs.json
types/index.d.ts
.jest/
test-results.json

# Flowgen stuff
source/_danger.d.tse
source/_danger.d.ts
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ matrix:
after_script:
- rm -rf node_modules/@types/babel-*
- rm -rf node_modules/@types/babylon
- echo "Testing that the Danger d.ts file lints"
- yarn docs
- yarn add dtslint@0.1.2
- yarn dts-lint
- echo "Testing Flow definition file"
- yarn build:flow-types
- yarn flow check

# Checks every example dangerfile can run in `danger runner`.
- node_js: '8.4'
Expand Down
58 changes: 57 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,62 @@

## Master

* []

## 3.2.0

=======

* Add BitBucket Server support.

To use Danger JS with BitBucket Server: you'll need to create a new account for Danger to use,
then set the following environment variables on your CI:

* `DANGER_BITBUCKETSERVER_HOST` = The root URL for your server, e.g. `https://bitbucket.mycompany.com`.
* `DANGER_BITBUCKETSERVER_USERNAME` = The username for the account used to comment.
* `DANGER_BITBUCKETSERVER_PASSWORD` = The password for the account used to comment.

Then you will have a fully fleshed out `danger.bitbucket_server` object in your Dangerfile to work with,
for example:

```ts
import { danger, warn } from "danger"

if (danger.bitbucket_server.pr.title.includes("WIP")) {
warn("PR is considered WIP")
}
```

The DSL is fully fleshed out, you can see all the details inside the [Danger JS Reference][ref],
but the summary is:

```ts
danger.bitbucket_server.
/** The pull request and repository metadata */
metadata: RepoMetaData
/** The related JIRA issues */
issues: JIRAIssue[]
/** The PR metadata */
pr: BitBucketServerPRDSL
/** The commits associated with the pull request */
commits: BitBucketServerCommit[]
/** The comments on the pull request */
comments: BitBucketServerPRActivity[]
/** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
activities: BitBucketServerPRActivity[]
```

You can see more in the docs for [Danger + BitBucket Server](http://danger.systems/js/usage/bitbucket_server.html).

* [@azz][]

* Don't check for same user ID on comment when running as a GitHub App. [@tibdex][]

## 3.1.8

* Improvements to the Flow definition file. [@orta][]
* Improve path generator for danger-runner.
* Update the PR DSL to include bots. [@orta][]
* Add BitBucket server support. [@azz][]

## 3.1.7

Expand Down Expand Up @@ -908,3 +962,5 @@ Not usable for others, only stubs of classes etc. - [@orta][]
[@hongrich]: https://github.com/hongrich
[@peterjgrainger]: https://github.com/peterjgrainger
[@azz]: https://github.com/azz
[@mifi]: https://github.com/ionutmiftode
[ref]: http://danger.systems/js/reference.html
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This provides another logical step in your process, through which Danger can hel

You can use Danger to codify your teams norms, leaving humans to think about harder problems.

Danger JS currently works with GitHub and Travis CI, Circle CI, Semaphore, Jenkins, Docker Cloud, Bitrise, surf-build,
Danger JS currently works with GitHub or BitBucket Server and Travis CI, Circle CI, Semaphore, Jenkins, Docker Cloud, Bitrise, surf-build,
Codeship, Drone, Buildkite, Nevercode, buddybuild or Visual Studio Team Services.

[![npm](https://img.shields.io/npm/v/danger.svg)](https://www.npmjs.com/package/danger) [![Build Status](https://travis-ci.org/danger/danger-js.svg?branch=master)](https://travis-ci.org/danger/danger-js) [![Build Status](https://ci.appveyor.com/api/projects/status/ep5hgeox3lbc5c7f?svg=true)](https://ci.appveyor.com/project/orta/danger-js/branch/master) [![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/danger)
Expand Down Expand Up @@ -75,6 +75,10 @@ yarn lint
The fixers for both tslint and prettier will be applied when you commit, and on a push your code will be verified that
it compiles.

### How does Danger JS work?

Check the [architecture doc](https://github.com/danger/danger-js/blob/master/docs/architecture.md).

### What is the TODO?

Check the issues, I try and keep my short term perspective there. Long term is in the [VISION.md](VISION.md).
Expand Down
8 changes: 8 additions & 0 deletions dangerfile.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file isn't used anywhere, but it is used as a part of `yarn flow check`
// to validate that flow typings work correctly for JS Dangerfiles

// @flow

import { danger } from "danger"

danger.github.pr
35 changes: 34 additions & 1 deletion docs/guides/faq.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ blurb: Common questions that come up in our GitHub issues.

## Can Danger comment inside a file on an PR?

Not yet, but there is a lot of discussion on [danger-js#77][77].
Not yet, but there is a lot of discussion on [danger-js#77][77] and a [WIP PR here][529].

## Can I use the same Dangerfile across many repos?

Expand All @@ -24,6 +24,38 @@ Let's say you run Danger on the same CI service that deploys your code. If that'

This ensures that Danger only runs when you have the environment variables set up to run. This is how Danger works for a lot of the open source mobile projects in Artsy.

## Danger is not posting to GitHub PRs, but everything looks fine?

Try logging in to the GitHub account that should be writing the messages, it's possible that your account has triggered the bot detection algorithm on GitHub. This means that messages are sent correctly, but do not show up for anyone except the sender. This makes it more or less impossible to detect from Danger's side.

## I'm not sure what Danger is doing

If you run danger with `DEBUG="*"` prefixed, you'll get a lot of information about what's happening under the hood. E.g:

```sh
DEBUG="*" DANGER_GITHUB_API_TOKEN=[123] yarn danger pr https://github.com/facebook/react/pull/11865
```

or on the CI:

```sh
DEBUG="*" yarn danger ci
```

This will print out a _lot_ of information.

## Circle CI doesnt run my build consistently

Yeah... We're struggling with that one. It's something we keep taking stabs at improving, so [keep an eye on the issues][circle_issues]. Ideally this issue will get resolved and we'll get it [fixed for free][circle_pr].

What happens is that Circle triggers a CI build before the PR has been set up, and so Danger cannot get information
about the corresponding repo and PR. Danger on Circle with use the Circle API to try and hook itself up to the right PR, so if you have `yarn danger ci` later on in the process, you'll have a better chance of them hooking up.

This can be worked around by sending PRs from forks.

[circle_issues]: https://github.com/danger/danger-js/search?q=circle&state=open&type=Issues&utf8=✓
[circle_pr]: https://discuss.circleci.com/t/pull-requests-not-triggering-build/1213

## I want to help influence Danger's direction

We'd recommend first becoming acquainted with the [VISION.md][] inside Danger, this is the long-term plan. Then there are two ways to start contributing today:
Expand All @@ -35,6 +67,7 @@ We'd recommend first becoming acquainted with the [VISION.md][] inside Danger, t
We keep comments in the public domain, there is a Slack, but it's very rarely used. If you're interested in joining, you can DM [orta][].

[77]: https://github.com/danger/danger-js/issues/77
[529]: https://github.com/danger/danger-js/issues/529
[vision.md]: https://github.com/danger/danger-js/blob/master/VISION.md
[open]: https://github.com/danger/danger-js/issues?q=is%3Aissue+is%3Aopen+label%3A%22Open+for+Discussion%22
[you-can-do-this]: https://github.com/danger/danger-js/issues?q=is%3Aissue+is%3Aopen+label%3A%22You+Can+Do+This%22
Expand Down
18 changes: 11 additions & 7 deletions docs/guides/the_dangerfile.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,52 @@ blurb: Step two on using Danger in your app, how to work locally and nuances aro

The Danger JS DSL is fully typed via TypeScript. These definitions are shipped with the Danger module. If your text editor supports working with type definitions you will get inline-documentation and auto-completion after you import danger in your Dangerfile. Visual Studios Code will do this by default for you.

If you are using Babel in your project, your Dangerfile will use the same transpilation settings. If you're using TypeScript + Jest it will work out of the box too, however, if you don't, you should head over to the [transpilation guide][transpilation_guide]
If you are using Babel in your project, your Dangerfile will use the same transpilation settings. If you're using TypeScript + Jest it will work out of the box too, however, if you don't, you should head over to the [transpilation guide][transpilation_guide].

## Working on your Dangerfile

There are two ways to locally work on your Dangerfile. These both rely on using the GitHub API locally, so you may hit the GitHub API rate-limit or need to have authenticated request for private repos. In which case you can use an access token to do authenticated requests by exposing a token to Danger.

```sh
export DANGER_GITHUB_API_TOKEN='xxxxxxxxxx'
export DANGER_GITHUB_API_TOKEN='xxxx'

# or for BitBucket
export DANGER_BITBUCKETSERVER_HOST='xxxx' DANGER_BITBUCKETSERVER_USERNAME='yyyy' DANGER_BITBUCKETSERVER_PASSWORD='zzzz'
```

Then the danger CLI will use these authenticated API calls.
Then the danger CLI will use authenticated API calls, which don't get this by API limits.

### Using `danger pr`

The command `danger pr` expects an argument of a PR url, e.g. `yarn danger pr https://github.com/danger/danger-js/pull/100`.

This will use your local Dangerfile against the metadata of the linked PR. Danger will then output the results into your terminal, instead of inside the PR itself.

This _will not_ post comments. It is for locally testing, see `yarn danger pr --help` for more info.

### Using `danger` and Faking being on a CI

If you create an [appropriately scoped temporary api token](http://danger.systems/guides/getting_started.html#setting-up-an-access-token) for your github account, this can be a good way to see if danger is suitable for you before integrating it into your CI system.
If you create an [appropriately scoped temporary api token](http://danger.systems/js/guides/getting_started.html#setting-up-an-access-token) for your GitHub account, this can be a good way to see if danger is suitable for you before integrating it into your CI system.

You can manually trigger danger against a pull request on the command line by setting the following environmental variables:

```bash
export DANGER_FAKE_CI="YEP"
export DANGER_GITHUB_API_TOKEN='xxxxxxxxxx' # a github api token
export DANGER_TEST_REPO='username/reponame'
```

Then you can run against a local branch that is attached to a pull-request, by running the following:

```bash
git checkout branch-for-pr-1234
DANGER_TEST_PR='1234' npm run danger
DANGER_TEST_PR='1234' yarn danger ci
```

Assuming that your local file-system matches up to that branch on GitHub, this will be a good approximation of how danger will work when you integrate it into your CI system. Note: this will leave a comment on the PR.

## Working with files

Over time, we've found it easier to create up-front arrays of files you are be interested in - then you can work with these potential arrays of files. For example:
Over time, we've found it easier to create up-front arrays of files you are interested in - then you can work with these potential arrays of files. For example:

```js
import { danger } from "danger"
Expand Down
34 changes: 0 additions & 34 deletions docs/guides/troubleshooting.html.md

This file was deleted.

77 changes: 77 additions & 0 deletions docs/usage/bitbucket_server.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: Danger + BitBucket Server
subtitle: Dangerous bits
layout: guide_js
order: 4
blurb: An overview of using Danger with BitBucket Server, and some examples
---

To use Danger JS with BitBucket Server: you'll need to create a new account for Danger to use,
then set the following environment variables on your CI:

* `DANGER_BITBUCKETSERVER_HOST` = The root URL for your server, e.g. `https://bitbucket.mycompany.com`.
* `DANGER_BITBUCKETSERVER_USERNAME` = The username for the account used to comment.
* `DANGER_BITBUCKETSERVER_PASSWORD` = The password for the account used to comment.

Then in your Dangerfiles you will have a fully fleshed out `danger.bitbucket_server` object to work with. For example:

```ts
import { danger, warn } from "danger"

if (danger.bitbucket_server.pr.title.includes("WIP")) {
warn("PR is considered WIP")
}
```

The DSL is expansive, you can see all the details inside the [Danger JS Reference][ref],
but the TLDR is:

```ts
danger.bitbucket_server.

/** The pull request and repository metadata */
metadata: RepoMetaData
/** The related JIRA issues */
issues: JIRAIssue[]
/** The PR metadata */
pr: BitBucketServerPRDSL
/** The commits associated with the pull request */
commits: BitBucketServerCommit[]
/** The comments on the pull request */
comments: BitBucketServerPRActivity[]
/** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
activities: BitBucketServerPRActivity[]
```

Here are some example rules using the DSL:

```ts
import { danger, warn } from "danger"

const bbs = danger.bitbucket_server

// Ensure a PR has assigned Jira issues
if (bbs.issues.length === 0) {
warn("This PR does not have any assigned Jira issues.")
}

// Make a warning if there are changes to a package.json but that a
// user called murphdog hasn't yet weighed in that the changes are fine.
const hasPackageChanges = danger.git.modified_files.includes("package.json")
const hasMurphDogApproval = bbs.comments.find(
c => c.user.slug == "murphdog" && !!c.comment && c.comment.text.includes(":+1:")
)
if (hasPackageChanges && !hasMurphDogApproval) {
warn("This PR has `package.json` changes, but @murphdog hasn't approved them yet.")
}

// Enforce team "fun"
const hasGIF = bbs.pr.description.includes(".gif")
if (hasGIF) {
fail("This PR needs a GIF.")
}
```

Plus any other example you can find that uses GitHub, will probably work in BitBucket Server, with a bit of DSL translation.

Our BitBucket Server support is still pretty new, so we'd love to see improvements and PRs to help make it work for everyone.

0 comments on commit c13ecb7

Please sign in to comment.