-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from danger/adam-moss-local-run
Local execution for lint-staging like tests
- Loading branch information
Showing
31 changed files
with
644 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as fs from "fs" | ||
|
||
import { DangerDSLType } from "./source/dsl/DangerDSL" | ||
declare var danger: DangerDSLType | ||
declare function warn(params: string): void | ||
|
||
const hasChangelog = danger.git.modified_files.includes("CHANGELOG.md") | ||
if (!hasChangelog) { | ||
warn("Please add a changelog entry for your changes.") | ||
} | ||
|
||
import dtsGenerator from "./scripts/danger-dts" | ||
const currentDTS = dtsGenerator() | ||
const savedDTS = fs.readFileSync("source/danger.d.ts").toString() | ||
if (currentDTS !== savedDTS) { | ||
const message = "There are changes to the Danger DSL which are not reflected in the current danger.d.ts." | ||
const idea = "Please run <code>yarn declarations</code> and update this PR." | ||
fail(`${message}\n - ${idea}`) | ||
} | ||
|
||
// Always ensure we name all CI providers in the README. These | ||
// regularly get forgotten on a PR adding a new one. | ||
const sentence = danger.utils.sentence | ||
|
||
import { realProviders } from "./source/ci_source/providers" | ||
const readme = fs.readFileSync("README.md").toString() | ||
const names = realProviders.map(p => new p({}).name) | ||
const missing = names.filter(n => !readme.includes(n)) | ||
if (missing.length) { | ||
warn(`These providers are missing from the README: ${sentence(missing)}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Env, CISource } from "../ci_source" | ||
|
||
export class LocalRepo implements CISource { | ||
private readonly env: Env | ||
|
||
constructor(env: Env) { | ||
const defaults = { | ||
repo: process.cwd(), | ||
pr: undefined, | ||
} | ||
|
||
this.env = { ...env, ...defaults } | ||
} | ||
get name(): string { | ||
return "local repo" | ||
} | ||
|
||
get isCI(): boolean { | ||
return true | ||
} | ||
get isPR(): boolean { | ||
return true | ||
} | ||
|
||
get pullRequestID(): string { | ||
return "" | ||
} | ||
get repoSlug(): string { | ||
return this.env.repo | ||
} | ||
get supportedPlatforms(): string[] { | ||
return ["git"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#! /usr/bin/env node | ||
|
||
import * as program from "commander" | ||
|
||
import setSharedArgs, { SharedCLI } from "./utils/sharedDangerfileArgs" | ||
import { runRunner } from "./ci/runner" | ||
import { LocalGit } from "../platforms/LocalGit" | ||
import { FakeCI } from "../ci_source/providers/Fake" | ||
|
||
interface App extends SharedCLI { | ||
/** What should we compare against? */ | ||
base?: string | ||
/** Should we run against current staged changes? */ | ||
staging?: boolean | ||
} | ||
|
||
program | ||
.usage("[options]") | ||
.option("-b, --base [base]", "Choose the base commit to work against.") | ||
// TODO: this option | ||
// .option("-s, --staging", "Just use staged changes.") | ||
.description("Runs danger without PR metadata, useful for git hooks.") | ||
setSharedArgs(program).parse(process.argv) | ||
|
||
const app = (program as any) as App | ||
const base = app.base || "master" | ||
const localPlatform = new LocalGit({ base, staged: app.staging }) | ||
const fakeSource = new FakeCI(process.env) | ||
runRunner(app, { source: fakeSource, platform: localPlatform, additionalArgs: ["--local"] }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.