Repository: napari/napari

Issue:
Add action that remove html comments from PR descriptions.
## 🧰 Task

I find it quite annoying to have commit messages like
```
commit XXXXX (origin/main, origin/HEAD, main)
Author: ----
Date:   Sun Jul 23 08:49:48 2023 -0700

    # Fixes/Closes

    <!-- In general, PRs should fix an existing issue on the repo. -->
    <!-- Please link to that issue here as "Closes #(issue-number)". -->
    Closes #5914
```

We should have something that strips html comments from PR merge messages.



Discussion:
Oof. Sorry if I let one of those slip in there... I agree with you @Carreau.
I don't think you are the only one. 

```
$ git log | grep '<!-- In general' | wc -l
      15
```

And more generally:

```
$ git log | grep '<!--' | wc -l
     369
```

We could also remove empty checkboxes, or sections without anything checked.

Resolving patch:
diff --git a/napari/_vispy/overlays/scale_bar.py b/napari/_vispy/overlays/scale_bar.py
--- a/napari/_vispy/overlays/scale_bar.py
+++ b/napari/_vispy/overlays/scale_bar.py
@@ -81,7 +81,7 @@ def _calculate_best_length(self, desired_length: float):
             # When we get the lowest index of the list, removing -1 will
             # return the last index.
             index -= 1
-        new_value = PREFERRED_VALUES[index]
+        new_value: float = PREFERRED_VALUES[index]
         if new_quantity.dimensionless and new_quantity.magnitude < 1:
             # using Decimal is necessary to avoid `4.999999e-6`
             # at really small scale.
diff --git a/tools/remove_html_comments_from_pr.py b/tools/remove_html_comments_from_pr.py
new file mode 100644
--- /dev/null
+++ b/tools/remove_html_comments_from_pr.py
@@ -0,0 +1,74 @@
+"""
+Edit pull request description to remove HTML comments
+
+We might want to remove section with markdown task lists that are completely empty
+"""
+
+import re
+import sys
+from os import environ
+
+import requests
+
+
+def remove_html_comments(text):
+    # Regular expression to remove HTML comments
+    # [^\S\r\n] is whitespace but not new line
+    html_comment_pattern = r"[^\S\r\n]*<!--(.*?)-->[^\S\r\n]*\n?"
+    return re.sub(html_comment_pattern, "", text, flags=re.DOTALL)
+
+
+def edit_pull_request_description(repo, pull_request_number, access_token):
+    # GitHub API base URL
+    base_url = "https://api.github.com"
+
+    # Prepare the headers with the access token
+    headers = {"Authorization": f"token {access_token}"}
+
+    # Get the current pull request description
+    pr_url = f"{base_url}/repos/{repo}/pulls/{pull_request_number}"
+    response = requests.get(pr_url, headers=headers)
+    response.raise_for_status()
+    response_json = response.json()
+    current_description = response_json["body"]
+
+    # Remove HTML comments from the description
+    edited_description = remove_html_comments(current_description)
+    if edited_description == current_description:
+        print("No HTML comments found in the pull request description")
+        return
+
+    # Update the pull request description
+    update_pr_url = f"{base_url}/repos/{repo}/pulls/{pull_request_number}"
+    payload = {"body": edited_description}
+    response = requests.patch(update_pr_url, json=payload, headers=headers)
+    response.raise_for_status()
+
+    if response.status_code == 200:
+        print(
+            f"Pull request #{pull_request_number} description has been updated successfully!"
+        )
+    else:
+        print(
+            f"Failed to update pull request description. Status code: {response.status_code}"
+        )
+
+
+if __name__ == "__main__":
+    # Replace with your repository and pull request number
+    # get cuurrent repository name from github actions
+    repository_name = environ.get("GITHUB_REPOSITORY")
+    if repository_name == "napari/napari":
+        sys.exit(0)
+
+    # get current PR number from github actions
+    github_ref = environ.get("GITHUB_REF")
+    refs, pull, number, merge = github_ref.split('/')
+    assert refs == 'refs'
+    assert pull == 'pull'
+    assert merge == 'merge'
+
+    # Replace with your GitHub access token
+    access_token = environ.get("GITHUB_TOKEN")
+
+    edit_pull_request_description(repository_name, number, access_token)


Test patch: