Skip to content

Commit 28cfb84

Browse files
authored
Add link to clang-tidy check docs to PR comments (#94)
1 parent e0e94fe commit 28cfb84

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

run_action.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import sys
1212
import time
13+
import urllib.parse
1314

1415
import requests
1516
import yaml
@@ -181,6 +182,24 @@ def unescape_chars(s):
181182

182183
return s
183184

185+
def markdown_url(label, url):
186+
return f"[{label}]({url})"
187+
188+
def diagnostic_name_visual(diagnostic_name):
189+
visual = f"**{markdown(diagnostic_name)}**"
190+
191+
try:
192+
first_dash_idx = diagnostic_name.index("-")
193+
except ValueError:
194+
return visual
195+
196+
namespace = urllib.parse.quote_plus(diagnostic_name[:first_dash_idx])
197+
check_name = urllib.parse.quote_plus(diagnostic_name[first_dash_idx + 1 :])
198+
return markdown_url(
199+
visual,
200+
f"https://clang.llvm.org/extra/clang-tidy/checks/{namespace}/{check_name}.html",
201+
)
202+
184203
def generate_single_comment(
185204
file_path,
186205
start_line_num,
@@ -189,12 +208,12 @@ def generate_single_comment(
189208
message,
190209
single_comment_marker,
191210
replacement_text=None,
192-
): # pylint: disable=too-many-arguments,too-many-positional-arguments
211+
): # pylint: disable=too-many-arguments,too-many-positional-arguments,line-too-long
193212
result = {
194213
"path": file_path,
195214
"line": end_line_num,
196215
"side": "RIGHT",
197-
"body": f"{single_comment_marker} **{markdown(name)}** {single_comment_marker}\n"
216+
"body": f"{single_comment_marker} {diagnostic_name_visual(name)} {single_comment_marker}\n"
198217
+ markdown(message),
199218
}
200219

0 commit comments

Comments
 (0)