[llvm] [workflows] Split pr-code-format into two parts to make it more secure (PR #78216)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 16:22:48 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 66786a79d6f622012879e94a92838449bf175a71...59d4a17f76efa9055fed9ced2f0dfad85d4ccf1d llvm/utils/git/code-format-helper.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- code-format-helper.py	2024-01-16 00:19:16.000000 +0000
+++ code-format-helper.py	2024-01-16 00:22:40.895806 +0000
@@ -122,16 +122,13 @@
         comment_text = self.comment_tag + "\n\n" + comment_text
 
         existing_comment = self.find_comment(pr)
 
         if args.write_comment_to_file:
-            self.comment = {
-                'number' : pr.number,
-                'body' : comment_text
-            }
+            self.comment = {"number": pr.number, "body": comment_text}
             if existing_comment:
-                self.comment['id'] =  existing_comment.id
+                self.comment["id"] = existing_comment.id
             return
 
         if existing_comment:
             existing_comment.edit(comment_text)
         elif create_new:
@@ -321,11 +318,11 @@
     for fmt in ALL_FORMATTERS:
         if fmt.has_tool():
             if not fmt.run(args.changed_files, args):
                 failed_fmts.append(fmt.name)
             if fmt.comment:
-              comments.append(fmt.comment)
+                comments.append(fmt.comment)
         else:
             print(f"Couldn't find {fmt.name}, can't check " + fmt.friendly_name.lower())
 
     if len(failed_fmts) > 0:
         sys.exit(1)
@@ -364,12 +361,13 @@
         type=str,
         help="Comma separated list of files that has been changed",
     )
     parser.add_argument(
         "--write-comment-to-file",
-        action='store_true',
-        help="Don't create a comments on the PR, instead write the comments and metadata a file called 'comment'"   )
+        action="store_true",
+        help="Don't create a comments on the PR, instead write the comments and metadata a file called 'comment'",
+    )
 
     args = FormatArgs(parser.parse_args())
 
     changed_files = []
     if args.changed_files:
@@ -380,14 +378,15 @@
     for fmt in ALL_FORMATTERS:
         if not fmt.run(changed_files, args):
             failed_formatters.append(fmt.name)
         if fmt.comment:
             comments.append(fmt.comment)
-    
+
     if len(comments):
-        with open('comments', 'w') as f:
+        with open("comments", "w") as f:
             import json
+
             json.dump(comments, f)
 
     if len(failed_formatters) > 0:
         print(f"error: some formatters failed: {' '.join(failed_formatters)}")
         sys.exit(1)

``````````

</details>


https://github.com/llvm/llvm-project/pull/78216


More information about the llvm-commits mailing list