Skip to content

Commit

Permalink
fix annotation on line
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Jul 31, 2024
1 parent 249189e commit 28563a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions tests/restyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def find_arduino_files():
class Changed:
file: str
hunk: list[str]
lines: list[str]
lines: list[int]


@dataclass
Expand Down Expand Up @@ -122,7 +122,9 @@ def reset_with_line(ctx, line):

def pop(out, context, line):
if ctx.file and ctx.hunk and ctx.markers:
out.append(Changed(ctx.file, "\n".join(ctx.hunk), ", ".join(ctx.markers)))
out.append(
Changed(file=ctx.file, hunk="\n".join(ctx.hunk), lines=ctx.markers)
)

reset_with_line(context, line)

Expand Down Expand Up @@ -157,7 +159,7 @@ def pop(out, context, line):
numbers = numbers.replace("+", "")
numbers = numbers.replace("-", "")

ctx.markers.append(numbers)
ctx.markers.append(int(numbers))
ctx.append_hunk = True

# capture diff for the summary
Expand All @@ -169,10 +171,12 @@ def pop(out, context, line):
return out


def warning_changed(changed: Changed):
print(
f"::warning file={changed.file},title=Run tests/restyle.sh and re-commit {changed.file}::File {changed.file} failed clang-format style check. (lines {changed.lines})"
)
def errors_changed(changed: Changed):
all_lines = ", ".join(str(x) for x in changed.lines)
for line in changed.lines:
print(
f"::error file={changed.file},title=Run tests/restyle.sh and re-commit {changed.file},line={line}::File {changed.file} failed clang-format style check. (lines {all_lines})"
)


SUMMARY_PATH = pathlib.Path(os.environ.get("GITHUB_STEP_SUMMARY", os.devnull))
Expand Down Expand Up @@ -214,8 +218,8 @@ def run_format(args):

def run_assert(args):
for changed in changed_files():
if args.with_warnings:
warning_changed(changed)
if args.with_errors:
errors_changed(changed)
if args.with_summary:
summary_diff(changed)

Expand Down Expand Up @@ -246,7 +250,7 @@ def run_assert(args):
assert_ = cmd.add_parser("assert")
assert_.set_defaults(func=run_assert)
assert_.add_argument("--with-summary", action="store_true")
assert_.add_argument("--with-warnings", action="store_true")
assert_.add_argument("--with-errors", action="store_true")

args = parser.parse_args()
args.func(args)
2 changes: 1 addition & 1 deletion tests/restyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ CLANG_FORMAT=${CLANG_FORMAT:-clang-format-15}

cd $root
python $root/tests/restyle.py format --clang-format=$CLANG_FORMAT preset --include core --include arduino
python $root/tests/restyle.py assert --with-summary --with-warnings
python $root/tests/restyle.py assert --with-summary --with-errors

0 comments on commit 28563a1

Please sign in to comment.