Browse Source

Show the weakest license check rename and its score next to its own source

pull/16341/head
Viacheslav Klimov 2 months ago
parent
commit
8d77085d56
Failed to extract signature
  1. 10
      tools/src/main/python/license-headers/check_license_headers.py
  2. 9
      tools/src/main/python/license-headers/test_check_license_headers.py

10
tools/src/main/python/license-headers/check_license_headers.py

@ -845,7 +845,7 @@ def infer(evidence):
f"and is less than {SIMILARITY}% similar to the CE {source}")
elif weakest["similarity"] < SIMILARITY:
reason = (f"renamed from CE {source}, but the rename of {weakest['from']} in {weakest['commit'][:11]} "
f"is less than {SIMILARITY}% similar without the header")
f"is {weakest['similarity']}% similar without the header, less than {SIMILARITY}%")
else:
return (verdict(evidence.current, "ce-modified", f"renamed from CE {source}")
| {"renamedFrom": list(evidence.renamed_from), "renames": renames})
@ -1130,15 +1130,15 @@ def describe_mismatch(row):
def describe_unresolved(row, ref_names):
hint = f" (hint: {row['suggestedHeader']})" if row.get("suggestedHeader") else ""
details = [f"has {header_name(row['currentHeader'])}, no expected header yet{hint}"]
renamed = min((rename["similarity"] for rename in row.get("renames", [])), default=None)
evidence = [(f"renamed from CE file ({renamed}% at the rename)", candidate)
for candidate in row.get("renameCandidates", [])]
if "renames" in row:
details.append(row["reason"])
evidence = [("rename source in CE", candidate) for candidate in row.get("renameCandidates", [])]
evidence += [(f"similar CE file ({candidate['similarity']}%)", candidate)
for candidate in row.get("copyCandidates", [])]
if "historicalCandidate" in row:
evidence.append(("CE history", row["historicalCandidate"]))
if not evidence:
return details + [row["reason"]]
return details if "renames" in row else details + [row["reason"]]
label, candidate = evidence[0]
details.append(f"{label}: {candidate['path']} at {ref_name(candidate['ref'], ref_names)}")
others = len(evidence) - 1

9
tools/src/main/python/license-headers/test_check_license_headers.py

@ -121,8 +121,8 @@ class DecisionTests(unittest.TestCase):
self.assertEqual(("unresolved", None, None), (row["status"], row["expectedHeader"], row["suggestedHeader"]))
self.assertEqual(([version], [first, weak], [self.COPY]),
(row["renameCandidates"], row["renames"], row["copyCandidates"]))
self.assertEqual("renamed from CE source.java, but the rename of middle.java in eeeeeeeeeee "
f"is less than {p.SIMILARITY}% similar without the header", row["reason"])
self.assertEqual(f"renamed from CE source.java, but the rename of middle.java in eeeeeeeeeee "
f"is {p.SIMILARITY - 1}% similar without the header, less than {p.SIMILARITY}%", row["reason"])
def test_rename_from_a_file_added_outside_ce_needs_a_decision(self):
version = {"path": "source.java", "ref": "a" * 40, "blob": "c" * 40}
@ -959,7 +959,10 @@ class CheckCommandTests(unittest.TestCase):
self.assertEqual({"Source.java"}, {candidate["path"] for candidate in row["renameCandidates"]})
self.assertLess(row["renames"][0]["similarity"], p.SIMILARITY)
self.assertEqual([], report["restamped"])
self.assertIn(" renamed from CE file (", output)
weakest = row["renames"][0]
self.assertIn(f" renamed from CE Source.java, but the rename of Source.java in {weakest['commit'][:11]} "
f"is {weakest['similarity']}% similar without the header, less than {p.SIMILARITY}%\n"
" rename source in CE: Source.java at ", output)
self.assertEqual(rewritten, (self.repo / "Moved.java").read_text())
@requires_merge_file_object_id

Loading…
Cancel
Save