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) - name: Check Deleted Files(s)
if: env.GIT_DIFF 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 - name: Save PR metadata
run: | run: |

View file

@ -72,6 +72,13 @@ jobs:
mkdir printer-linter-result mkdir printer-linter-result
unzip printer-linter-result.zip -d 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 - name: Run clang-tidy-pr-comments action
uses: platisd/clang-tidy-pr-comments@bc0bb7da034a8317d54e7fe1e819159002f4cc40 uses: platisd/clang-tidy-pr-comments@bc0bb7da034a8317d54e7fe1e819159002f4cc40
with: with:

View file

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

View file

@ -42,18 +42,19 @@ def main() -> None:
settings = yaml.load(f, yaml.FullLoader) settings = yaml.load(f, yaml.FullLoader)
full_body_check = {"Diagnostics": []} full_body_check = {"Diagnostics": []}
comments_check = {"Git Comment": []}
for file in files: for file in files:
if not path.exists(file): if not path.exists(file):
print(f"Can't find the file: {file}") print(f"Can't find the file: {file}")
return return
if args.deleted and files ==[]: if args.deleted:
for file in args.Files: for file in args.Files:
deletedFiles = diagnoseIssuesWithFile(file, settings ) 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: if report:
report.write_text(results) report.write_text(results)