-
Notifications
You must be signed in to change notification settings - Fork 459
Added blame info feature for "cmd results" command #4008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1901,9 +1901,15 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
|
|
||
| # Get report details if it is required. | ||
| report_details = {} | ||
| if get_details: | ||
| report_ids = [r[0].id for r in query_result] | ||
| blame_infos = {} | ||
| if get_details and len(query_result): | ||
| report_ids, blames = zip(*[ | ||
| ( | ||
| r[0].id, | ||
| (r[0].id, self.getBlameInfo(r[0].file_id)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could consider caching fetched blame info in case there are many reports in a file. |
||
| ) for r in query_result]) | ||
| report_details = get_report_details(session, report_ids) | ||
| blame_infos = dict(blames) | ||
|
Comment on lines
+1904
to
+1912
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| for row in query_result: | ||
| report = row[0] | ||
|
|
@@ -1919,6 +1925,21 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
| report.review_status_date, | ||
| report.review_status_is_in_source) | ||
|
|
||
| blame_info = blame_infos.get(report.id) | ||
| if blame_info and blame_info.commits and blame_info.blame: | ||
| blame_data = [b for b in blame_info.blame | ||
| if report.line >= b.startLine | ||
| and report.line <= b.endLine] | ||
| commitHash = blame_data[0].commitHash \ | ||
| if len(blame_data) else None | ||
| commitInfo = {cHash: commit for cHash, commit | ||
| in blame_info.commits.items() | ||
| if cHash == commitHash} | ||
| blame_info = BlameInfo( | ||
| commits=commitInfo, | ||
| blame=blame_data | ||
| ) | ||
|
|
||
|
Comment on lines
+1928
to
+1942
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here. |
||
| results.append( | ||
| ReportData(runId=report.run_id, | ||
| bugHash=report.bug_id, | ||
|
|
@@ -1937,6 +1958,7 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
| fixedAt=str(report.fixed_at), | ||
| bugPathLength=report.path_length, | ||
| details=report_details.get(report.id), | ||
| blameInfo=blame_info, | ||
| analyzerName=report.analyzer_name, | ||
| annotations=annotations)) | ||
| else: # not is_unique | ||
|
|
@@ -1986,9 +2008,15 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
|
|
||
| # Get report details if it is required. | ||
| report_details = {} | ||
| if get_details: | ||
| report_ids = [r[0].id for r in query_result] | ||
| blame_infos = {} | ||
| if get_details and len(query_result): | ||
| report_ids, blames = zip(*[ | ||
| ( | ||
| r[0].id, | ||
| (r[0].id, self.getBlameInfo(r[0].file_id)) | ||
| ) for r in query_result]) | ||
| report_details = get_report_details(session, report_ids) | ||
| blame_infos = dict(blames) | ||
|
|
||
| for row in query_result: | ||
| report = row[0] | ||
|
|
@@ -2004,6 +2032,22 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
| report.review_status_date, | ||
| report.review_status_is_in_source) | ||
|
|
||
| blame_info = blame_infos[report.id] \ | ||
| if report.id in blame_infos else None | ||
| if blame_info and blame_info.commits and blame_info.blame: | ||
| blame_data = [b for b in blame_info.blame | ||
| if report.line >= b.startLine | ||
| and report.line <= b.endLine] | ||
| commitHash = blame_data[0].commitHash \ | ||
| if len(blame_data) else None | ||
| commitInfo = {cHash: commit for cHash, commit | ||
| in blame_info.commits.items() | ||
| if cHash == commitHash} | ||
| blame_info = BlameInfo( | ||
| commits=commitInfo, | ||
| blame=blame_data | ||
| ) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These code snippets are basically copy-paste from above, right? Can we do something about that?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is more readable form. |
||
| results.append( | ||
| ReportData(runId=report.run_id, | ||
| bugHash=report.bug_id, | ||
|
|
@@ -2023,6 +2067,7 @@ def getRunResults(self, run_ids, limit, offset, sort_types, | |
| report.fixed_at else None, | ||
| bugPathLength=report.path_length, | ||
| details=report_details.get(report.id), | ||
| blameInfo=blame_info, | ||
| analyzerName=report.analyzer_name, | ||
| annotations=annotations)) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -447,3 +447,20 @@ def test_get_checker_labels(self): | |
| self.assertEqual(len(checker_labels), 2) | ||
| self.assertEqual(set(checker_labels[0]), div_zero_labels) | ||
| self.assertEqual(set(checker_labels[1]), set()) | ||
|
|
||
| def test_report_blame_info(self): | ||
| """ | ||
| Get run results and check that blame info exists | ||
| when get_details is set. | ||
| """ | ||
| runid = self._runid | ||
| simple_filter = ReportFilter() | ||
| run_results = self._cc_client.getRunResults([runid], | ||
| 100, | ||
| 0, | ||
| None, | ||
| simple_filter, | ||
| None, | ||
| True) | ||
|
Comment on lines
+458
to
+464
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we name the parameters we're assign to here? LLVM Coding Standards has a well written guidince on this. By no means are we strictly abiding all of these, but they make a lot of sense :)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not name the parameters in the above functions either. If we want to do it, then in all the other cases we must also assigne them. |
||
|
|
||
| self.assertTrue(any(res.blameInfo for res in run_results)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test the json output as well? At least that is doesn't crash.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is sufficient to check only the existence of the blame info. If someone modified the test files, the blame info whould be also changed, which whould break the test. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is longer than 79 columns.