fix: align migrated review helpers with repository lint policy
This commit is contained in:
1 parent
9454e7987c
commit
f2441ddd2a
2 files changed
+27
-15
No files matched your search
Executable → Regular
+17
-4
@@ -6,11 +6,24 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import ast
|
import ast
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
HUNK = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
|
||||||
|
def parse_hunk(text):
|
||||||
|
"""Parse a unified-diff hunk header without a runtime dependency."""
|
||||||
|
parts = text.split(" ", 4)
|
||||||
|
if len(parts) < 4 or parts[0] != "@@" or not parts[3].startswith("@@"):
|
||||||
|
return None
|
||||||
|
bounds = []
|
||||||
|
for value, sign in zip(parts[1:3], ("-", "+")):
|
||||||
|
if not value.startswith(sign):
|
||||||
|
return None
|
||||||
|
numbers = value[1:].split(",")
|
||||||
|
if len(numbers) not in (1, 2) or not all(number.isdecimal() for number in numbers):
|
||||||
|
return None
|
||||||
|
bounds.extend((numbers[0], numbers[1] if len(numbers) == 2 else None))
|
||||||
|
return tuple(bounds)
|
||||||
|
|
||||||
|
|
||||||
def diff_path(value):
|
def diff_path(value):
|
||||||
@@ -29,8 +42,8 @@ def diff_lines(diff):
|
|||||||
if text.startswith("diff --git "):
|
if text.startswith("diff --git "):
|
||||||
old_path = new_path = None
|
old_path = new_path = None
|
||||||
old_remaining = new_remaining = 0
|
old_remaining = new_remaining = 0
|
||||||
elif match := HUNK.match(text):
|
elif hunk := parse_hunk(text):
|
||||||
old_line, old_count, new_line, new_count = match.groups()
|
old_line, old_count, new_line, new_count = hunk
|
||||||
old_line, new_line = int(old_line), int(new_line)
|
old_line, new_line = int(old_line), int(new_line)
|
||||||
old_remaining = int(old_count) if old_count is not None else 1
|
old_remaining = int(old_count) if old_count is not None else 1
|
||||||
new_remaining = int(new_count) if new_count is not None else 1
|
new_remaining = int(new_count) if new_count is not None else 1
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ else:
|
|||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_select_filters_drafts_wip_and_own_prs(self):
|
def test_select_filters_drafts_wip_and_own_prs(self):
|
||||||
prs = [
|
prs = [
|
||||||
{"number": i, "title": title, "author": {"login": author}, "isDraft": draft}
|
{"number": i, "title": title, "author": {"login": author}, "isDraft": draft}
|
||||||
@@ -113,17 +112,17 @@ else:
|
|||||||
self.assertNotEqual(result.returncode, 0)
|
self.assertNotEqual(result.returncode, 0)
|
||||||
|
|
||||||
def test_verify_deleted_file_on_left(self):
|
def test_verify_deleted_file_on_left(self):
|
||||||
diff = (
|
diff = "diff --git a/gone.py b/gone.py\n--- a/gone.py\n+++ /dev/null\n@@ -1 +0,0 @@\n-old\n"
|
||||||
"diff --git a/gone.py b/gone.py\n--- a/gone.py\n+++ /dev/null\n"
|
result = self.verify([{"path": "gone.py", "line": 1, "side": "LEFT", "body": "Check"}], diff)
|
||||||
"@@ -1 +0,0 @@\n-old\n"
|
|
||||||
)
|
|
||||||
result = self.verify(
|
|
||||||
[{"path": "gone.py", "line": 1, "side": "LEFT", "body": "Check"}], diff
|
|
||||||
)
|
|
||||||
self.assertEqual(result.returncode, 0, result.stderr)
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
result = self.verify(
|
result = self.verify([{"path": "gone.py", "line": 1, "side": "RIGHT", "body": "Check"}], diff)
|
||||||
[{"path": "gone.py", "line": 1, "side": "RIGHT", "body": "Check"}], diff
|
self.assertNotEqual(result.returncode, 0)
|
||||||
)
|
|
||||||
|
def test_verify_new_file_with_explicit_zero_old_count(self):
|
||||||
|
diff = "diff --git a/new.py b/new.py\n--- /dev/null\n+++ b/new.py\n@@ -0,0 +1,2 @@\n+one\n+two\n"
|
||||||
|
result = self.verify([{"path": "new.py", "line": 2, "side": "RIGHT", "body": "Check"}], diff)
|
||||||
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
|
result = self.verify([{"path": "new.py", "line": 1, "side": "LEFT", "body": "Check"}], diff)
|
||||||
self.assertNotEqual(result.returncode, 0)
|
self.assertNotEqual(result.returncode, 0)
|
||||||
|
|
||||||
def test_verify_checks_multiline_comment_start(self):
|
def test_verify_checks_multiline_comment_start(self):
|
||||||
|
|||||||
Reference in new issue
Block a user