Print links for all mentioned tickets
Up to now this plugin only printed the link for the first encountered ticket id. With this change links for all tickets are printed instead.
This commit is contained in:
parent
aeaa93d82e
commit
0d22b8e05b
35
plugin.py
35
plugin.py
@ -49,28 +49,25 @@ def doPrivmsg(self, irc, msg):
|
|||||||
if channels and channel not in channels:
|
if channels and channel not in channels:
|
||||||
return
|
return
|
||||||
|
|
||||||
matchobj = self.ticket_pattern.search(payload)
|
|
||||||
if matchobj is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
ticket_number = matchobj.group(1)
|
|
||||||
ticket_url = self.registryValue('ticketUrl')
|
ticket_url = self.registryValue('ticketUrl')
|
||||||
url = f'{ticket_url.rstrip("/")}/{ticket_number}'
|
|
||||||
|
|
||||||
self.log.info(f'Fetching title for {url}')
|
for ticket_number in sorted(set(self.ticket_pattern.findall(payload))):
|
||||||
# Fetch the title of the ticket page
|
url = f'{ticket_url.rstrip("/")}/{ticket_number}'
|
||||||
try:
|
|
||||||
response = urllib.request.urlopen(url)
|
|
||||||
html = response.read().decode()
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
title_match = re.search(r"<title>(.*)</title>", html)
|
self.log.info(f'Fetching title for {url}')
|
||||||
title = title_match[1].strip() if title_match else "No title found"
|
# Fetch the title of the ticket page
|
||||||
# Clean up the title if necessary
|
try:
|
||||||
title = self.title_pattern.sub('', title)
|
response = urllib.request.urlopen(url)
|
||||||
|
html = response.read().decode()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
response = f'{title} – {response.url}'
|
title_match = re.search(r"<title>(.*)</title>", html)
|
||||||
irc.queueMsg(ircmsgs.privmsg(channel, response))
|
title = title_match[1].strip() if title_match else "No title found"
|
||||||
|
# Clean up the title if necessary
|
||||||
|
title = self.title_pattern.sub('', title)
|
||||||
|
|
||||||
|
response = f'{title} – {response.url}'
|
||||||
|
irc.queueMsg(ircmsgs.privmsg(channel, response))
|
||||||
|
|
||||||
Class = wfg
|
Class = wfg
|
||||||
|
34
test.py
34
test.py
@ -124,3 +124,37 @@ def test_ticket_id_at_the_beginning(self):
|
|||||||
"https://gitea.wildfiregames.com/0ad/0ad/issues/1234")
|
"https://gitea.wildfiregames.com/0ad/0ad/issues/1234")
|
||||||
|
|
||||||
self.assertIsNone(self.irc.takeMsg())
|
self.assertIsNone(self.irc.takeMsg())
|
||||||
|
|
||||||
|
def test_match_multiple_ticket_ids(self):
|
||||||
|
obj = self.irc.getCallback('wfg')
|
||||||
|
|
||||||
|
obj.doPrivmsg(
|
||||||
|
self.irc,
|
||||||
|
ircmsgs.privmsg(self.config["supybot.plugins.wfg.channels"][0],
|
||||||
|
"References for this are #1234, #1234,#1235 and #1236")
|
||||||
|
)
|
||||||
|
msg = self.irc.takeMsg()
|
||||||
|
self.assertIsInstance(msg, ircmsgs.IrcMsg)
|
||||||
|
self.assertEqual(msg.nick, "")
|
||||||
|
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
|
||||||
|
self.assertEqual(msg.args[1],
|
||||||
|
"#1234 - [PATCH] Read formations from json files – "
|
||||||
|
"https://gitea.wildfiregames.com/0ad/0ad/issues/1234")
|
||||||
|
|
||||||
|
msg = self.irc.takeMsg()
|
||||||
|
self.assertIsInstance(msg, ircmsgs.IrcMsg)
|
||||||
|
self.assertEqual(msg.nick, "")
|
||||||
|
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
|
||||||
|
self.assertEqual(msg.args[1],
|
||||||
|
"#1235 - selection box moves when moving the camera – "
|
||||||
|
"https://gitea.wildfiregames.com/0ad/0ad/issues/1235")
|
||||||
|
|
||||||
|
msg = self.irc.takeMsg()
|
||||||
|
self.assertIsInstance(msg, ircmsgs.IrcMsg)
|
||||||
|
self.assertEqual(msg.nick, "")
|
||||||
|
self.assertEqual(msg.args[0], self.config["supybot.plugins.wfg.channels"][0])
|
||||||
|
self.assertEqual(msg.args[1],
|
||||||
|
"#1236 - WP Theming - Fine Footer – "
|
||||||
|
"https://gitea.wildfiregames.com/0ad/0ad/issues/1236")
|
||||||
|
|
||||||
|
self.assertIsNone(self.irc.takeMsg())
|
||||||
|
Loading…
Reference in New Issue
Block a user