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

Initial work on the CHANGELOG test, and adds a fail command #14

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### 0.0.2

OK, first usable for others version. Only supports GitHub and Travis CI.

You can run by doing:

```sh
danger
```

Make sure you set a `DANGER_GITHUB_API_TOKEN` on your CI - [see the Ruby guide](http://danger.systems/guides/getting_started.html#setting-up-danger-to-run-on-your-ci) for that.

Then you can make a `dangerfile.js` (has to be lowercase, deal with it.) It has access to a whopping 2 DSL attributes.

```sh
pr
git
fail(message: string)
```

`pr` _probably_ won't be sticking around for the long run, but if you're using a `0.0.2` release, you should be OK with that. It's the full metadata of the PR, so [this JSON file](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/github_api/pr_response.json).
`git` currently has:

```sh
git.modified_file
git.created_files
git.deleted_files
```

which are string arrays of files.

`fail(message: string)` will let you raise an error, and will make the process return 1 after the parsing has finished.

Overall: your Dangerfile should look something like:

```js
import { danger } from "danger"

const hasChangelog = danger.git.modified_files.includes("changelog.md")
if (!hasChangelog) {
fail("No Changelog changes!")
}
```

That should do ya. I think. This doens't support babel, and I haven't explored using other modules etc, so

./

### 0.0.1

Not usable for others, only stubs of classes etc.
6 changes: 5 additions & 1 deletion dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// @flow

// import danger from "danger"
import danger from "./source/danger"
import { danger, fail } from "./source/danger"

// warn on changes in Package.json and not in shrinkwrap
const hasChangelog = danger.git.modified_files.includes("changelog.md")
if (!hasChangelog) {
fail("No Changelog changes!")
}

// warn on changelog
// console.log(danger)
Expand Down
8 changes: 5 additions & 3 deletions source/danger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ type DangerDSL = {
git: GitDSL
}

const danger: DangerDSL = {
/** Fails the build */
export function fail(message: string) {
}

export const danger: DangerDSL = {
git: {
modified_files: ["hello world"],
created_files: ["other file"],
deleted_files: ["last file"]
}
}

export default danger
1 change: 0 additions & 1 deletion source/dsl/DangerDSL.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow
"use strict"

// import type { Platform } from "../platforms/platform"
import type { GitDSL } from "../dsl/Git"

export default class DangerDSL {
Expand Down
12 changes: 11 additions & 1 deletion source/runner/Dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default class Dangerfile {
// then user get typed data, and we fill it in
// via the VM context

const cleaned = data.replace(/import danger from/gi, "// import danger from")
const cleaned = data
.replace(/import danger /gi, "// import danger ")
.replace(/import { danger/gi, "// import { danger ")

const script = new vm.Script(cleaned, {
filename: file,
Expand All @@ -28,12 +30,20 @@ export default class Dangerfile {
timeout: 1000 // ms
})

let failed = false
const fail = (message: string) => {
console.error(message)
failed = true
}

const context: any = {
fail,
console,
danger: this.dsl
}

script.runInNewContext(context)
if (failed) { process.exitCode = 1 }
})
}
}
Expand Down