Skip to content

Commit 3424ef6

Browse files
committed
Add a comment with the summary of the submission
1 parent 2606ff8 commit 3424ef6

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ jobs:
3131
3232
- name: Show changed files
3333
run: |
34-
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
35-
poetry run smtcomp show $file
36-
done
34+
poetry run smtcomp show --into-comment-file comment.md ${{ steps.changed-files.outputs.all_changed_files }}
35+
36+
- name: PR comment with file
37+
uses: thollander/actions-comment-pull-request@v2
38+
with:
39+
filePath: comment.md
40+
comment_tag: summary
3741

3842
- name: Run checks
3943
run: make check

smtcomp/defs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def of_int(cls, id: int) -> EnumAutoInt:
6767
def __hash__(self) -> int:
6868
return self.id
6969

70+
def __lt__(self, a: EnumAutoInt) -> bool:
71+
return self.id.__lt__(a.id)
72+
73+
def __le__(self, a: EnumAutoInt) -> bool:
74+
return self.id.__le__(a.id)
75+
76+
def __gt__(self, a: EnumAutoInt) -> bool:
77+
return self.id.__gt__(a.id)
78+
79+
def __ge__(self, a: EnumAutoInt) -> bool:
80+
return self.id.__ge__(a.id)
81+
7082

7183
class NameEmail(BaseModel):
7284
"""

smtcomp/main.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,49 @@
2626
import smtcomp.selection
2727
from smtcomp.unpack import write_cin, read_cin
2828
import smtcomp.scramble_benchmarks
29+
from rich.console import Console
2930

3031
app = typer.Typer()
3132

3233

3334
@app.command()
34-
def show(file: str) -> None:
35+
def show(
36+
files: list[Path] = typer.Argument(None),
37+
into_comment_file: Annotated[Optional[Path], typer.Option(help="Write the summary into the given file")] = None,
38+
) -> None:
3539
"""
3640
Show information about a solver submission
3741
"""
38-
s = None
39-
try:
40-
s = submission.read(file)
41-
except Exception as e:
42-
rich.print(f"[red]Error during file parsing of {file}[/red]")
43-
print(e)
44-
exit(1)
45-
if not s:
46-
rich.print(f"[red]Empty submission??? {file}[/red]")
47-
exit(1)
48-
submission.show(s)
4942

43+
def read_submission(file: Path) -> defs.Submission:
44+
try:
45+
return submission.read(str(file))
46+
except Exception as e:
47+
rich.print(f"[red]Error during file parsing of {file}[/red]")
48+
print(e)
49+
exit(1)
50+
51+
l = list(map(read_submission, files))
52+
53+
console = Console(record=into_comment_file is not None)
54+
if into_comment_file is not None:
55+
console.print("<details><summary>Summary of modified submissions</summary>")
56+
for s in l:
57+
if into_comment_file is not None:
58+
console.print("")
59+
console.print("```")
60+
t = submission.tree_summary(s)
61+
console.print(t)
62+
if into_comment_file is not None:
63+
console.print("```")
64+
if into_comment_file is not None:
65+
console.print("</details>")
66+
67+
if into_comment_file is not None:
68+
if len(l) > 0:
69+
into_comment_file.write_text(console.export_text())
70+
else:
71+
into_comment_file.write_text("")
5072

5173
@app.command()
5274
def validate(file: str) -> None:

smtcomp/submission.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def read(file: str) -> Submission:
1010
return Submission.model_validate_json(Path(file).read_text())
1111

1212

13-
def show(s: Submission) -> None:
13+
def tree_summary(s: Submission) -> Tree:
1414
tree = Tree(f"[bold]{s.name}[/bold]")
1515
tree.add(f"{len(s.contributors)} authors")
1616
tree.add(f"website: {s.website}")
@@ -23,4 +23,8 @@ def show(s: Submission) -> None:
2323
slogics = map(str, logics)
2424
for logic in sorted(slogics):
2525
tree_div.add(logic)
26-
rich.print(tree)
26+
return tree
27+
28+
29+
def show(s: Submission) -> None:
30+
rich.print(tree_summary(s))

tests/test_validate.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_bad_json(name: str) -> None:
2626
assert result.exit_code == 1
2727

2828

29+
@pytest.mark.parametrize("name", good_cases)
30+
def test_show_json(name: str) -> None:
31+
result = runner.invoke(app, ["show", name])
32+
assert result.exit_code == 0
33+
34+
2935
submissions = list(Path("submissions").glob("*.json"))
3036

3137

0 commit comments

Comments
 (0)