Skip to content

Commit

Permalink
Adds a check for the diff existing on local
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Feb 7, 2018
1 parent a8ccd71 commit f045985
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Fix --base options for danger local. [@peterjgrainger][]
* Fix a minor typo in Semaphore CI setup. [@hongrich][]
* Fix for capitalized Dangerfiles in CI environment. [@wizardishungry][]
* Fix `danger local` crashing when comparing master to HEAD with no changes. [@orta][]

## 3.1.4

Expand Down
10 changes: 8 additions & 2 deletions source/commands/danger-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ 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"] })
localPlatform.validateThereAreChanges().then(changes => {
if (changes) {
const fakeSource = new FakeCI(process.env)
runRunner(app, { source: fakeSource, platform: localPlatform, additionalArgs: ["--local"] })
} else {
console.log("No git changes detected between head and master.")
}
})
20 changes: 18 additions & 2 deletions source/platforms/LocalGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,36 @@ export interface LocalGitOptions {

export class LocalGit implements Platform {
public readonly name: string
private gitDiff: string

constructor(public readonly options: LocalGitOptions) {
this.name = "local git"
}

async getGitDiff(): Promise<string> {
if (this.gitDiff) {
return this.gitDiff
}
const base = this.options.base || "master"
const head = "HEAD"

this.gitDiff = await localGetDiff(base, head)
return this.gitDiff
}

async validateThereAreChanges(): Promise<boolean> {
const diff = await this.getGitDiff()
return diff.trim().length > 0
}

async getPlatformDSLRepresentation(): Promise<any> {
return null
}

async getPlatformGitRepresentation(): Promise<GitDSL> {
const base = this.options.base || "master"
const head = "HEAD"

const diff = await localGetDiff(base, head)
const diff = await this.getGitDiff()
const commits: GitCommit[] = await localGetCommits(base, head)
const gitJSON = diffToGitJSONDSL(diff, commits)

Expand Down

0 comments on commit f045985

Please sign in to comment.