Skip to content

Commit

Permalink
Special case just markdown messages WRT the issue/checks hybrid
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 24, 2018
1 parent b2290a4 commit a97d425
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions source/dsl/DangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export const emptyResults = (): DangerResults => ({ fails: [], markdowns: [], wa
export const isEmptyResults = (results: DangerResults): boolean =>
[...results.fails, ...results.warnings, ...results.messages, ...results.markdowns].length === 0

export const isMarkdownOnlyResults = (results: DangerResults): boolean =>
results.markdowns.length > 0 && [...results.fails, ...results.warnings, ...results.messages].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
6 changes: 2 additions & 4 deletions source/platforms/github/comms/_tests/_checksCommenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ it("deals with warnings", () => {
)
})

it("deals with markdowns", () => {
it("deals with *just* markdowns by returning the markdowns", () => {
const newResults = tweetSizedResultsFromResults(markdownResults, checksResults)
expect(newResults.markdowns[0].message).toMatchInlineSnapshot(
`"Danger run resulted in 2 markdowns; to find out more, see the [checks page](https://gh.com/a)."`
)
expect(newResults.markdowns[0].message).toMatchInlineSnapshot(`"### Short Markdown Message1"`)
})

it("handles singular results", () => {
Expand Down
40 changes: 23 additions & 17 deletions source/platforms/github/comms/checksCommenter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitHubAPI } from "../GitHubAPI"
import { DangerResults, isEmptyResults, emptyResults } from "../../../dsl/DangerResults"
import { DangerResults, isEmptyResults, isMarkdownOnlyResults } from "../../../dsl/DangerResults"
import { ExecutorOptions } from "../../../runner/Executor"
import { resultsToCheck } from "./checks/resultsToCheck"
import { getAccessTokenForInstallation } from "./checks/githubAppSupport"
Expand Down Expand Up @@ -92,22 +92,28 @@ export const GitHubChecksCommenter = (api: GitHubAPI) => {
}
}

export const tweetSizedResultsFromResults = (results: DangerResults, checksResponse: any): DangerResults =>
isEmptyResults(results)
? emptyResults()
: {
warnings: [],
messages: [],
fails: [],
markdowns: [
{
message:
"Danger run resulted in " +
messageFromResults(results) +
`; to find out more, see the [checks page](${checksResponse.html_url}).`,
},
],
}
export const tweetSizedResultsFromResults = (results: DangerResults, checksResponse: any): DangerResults => {
const allowMarkdowns = isMarkdownOnlyResults(results)
const isEmpty = isEmptyResults(results)

if (allowMarkdowns || isEmpty) {
return results
}

return {
warnings: [],
messages: [],
fails: [],
markdowns: [
{
message:
"Danger run resulted in " +
messageFromResults(results) +
`; to find out more, see the [checks page](${checksResponse.html_url}).`,
},
],
}
}

const messageFromResults = (results: DangerResults): string => {
const appendS = (arr: any[]) => (arr.length === 1 ? "" : "s")
Expand Down

0 comments on commit a97d425

Please sign in to comment.