Skip to content

Commit 2cc27d0

Browse files
kmillKha
authored andcommitted
feat: convert links such as zulip#123 to repoName#123
Also fixes a bug where the match variable `m` wasn't being reset in the unlikely event that the message was completely empty.
1 parent 9c0c7e5 commit 2cc27d0

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

zulip/integrations/rss/rss-bot

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ parser.add_argument(
8686
help="Convert $ to $$ (for KaTeX processing)",
8787
default=False,
8888
)
89+
parser.add_argument(
90+
"--pr-links",
91+
dest="pr_links",
92+
action="store_true",
93+
help="Prefix PR/issue links like '#123' with the repository name in the message body",
94+
default=False,
95+
)
8996

9097
opts = parser.parse_args() # type: Any
9198

@@ -176,21 +183,25 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:
176183
if m:
177184
repo = m.group(1) # type: str
178185
lines = body.splitlines()
179-
if lines:
180-
m = re.match(r"^(.*?) \((#\d+)\)(.*)$", lines[0])
186+
main_body = "\n".join(lines[1:])
187+
if opts.pr_links:
188+
main_body = re.sub(r'(?<!\w)(#[0-9]+)\b', lambda m: repo + m.group(0), main_body)
189+
m = re.match(r"^(.*?) \((#\d+)\)(.*)$", lines[0]) if lines else None
181190
if m:
182-
body = "**[{}]({})** ({}{}){}\n".format(
191+
body = "**[{}]({})** ({}{}){}\n{}".format(
183192
m.group(1),
184193
entry.link,
185194
repo,
186195
m.group(2),
187-
m.group(3)
188-
) + "\n".join(lines[1:])
196+
m.group(3),
197+
main_body
198+
)
189199
elif lines:
190-
body = "**[{}]({})**\n".format(
200+
body = "**[{}]({})**\n{}".format(
191201
lines[0],
192-
entry.link
193-
) + "\n".join(lines[1:])
202+
entry.link,
203+
main_body
204+
)
194205

195206
author_detail = entry.author # type: str
196207
if 'author_detail' in entry and 'href' in entry.author_detail:

0 commit comments

Comments
 (0)