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

Commit cb81cfd

Browse files
betterphpthienan93
authored andcommitted
Fallback to an global comment if the file does not exist in the revision
1 parent 32402cb commit cb81cfd

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/main/kotlin/io/nthienan/phdiff/PhabricatorDifferentialPostJob.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,32 @@ class PhabricatorDifferentialPostJob(
4545

4646
override fun execute(context: PostJobContext?) {
4747
val diffID = configuration.diffId()
48-
if (context?.analysisMode()?.isIssues ?: false) {
49-
StreamSupport.stream(context?.issues()?.spliterator(), false)
50-
.filter { it.isNew }
51-
.filter { it.inputComponent()?.isFile ?: false }
52-
.sorted(issueComparator)
53-
.forEach { i ->
54-
run {
55-
globalReportBuilder.add(i)
56-
val ic = inlineReportBuilder.issue(i).build()
57-
val filePath = i.componentKey().replace(projectKey, "").substring(1)
58-
try {
59-
differentialClient.postInlineComment(diffID, filePath, i.line()!!, ic)
60-
log.debug("Comment $ic has been published")
61-
} catch (e: ConduitException) {
62-
log.error(e.message, e)
63-
}
64-
65-
}
66-
}
67-
}
6848
try {
6949
val diff = differentialClient.fetchDiff(diffID)
50+
if (context?.analysisMode()?.isIssues ?: false) {
51+
StreamSupport.stream(context?.issues()?.spliterator(), false)
52+
.filter { it.isNew }
53+
.filter { it.inputComponent()?.isFile ?: false }
54+
.sorted(issueComparator)
55+
.forEach { i ->
56+
run {
57+
globalReportBuilder.add(i)
58+
val ic = inlineReportBuilder.issue(i).build()
59+
val filePath = i.componentKey().replace(projectKey, "").substring(1)
60+
try {
61+
differentialClient.postInlineComment(diffID, filePath, i.line()!!, ic)
62+
log.debug("Comment $ic has been published")
63+
} catch (e: ConduitException) {
64+
if (e.message.equals("Requested file doesn't exist in this revision.")) {
65+
val message = "Unmodified file " + filePath + " on line " + i.line() + "\n\n" + ic
66+
differentialClient.postComment(diff.revisionId, message)
67+
} else {
68+
log.error(e.message, e)
69+
}
70+
}
71+
}
72+
}
73+
}
7074
differentialClient.postComment(diff.revisionId, globalReportBuilder.summarize())
7175
log.info("Analysis result has been published to your differential revision")
7276
} catch (e: ConduitException) {

0 commit comments

Comments
 (0)