|
4 | 4 | import json |
5 | 5 | import sys |
6 | 6 | from collections.abc import Sequence |
| 7 | +from hashlib import sha256 |
7 | 8 | from pathlib import Path |
8 | 9 |
|
9 | 10 | from . import __version__ |
@@ -124,18 +125,26 @@ def _run_check(args: argparse.Namespace) -> int: |
124 | 125 | issue_url = build_issue_url(report) |
125 | 126 | if args.include_source_in_issue_link: |
126 | 127 | try: |
127 | | - source = args.file.read_bytes().decode(args.encoding) |
128 | | - reproduction = extract_reproduction_snippet(source) |
129 | | - if reproduction is None: |
| 128 | + source_bytes = args.file.read_bytes() |
| 129 | + if sha256(source_bytes).hexdigest() != report.source_sha256: |
130 | 130 | reproduction_notice = ( |
131 | | - "no exact bounded failed-block reproduction could be extracted; " |
132 | | - "add a reviewed minimal example manually" |
| 131 | + "the file changed after the compatibility check; rerun the command" |
133 | 132 | ) |
134 | 133 | else: |
135 | | - reproduction_issue_url = build_issue_url( |
136 | | - report, |
137 | | - reproduction=reproduction, |
138 | | - ) |
| 134 | + source = source_bytes.decode(args.encoding) |
| 135 | + reproduction = extract_reproduction_snippet(source) |
| 136 | + if reproduction is None: |
| 137 | + reproduction_notice = ( |
| 138 | + "no exact bounded failed-block reproduction could be " |
| 139 | + "extracted; add a reviewed minimal example manually" |
| 140 | + ) |
| 141 | + else: |
| 142 | + reproduction_issue_url = build_issue_url( |
| 143 | + report, |
| 144 | + reproduction=reproduction, |
| 145 | + ) |
| 146 | + except OSError: |
| 147 | + reproduction_notice = "the file could not be reread for a source-bearing draft" |
139 | 148 | except (LookupError, UnicodeDecodeError): |
140 | 149 | reproduction_notice = "the selected encoding could not decode the source" |
141 | 150 | except ValueError as error: |
|
0 commit comments