Skip to content

Commit a97d425

Browse files
committed
Special case just markdown messages WRT the issue/checks hybrid
1 parent b2290a4 commit a97d425

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

source/dsl/DangerResults.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ export const emptyResults = (): DangerResults => ({ fails: [], markdowns: [], wa
211211
export const isEmptyResults = (results: DangerResults): boolean =>
212212
[...results.fails, ...results.warnings, ...results.messages, ...results.markdowns].length === 0
213213

214+
export const isMarkdownOnlyResults = (results: DangerResults): boolean =>
215+
results.markdowns.length > 0 && [...results.fails, ...results.warnings, ...results.messages].length === 0
216+
214217
export function resultsIntoInlineResults(results: DangerResults): DangerInlineResults[] {
215218
// Here we iterate through all keys ("fails", "warnings", "messages", "markdowns") and for each violation
216219
// in given kind we produce new DangerInlineResult or append a violation to existing result. This is all

source/platforms/github/comms/_tests/_checksCommenter.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ it("deals with warnings", () => {
2929
)
3030
})
3131

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

3937
it("handles singular results", () => {

source/platforms/github/comms/checksCommenter.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GitHubAPI } from "../GitHubAPI"
2-
import { DangerResults, isEmptyResults, emptyResults } from "../../../dsl/DangerResults"
2+
import { DangerResults, isEmptyResults, isMarkdownOnlyResults } from "../../../dsl/DangerResults"
33
import { ExecutorOptions } from "../../../runner/Executor"
44
import { resultsToCheck } from "./checks/resultsToCheck"
55
import { getAccessTokenForInstallation } from "./checks/githubAppSupport"
@@ -92,22 +92,28 @@ export const GitHubChecksCommenter = (api: GitHubAPI) => {
9292
}
9393
}
9494

95-
export const tweetSizedResultsFromResults = (results: DangerResults, checksResponse: any): DangerResults =>
96-
isEmptyResults(results)
97-
? emptyResults()
98-
: {
99-
warnings: [],
100-
messages: [],
101-
fails: [],
102-
markdowns: [
103-
{
104-
message:
105-
"Danger run resulted in " +
106-
messageFromResults(results) +
107-
`; to find out more, see the [checks page](${checksResponse.html_url}).`,
108-
},
109-
],
110-
}
95+
export const tweetSizedResultsFromResults = (results: DangerResults, checksResponse: any): DangerResults => {
96+
const allowMarkdowns = isMarkdownOnlyResults(results)
97+
const isEmpty = isEmptyResults(results)
98+
99+
if (allowMarkdowns || isEmpty) {
100+
return results
101+
}
102+
103+
return {
104+
warnings: [],
105+
messages: [],
106+
fails: [],
107+
markdowns: [
108+
{
109+
message:
110+
"Danger run resulted in " +
111+
messageFromResults(results) +
112+
`; to find out more, see the [checks page](${checksResponse.html_url}).`,
113+
},
114+
],
115+
}
116+
}
111117

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

0 commit comments

Comments
 (0)