[llvm] [workflow] escape issue/pr body only if it exists (PR #71251)

Julian Schmidt via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 16:16:42 PDT 2023


https://github.com/5chmidti created https://github.com/llvm/llvm-project/pull/71251

Empty descriptions for issues should not exist, but might happen
accidentally.
Empty desciptions for prs may exist when no further explanation
beyond the pr title is needed.

For empty bodies, this script would crash in `html.escape`
because the type of the supposed str is NoneType.


>From b9bd1734de5d47a03691005bd217601223dde1a1 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmidti at users.noreply.github.com>
Date: Sat, 4 Nov 2023 00:08:28 +0100
Subject: [PATCH] [workflow] escape issue/pr body only if it exists

Empty descriptions for issues should not exist, but might happen
accidentally.
Empty desciptions for prs may exist when no further explanation
beyond the pr title is needed.

For empty bodies, this script would crash in `html.escape`
because the type of the supposed str is NoneType.
---
 llvm/utils/git/github-automation.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 52523704fe82dc8..b8a7c98065f54c0 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -77,7 +77,12 @@ def run(self) -> bool:
         if team.slug == "issue-subscribers-good-first-issue":
             comment = "{}\n".format(beginner_comment)
 
-        body = escape_description(self.issue.body)
+        # Check for an empty issue description,
+        # which should not occur, but this avoids crashing
+        # if it does.
+        body = ""
+        if self.issue.body is not None:
+            body = escape_description(self.issue.body)
 
         comment = f"""
 @llvm/{team.slug}
@@ -160,7 +165,10 @@ def run(self) -> bool:
             patch = patch[0:DIFF_LIMIT] + "...\n[truncated]\n"
         team_mention = "@llvm/{}".format(team.slug)
 
-        body = escape_description(self.pr.body)
+        # Check for an empty pr description
+        body = ""
+        if self.pr.body is not None:
+            body = escape_description(self.pr.body)
         # Note: the comment is in markdown and the code below
         # is sensible to line break
         comment = f"""



More information about the llvm-commits mailing list