Implement GitComment class and update workflow files

A new GitComment class was implemented to replace Diagnostic for deleted file checks. As part of this change, both main workflow files (printer-linter-pr-diagnose.yml and printer-linter-pr-post.yml) have been updated to accommodate this new class. Also, reports now use 'comment.md' instead of 'fixes.yml'. All of this is ultimately geared at improving diagnostic functionality and allowing deleted file checks to output directly to a Git comment.

CURA-10903
This commit is contained in:
Saumya Jain 2024-04-09 11:33:24 +02:00
parent 702f8573c3
commit 561a40d000
5 changed files with 28 additions and 16 deletions

View file

@ -44,7 +44,7 @@ jobs:
- name: Check Deleted Files(s)
if: env.GIT_DIFF
run: python printer-linter/src/terminal.py --deleted --report printer-linter-result/fixes.yml ${{ env.GIT_DIFF_FILTERED }}
run: python printer-linter/src/terminal.py --deleted --report printer-linter-result/comment.md ${{ env.GIT_DIFF_FILTERED }}
- name: Save PR metadata
run: |

View file

@ -72,6 +72,13 @@ jobs:
mkdir printer-linter-result
unzip printer-linter-result.zip -d printer-linter-result
- name: Run PR Comments
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-path: printer-linter-result/comment.md
- name: Run clang-tidy-pr-comments action
uses: platisd/clang-tidy-pr-comments@bc0bb7da034a8317d54e7fe1e819159002f4cc40
with:

View file

@ -32,3 +32,13 @@ class Diagnostic:
},
"Level": self.level
}
class GitComment:
def __init__(self, comment: str) -> None:
"""
@param comment: The comment text.
"""
self.comment = comment
def toDict(self) -> Dict[str, Any]:
return self.comment

View file

@ -1,7 +1,7 @@
from pathlib import Path
from typing import Iterator
from ..diagnostic import Diagnostic
from ..diagnostic import Diagnostic, GitComment
from .linter import Linter
@ -14,7 +14,7 @@ class Directory(Linter):
if self._file.exists() and self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
for check in self.checkForDotInDirName():
yield check
if self._settings["checks"].get("diagnostic-resource-file-deleted", False):
elif self._settings["checks"].get("diagnostic-resource-file-deleted", False):
for check in self.checkFilesDeleted():
yield check
@ -32,14 +32,8 @@ class Directory(Linter):
)
yield
def checkFilesDeleted(self) -> Iterator[Diagnostic]:
""" Check if there is a file that is deleted, this causes upgrade scripts to not work properly """
yield Diagnostic(
file = self._file.parent,
diagnostic_name = "diagnostic-resource-file-deleted",
message = f"File: {self._file} must not be deleted as it is not allowed. It will create issues upgrading Cura",
level = "Error",
offset = 1
)
def checkFilesDeleted(self) -> Iterator[GitComment]:
if not self._file.exists():
""" Check if there is a file that is deleted, this causes upgrade scripts to not work properly """
yield GitComment( f"File: {self._file} must not be deleted as it is not allowed. It will create issues upgrading Cura" )
yield

View file

@ -42,18 +42,19 @@ def main() -> None:
settings = yaml.load(f, yaml.FullLoader)
full_body_check = {"Diagnostics": []}
comments_check = {"Git Comment": []}
for file in files:
if not path.exists(file):
print(f"Can't find the file: {file}")
return
if args.deleted and files ==[]:
if args.deleted:
for file in args.Files:
deletedFiles = diagnoseIssuesWithFile(file, settings )
full_body_check["Diagnostics"].extend([d.toDict() for d in deletedFiles])
comments_check["GitComment"].extend([d.toDict() for d in deletedFiles])
results = yaml.dump(full_body_check, default_flow_style=False, indent=4, width=240)
results = yaml.dump(comments_check, default_flow_style=False, indent=4, width=240)
if report:
report.write_text(results)