Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/danger/danger-js into dan…
Browse files Browse the repository at this point in the history
…ger-process
  • Loading branch information
orta committed Aug 22, 2017
2 parents b84b12c + 73b44e0 commit 1f60dc0
Show file tree
Hide file tree
Showing 11 changed files with 628 additions and 405 deletions.
11 changes: 2 additions & 9 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{
"presets": [
"es2015",
"stage-3"
],
"plugins": [
"transform-flow-strip-types",
"syntax-async-functions",
"transform-regenerator"
]
"presets": ["es2015", "stage-3"],
"plugins": ["syntax-async-functions", "transform-regenerator"]
}
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

// TODO

### 2.0.0-alpha.9

* Uses the Babel 7 alpha for all source compilation with JS, Flow+JS and TS. This worked without any changes to our
internal infra which is pretty awesome. All TS tests passed. Babel 7 is still in alpha, but so is Danger 2.0 - so I'm
happy to keep Danger in a pretty long alpha, till at least Babel 7 is in beta.

It also still supports using TypeScript via the "`typescript"` module, if you have that installed. - orta

* `danger.github.thisPR` now uses the PR's head, not base - orta

### 2.0.0-alpha.8

* Uses the GitHub `diff_url` instead of the `diff` version header, as it conflicted with Peril - orta
Expand Down
30 changes: 15 additions & 15 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ import { distanceInWords } from "date-fns"

// For some reason we're getting type errors on this includes module?
// Wonder if we could move to the includes function in ES2015?
import * as includesOriginal from "lodash.includes"
const includes = includesOriginal as Function

import * as includes from "lodash.includes"
const sentence = danger.utils.sentence

// Request a CHANGELOG entry if not declared #trivial
const hasChangelog = includes(danger.git.modified_files, "changelog.md")
const isTrivial = includes(danger.github.pr.body + danger.github.pr.title, "#trivial")
const isGreenkeeper = danger.github.pr.user.login === "greenkeeper"
schedule(async () => {
// Request a CHANGELOG entry if not declared #trivial
const hasChangelog = includes(danger.git.modified_files, "changelog.md")
const isTrivial = includes(danger.github.pr.body + danger.github.pr.title, "#trivial")
const isGreenkeeper = danger.github.pr.user.login === "greenkeeper"

if (!hasChangelog && !isTrivial && !isGreenkeeper) {
warn("Please add a changelog entry for your changes.")
if (!hasChangelog && !isTrivial && !isGreenkeeper) {
warn("Please add a changelog entry for your changes.")

// Politely ask for their name on the entry too
const changelogDiff = danger.git.diffForFile("changelog.md")
const contributorName = danger.github.pr.user.login
if (changelogDiff && !includes(changelogDiff, contributorName)) {
warn("Please add your GitHub name to the changelog entry, so we can attribute you correctly.")
// Politely ask for their name on the entry too
const changelogDiff = await danger.git.diffForFile("changelog.md")
const contributorName = danger.github.pr.user.login
if (changelogDiff && !includes(changelogDiff.diff, contributorName)) {
warn("Please add your GitHub name to the changelog entry, so we can attribute you correctly.")
}
}
}
})

import yarn from "danger-plugin-yarn"
schedule(yarn())
Expand Down
9 changes: 9 additions & 0 deletions docs/guides/troubleshooting.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ This seems to happen when you have multiple versions of Jest inside the same pro
#### 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.

## 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].

[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


22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "2.0.0-alpha.8",
"version": "2.0.0-alpha.9",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down Expand Up @@ -56,14 +56,18 @@
"@types/commander": "^2.3.31",
"@types/debug": "0.0.29",
"@types/jest": "^20.0.0",
"@types/lodash.includes": "^4.3.3",
"@types/node-fetch": "^1.6.6",
"babel-cli": "~6.24.1",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-3": "^6.22.0",
"danger-plugin-yarn": "^0.2.9",
"babel-cli": "7.0.0-alpha.19",
"babel-core": "7.0.0-alpha.19",
"babel-plugin-syntax-async-functions": "7.0.0-alpha.19",
"babel-plugin-transform-flow-strip-types": "7.0.0-alpha.19",
"babel-plugin-transform-regenerator": "7.0.0-alpha.19",
"babel-plugin-transform-typescript": "7.0.0-alpha.19",
"babel-preset-es2015": "7.0.0-alpha.19",
"babel-preset-stage-3": "7.0.0-alpha.19",
"babel-traverse": "7.0.0-alpha.19",
"danger-plugin-yarn": "^1.0.0",
"date-fns": "^1.28.3",
"husky": "^0.14.0",
"jest": "^20.0.4",
Expand All @@ -79,7 +83,7 @@
"typescript": "^2.4.2"
},
"dependencies": {
"babel-polyfill": "^6.20.0",
"babel-polyfill": "7.0.0-alpha.19",
"chalk": "^2.0.0",
"commander": "^2.9.0",
"debug": "^3.0.0",
Expand Down
6 changes: 3 additions & 3 deletions source/platforms/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export class GitHub {
}

/**
* Converts the PR JSON into something easily used by the Github API client
* Converts the PR JSON into something easily used by the Github API client.
*/
APIMetadataForPR(pr: GitHubPRDSL): GitHubAPIPR {
return {
number: pr.number,
repo: pr.base.repo.name,
owner: pr.base.repo.owner.login,
repo: pr.head.repo.name,
owner: pr.head.repo.owner.login,
}
}
}
10 changes: 10 additions & 0 deletions source/platforms/_tests/_github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ describe("getPlatformDSLRepresentation", () => {
const { pr } = await github.getPlatformDSLRepresentation()
expect(pr.number).toEqual(327)
})

it("should set thisPR correct", async () => {
const dsl = await github.getPlatformDSLRepresentation()

expect(dsl.thisPR).toEqual({
number: 327,
owner: "orta",
repo: "emission",
})
})
})
56 changes: 28 additions & 28 deletions source/platforms/_tests/fixtures/github_pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,34 @@
"comments_url": "https://api.github.com/repos/artsy/emission/issues/327/comments",
"statuses_url": "https://api.github.com/repos/artsy/emission/statuses/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"head": {
"label": "artsy:genevc",
"label": "orta:genevc",
"ref": "genevc",
"sha": "cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"user": {
"login": "artsy",
"login": "orta",
"id": 546231,
"avatar_url": "https://avatars.githubusercontent.com/u/546231?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/artsy",
"html_url": "https://github.com/artsy",
"followers_url": "https://api.github.com/users/artsy/followers",
"following_url": "https://api.github.com/users/artsy/following{/other_user}",
"gists_url": "https://api.github.com/users/artsy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/artsy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/artsy/subscriptions",
"organizations_url": "https://api.github.com/users/artsy/orgs",
"repos_url": "https://api.github.com/users/artsy/repos",
"events_url": "https://api.github.com/users/artsy/events{/privacy}",
"received_events_url": "https://api.github.com/users/artsy/received_events",
"url": "https://api.github.com/users/orta",
"html_url": "https://github.com/orta",
"followers_url": "https://api.github.com/users/orta/followers",
"following_url": "https://api.github.com/users/orta/following{/other_user}",
"gists_url": "https://api.github.com/users/orta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/orta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/orta/subscriptions",
"organizations_url": "https://api.github.com/users/orta/orgs",
"repos_url": "https://api.github.com/users/orta/repos",
"events_url": "https://api.github.com/users/orta/events{/privacy}",
"received_events_url": "https://api.github.com/users/orta/received_events",
"type": "Organization",
"site_admin": false
},
"repo": {
"id": 52437732,
"name": "emission",
"full_name": "artsy/emission",
"full_name": "orta/emission",
"owner": {
"login": "artsy",
"login": "orta",
"id": 546231,
"avatar_url": "https://avatars.githubusercontent.com/u/546231?v=3",
"gravatar_id": "",
Expand All @@ -127,21 +127,21 @@
"site_admin": false
},
"private": false,
"html_url": "https://github.com/artsy/emission",
"html_url": "https://github.com/orta",
"description": "React Native Components",
"fork": false,
"url": "https://api.github.com/repos/artsy/emission",
"forks_url": "https://api.github.com/repos/artsy/emission/forks",
"keys_url": "https://api.github.com/repos/artsy/emission/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/artsy/emission/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/artsy/emission/teams",
"hooks_url": "https://api.github.com/repos/artsy/emission/hooks",
"issue_events_url": "https://api.github.com/repos/artsy/emission/issues/events{/number}",
"events_url": "https://api.github.com/repos/artsy/emission/events",
"assignees_url": "https://api.github.com/repos/artsy/emission/assignees{/user}",
"branches_url": "https://api.github.com/repos/artsy/emission/branches{/branch}",
"tags_url": "https://api.github.com/repos/artsy/emission/tags",
"blobs_url": "https://api.github.com/repos/artsy/emission/git/blobs{/sha}",
"url": "https://api.github.com/repos/orta",
"forks_url": "https://api.github.com/repos/orta/emission/forks",
"keys_url": "https://api.github.com/repos/orta/emission/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/orta/emission/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/orta/emission/teams",
"hooks_url": "https://api.github.com/repos/orta/emission/hooks",
"issue_events_url": "https://api.github.com/repos/orta/emission/issues/events{/number}",
"events_url": "https://api.github.com/repos/orta/emission/events",
"assignees_url": "https://api.github.com/repos/orta/emission/assignees{/user}",
"branches_url": "https://api.github.com/repos/orta/emission/branches{/branch}",
"tags_url": "https://api.github.com/repos/orta/emission/tags",
"blobs_url": "https://api.github.com/repos/orta/emission/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/artsy/emission/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/artsy/emission/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/artsy/emission/git/trees{/sha}",
Expand Down
6 changes: 3 additions & 3 deletions source/platforms/github/_tests/_github_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ describe("fileLinks", () => {
it("Should convert a few paths into links", () => {
const sut = utils(pr, apiFake)
const links = sut.fileLinks(["a/b/c", "d/e/f"])
const url = "https://github.com/artsy/emission/blob/genevc/a/b/c"
const url = "https://github.com/orta/emission/blob/genevc/a/b/c"
expect(links).toEqual(
`<a href="${url}">c</a> and <a href="https://github.com/artsy/emission/blob/genevc/d/e/f">f</a>`
`<a href="${url}">c</a> and <a href="https://github.com/orta/emission/blob/genevc/d/e/f">f</a>`
)
})

it("Should convert a few paths into links showing full links", () => {
const sut = utils(pr, apiFake)
const links = sut.fileLinks(["a/b/c", "d/e/f"], false)
const url = "https://github.com/artsy/emission/blob/genevc"
const url = "https://github.com/orta/emission/blob/genevc"
expect(links).toEqual(`<a href="${url}/a/b/c">a/b/c</a> and <a href="${url}/d/e/f">d/e/f</a>`)
})

Expand Down
29 changes: 24 additions & 5 deletions source/runner/DangerfileRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@ import { DangerContext } from "../runner/Dangerfile"

import { NodeVM, NodeVMOptions } from "vm2"

let hasTypeScript = false
let hasNativeTypeScript = false
let hasBabel = false
let hasBabelTypeScript = false
let hasFlow = false

declare const regeneratorRuntime: any

// You know you're being a dangerous badass when you have this many linter disables. Deal with it.

try {
require.resolve("typescript") // tslint:disable-line
hasTypeScript = true
hasNativeTypeScript = true
} catch (e) {} // tslint:disable-line

try {
require.resolve("babel-core") // tslint:disable-line
require("babel-polyfill") // tslint:disable-line
hasBabel = true

try {
require.resolve("babel-plugin-transform-typescript") // tslint:disable-line
hasBabelTypeScript = true
} catch (e) {} // tslint:disable-line

try {
require.resolve("babel-plugin-transform-flow-strip-types") // tslint:disable-line
hasFlow = true
} catch (e) {} // tslint:disable-line
} catch (e) {} // tslint:disable-line

/**
Expand Down Expand Up @@ -52,10 +66,12 @@ export async function createDangerfileRuntimeEnvironment(dangerfileContext: Dang
function compile(code: string, filename: string) {
const filetype = path.extname(filename)
let result = code
if (hasTypeScript && filetype.startsWith(".ts")) {
if (hasNativeTypeScript && !filename.includes("node_modules") && filetype.startsWith(".ts")) {
result = typescriptify(code)
} else if (hasBabel && hasBabelTypeScript && !filename.includes("node_modules") && filetype.startsWith(".ts")) {
result = babelify(code, filename, ["transform-typescript"])
} else if (hasBabel && !filename.includes("node_modules") && filetype.startsWith(".js")) {
result = babelify(code, filename)
result = babelify(code, filename, hasFlow ? ["transform-flow-strip-types"] : [])
}

return result
Expand Down Expand Up @@ -165,14 +181,17 @@ const typescriptify = (content: string): string => {
return result.outputText
}

const babelify = (content: string, filename: string): string => {
const babelify = (content: string, filename: string, extraPlugins: string[]): string => {
const babel = require("babel-core") // tslint:disable-line
const options = babel.loadOptions({})

const fileOpts = {
filename,
filenameRelative: filename,
sourceMap: false,
sourceFileName: null,
sourceMapTarget: null,
plugins: [...extraPlugins, ...options.plugins],
}

const result = babel.transform(content, fileOpts)
Expand Down

0 comments on commit 1f60dc0

Please sign in to comment.