diff --git a/.github/workflows/printer-linter-pr-diagnose.yml b/.github/workflows/printer-linter-pr-diagnose.yml index 2846cdb603..1be20c4548 100644 --- a/.github/workflows/printer-linter-pr-diagnose.yml +++ b/.github/workflows/printer-linter-pr-diagnose.yml @@ -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: | diff --git a/.github/workflows/printer-linter-pr-post.yml b/.github/workflows/printer-linter-pr-post.yml index 81dbf96469..94fe810c43 100644 --- a/.github/workflows/printer-linter-pr-post.yml +++ b/.github/workflows/printer-linter-pr-post.yml @@ -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: diff --git a/printer-linter/src/printerlinter/diagnostic.py b/printer-linter/src/printerlinter/diagnostic.py index 27f4fdd14a..1ef8bef638 100644 --- a/printer-linter/src/printerlinter/diagnostic.py +++ b/printer-linter/src/printerlinter/diagnostic.py @@ -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 \ No newline at end of file diff --git a/printer-linter/src/printerlinter/linters/directory.py b/printer-linter/src/printerlinter/linters/directory.py index e1b04c84f6..d8626b1be4 100644 --- a/printer-linter/src/printerlinter/linters/directory.py +++ b/printer-linter/src/printerlinter/linters/directory.py @@ -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 \ No newline at end of file diff --git a/printer-linter/src/terminal.py b/printer-linter/src/terminal.py index fa2212285c..b7c1607660 100644 --- a/printer-linter/src/terminal.py +++ b/printer-linter/src/terminal.py @@ -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)