Skip to content

Commit

Permalink
Merge empty comment fix changes pull #564
Browse files Browse the repository at this point in the history
  • Loading branch information
codestergit committed Apr 17, 2018
2 parents 81db75b + 6d416f2 commit 22b4ca0
Show file tree
Hide file tree
Showing 5 changed files with 35 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 @@

## Master

* Fixed a bug where Danger posts empty main comment when it have one or more inline comments to post [@codestergit][]
* fix bug when commiting .png files on BitBucket [@Mifi][]
* Adds support for inline comments for bitbucket server. [@codestergit][]

Expand Down
4 changes: 4 additions & 0 deletions source/dsl/DangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ export function sortResults(results: DangerResults): DangerResults {
}
}

export function isEmptyResults(results: DangerResults): boolean {
return [...results.fails, ...results.warnings, ...results.messages, ...results.markdowns].length === 0
}

export function resultsIntoInlineResults(results: DangerResults): DangerInlineResults[] {
// Here we iterate through all keys ("fails", "warnings", "messages", "markdowns") and for each violation
// in given kind we produce new DangerInlineResult or append a violation to existing result. This is all
Expand Down
13 changes: 13 additions & 0 deletions source/dsl/_tests/DangerResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
regularResults,
sortInlineResults,
validateResults,
isEmptyResults,
} from "../DangerResults"
import {
singleViolationSingleFileResults,
Expand Down Expand Up @@ -89,6 +90,18 @@ describe("DangerResults operations", () => {

expect(results).toMatchSnapshot()
})

it("find empty results", () => {
const result = isEmptyResults(emptyDangerResults)

expect(result).toEqual(true)
})

it("find empty results", () => {
const result = isEmptyResults(multipleViolationSingleFileResults)

expect(result).toEqual(false)
})
})

describe("validation", () => {
Expand Down
7 changes: 7 additions & 0 deletions source/dsl/_tests/fixtures/ExampleDangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const multipleViolationsMultipleFilesResults: DangerResults = {
],
}

export const emptyDangerResults: DangerResults = {
fails: [],
warnings: [],
messages: [],
markdowns: [],
}

export const emptyDangerInlineResults: DangerInlineResults = {
file: "",
line: 0,
Expand Down
14 changes: 10 additions & 4 deletions source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
sortResults,
sortInlineResults,
validateResults,
isEmptyResults,
} from "../dsl/DangerResults"
import {
template as githubResultsTemplate,
Expand Down Expand Up @@ -233,11 +234,16 @@ export class Executor {
const inlineLeftovers = await this.sendInlineComments(inline, git, previousComments)
const regular = regularResults(results)
const mergedResults = sortResults(mergeResults(regular, inlineLeftovers))
const comment = process.env["DANGER_BITBUCKETSERVER_HOST"]
? bitbucketServerTemplate(dangerID, mergedResults)
: githubResultsTemplate(dangerID, mergedResults)

await this.platform.updateOrCreateComment(dangerID, comment)
// If danger have no comments other than inline to update. Just delete previous main comment.
if (isEmptyResults(mergedResults)) {
this.platform.deleteMainComment(dangerID)
} else {
const comment = process.env["DANGER_BITBUCKETSERVER_HOST"]
? bitbucketServerTemplate(dangerID, mergedResults)
: githubResultsTemplate(dangerID, mergedResults)
await this.platform.updateOrCreateComment(dangerID, comment)
}
}

// More info, is more info.
Expand Down

0 comments on commit 22b4ca0

Please sign in to comment.