in bot/code_review_bot/report/phabricator.py [0:0]
def compare_issues(self, former_diff_id, issues):
"""
Compare new issues depending on their evolution from the
previous diff on the same revision.
Returns a tuple containing lists of:
* Unresolved issues, that are present on both diffs
* Closed issues, that were present in the previous diff and are now gone
"""
if not self.backend_api.enabled:
logger.warning(
"Backend API must be enabled to compare issues with previous diff {former_diff_id}."
)
return [], []
# If this is the first diff, there's no need to compare issues with a
# previous diff since there is no previous diff.
if former_diff_id is None:
return [], []
# Retrieve issues related to the previous diff
try:
previous_issues = self.backend_api.list_diff_issues(former_diff_id)
except Exception as e:
logger.warning(
f"An error occurred listing issues on previous diff {former_diff_id}: {e}. "
"Each issue will be considered as a new case."
)
previous_issues = []
# Multiple issues may share a similar hash in case they were
# produced by the same linter on the same lines
indexed_issues = defaultdict(list)
for issue in previous_issues:
indexed_issues[issue["hash"]].append(issue)
# Compare current issues with the previous ones based on the hash
unresolved = [
issue.on_backend["hash"]
for issue in issues
if issue.on_backend and issue.on_backend["hash"] in indexed_issues
]
# All previous issues that are not unresolved are closed
closed = [issue for issue in previous_issues if issue["hash"] not in unresolved]
return unresolved, closed