Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Fallback to an global comment if the file does not exist in the revision #2

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,32 @@ class PhabricatorDifferentialPostJob(

override fun execute(context: PostJobContext?) {
val diffID = configuration.diffId()
if (context?.analysisMode()?.isIssues ?: false) {
StreamSupport.stream(context?.issues()?.spliterator(), false)
.filter { it.isNew }
.filter { it.inputComponent()?.isFile ?: false }
.sorted(issueComparator)
.forEach { i ->
run {
globalReportBuilder.add(i)
val ic = inlineReportBuilder.issue(i).build()
val filePath = i.componentKey().replace(projectKey, "").substring(1)
try {
differentialClient.postInlineComment(diffID, filePath, i.line()!!, ic)
log.debug("Comment $ic has been published")
} catch (e: ConduitException) {
log.error(e.message, e)
}

}
}
}
try {
val diff = differentialClient.fetchDiff(diffID)
if (context?.analysisMode()?.isIssues ?: false) {
StreamSupport.stream(context?.issues()?.spliterator(), false)
.filter { it.isNew }
.filter { it.inputComponent()?.isFile ?: false }
.sorted(issueComparator)
.forEach { i ->
run {
globalReportBuilder.add(i)
val ic = inlineReportBuilder.issue(i).build()
val filePath = i.componentKey().replace(projectKey, "").substring(1)
try {
differentialClient.postInlineComment(diffID, filePath, i.line()!!, ic)
log.debug("Comment $ic has been published")
} catch (e: ConduitException) {
if (e.message.equals("Requested file doesn't exist in this revision.")) {
val message = "Unmodified file " + filePath + " on line " + i.line() + "\n\n" + ic
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use string template

differentialClient.postComment(diff.revisionId, message)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should modify postComment() to not attach inline comments in this case

} else {
log.error(e.message, e)
}
}
}
}
}
differentialClient.postComment(diff.revisionId, globalReportBuilder.summarize())
log.info("Analysis result has been published to your differential revision")
} catch (e: ConduitException) {
Expand Down