Skip to content

Commit 5b8d9e6

Browse files
Copilotgramster
andauthored
Expose commit hash in sarif blame output (#103)
* Initial plan * Expose commit hash in sarif blame output - Add commit hash as "commit" field in blame properties - Update tests to expect commit hash in output - Update README documentation with new commit field - Add commit shortcut to filtering table - Verify functionality with manual testing Co-authored-by: gramster <2762632+gramster@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gramster <2762632+gramster@users.noreply.github.com>
1 parent d4d79ec commit 5b8d9e6

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Blame information is added to the property bag of each `result` object for which
184184
...
185185
"properties": {
186186
"blame": {
187+
"commit": "1234567890abcdef1234567890abcdef12345678",
187188
"author": "aperson",
188189
"author-mail": "<aperson@acompany.com>",
189190
"author-time": "1350899798",
@@ -740,6 +741,7 @@ For commonly used properties the following shortcuts are defined:
740741
| -------- | -------- |
741742
| author | properties.blame.author |
742743
| author-mail | properties.blame.author-mail |
744+
| commit | properties.blame.commit |
743745
| committer | properties.blame.committer |
744746
| committer-mail | properties.blame.committer-mail |
745747
| location | locations[*].physicalLocation.artifactLocation.uri |

sarif/operations/blame_op.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ def _enhance_with_blame(
118118
if line_no in blame_info["line_to_commit"]:
119119
commit_hash = blame_info["line_to_commit"][line_no]
120120
commit = blame_info["commits"][commit_hash]
121+
# Add commit hash to the blame information
122+
commit_with_hash = {"commit": commit_hash, **commit}
121123
# Add blame information to the SARIF Property Bag of the result
122-
result.setdefault("properties", {})["blame"] = commit
124+
result.setdefault("properties", {})["blame"] = commit_with_hash
123125
blame_info_count += 1
124126
print(f"Found blame information for {blame_info_count} of {item_count} results")
125127

tests/ops/blame/test_blame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def run_git_blame(blame_repo_path: str, blame_file_path: str) -> List[bytes]:
157157

158158
expected_blame_properties = {
159159
"blame": {
160+
"commit": "f9db03438aba52affc5c3fcdb619afa620ad603a",
160161
"author": "Taylor Developer",
161162
"author-mail": "<taylor@developer.com>",
162163
"author-time": "1699272533",
@@ -200,6 +201,7 @@ def run_git_blame(blame_repo_path: str, blame_file_path: str) -> List[bytes]:
200201

201202
expected_blame_properties = {
202203
"blame": {
204+
"commit": "f9db03438aba52affc5c3fcdb619afa620ad603a",
203205
"author": "Taylor Developer",
204206
"author-mail": "<taylor@developer.com>",
205207
"author-time": "1699272533",

0 commit comments

Comments
 (0)