Skip to content

Commit

Permalink
Add sorting inline results
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinejr committed Mar 7, 2018
1 parent 4c44daa commit dc3363e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions source/dsl/DangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,36 @@ export function mergeResults(results1: DangerResults, results2: DangerResults):
}
}

export function sortInlineResults(inlineResults: DangerInlineResults[]): DangerInlineResults[] {
// First sort messages in every inline result
const sortedInlineResults = inlineResults.map(i => {
return {
file: i.file,
line: i.line,
fails: i.fails.sort(),
warnings: i.warnings.sort(),
messages: i.messages.sort(),
markdowns: i.markdowns.sort(),
}
})

// Then sort a whole array of inline results based on file/line
return sortedInlineResults.sort((a, b) => {
if (a.file < b.file) {
return -1
} else if (a.file > b.file) {
return 1
} else if (a.line < b.line) {
return -1
} else if (a.line > b.line) {
return 1
} else {
// both file & line are the same
return 0
}
})
}

export function sortResults(results: DangerResults): DangerResults {
const sortByFile = (a: Violation, b: Violation): number => {
if (a.file === undefined) {
Expand Down
4 changes: 3 additions & 1 deletion source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
emptyDangerResults,
inlineResultsIntoResults,
sortResults,
sortInlineResults,
} from "../dsl/DangerResults"
import {
template as githubResultsTemplate,
Expand Down Expand Up @@ -241,7 +242,8 @@ export class Executor {
// TODO: Get current inline comments, if any of the old ones is not present
// in the new ones - delete.
const inlineResults = resultsIntoInlineResults(results)
const promises = inlineResults.map(inlineResult => {
const sortedInlineResults = sortInlineResults(inlineResults)
const promises = sortedInlineResults.map(inlineResult => {
return this.sendInlineComment(git, inlineResult)
.then(_r => emptyDangerResults)
.catch(_e => inlineResultsIntoResults(inlineResult))
Expand Down

0 comments on commit dc3363e

Please sign in to comment.