mypy: Annotate api/integrations/trac/zulip_trac.py
This commit is contained in:
parent
7f123585a2
commit
3f8f4dc616
|
@ -42,6 +42,9 @@ sys.path.insert(0, os.path.dirname(__file__))
|
||||||
import zulip_trac_config as config
|
import zulip_trac_config as config
|
||||||
VERSION = "0.9"
|
VERSION = "0.9"
|
||||||
|
|
||||||
|
if False:
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
if config.ZULIP_API_PATH is not None:
|
if config.ZULIP_API_PATH is not None:
|
||||||
sys.path.append(config.ZULIP_API_PATH)
|
sys.path.append(config.ZULIP_API_PATH)
|
||||||
|
|
||||||
|
@ -53,20 +56,25 @@ client = zulip.Client(
|
||||||
client="ZulipTrac/" + VERSION)
|
client="ZulipTrac/" + VERSION)
|
||||||
|
|
||||||
def markdown_ticket_url(ticket, heading="ticket"):
|
def markdown_ticket_url(ticket, heading="ticket"):
|
||||||
|
# type: (Any, str) -> str
|
||||||
return "[%s #%s](%s/%s)" % (heading, ticket.id, config.TRAC_BASE_TICKET_URL, ticket.id)
|
return "[%s #%s](%s/%s)" % (heading, ticket.id, config.TRAC_BASE_TICKET_URL, ticket.id)
|
||||||
|
|
||||||
def markdown_block(desc):
|
def markdown_block(desc):
|
||||||
|
# type: (str) -> str
|
||||||
return "\n\n>" + "\n> ".join(desc.split("\n")) + "\n"
|
return "\n\n>" + "\n> ".join(desc.split("\n")) + "\n"
|
||||||
|
|
||||||
def truncate(string, length):
|
def truncate(string, length):
|
||||||
|
# type: (str, int) -> str
|
||||||
if len(string) <= length:
|
if len(string) <= length:
|
||||||
return string
|
return string
|
||||||
return string[:length - 3] + "..."
|
return string[:length - 3] + "..."
|
||||||
|
|
||||||
def trac_subject(ticket):
|
def trac_subject(ticket):
|
||||||
|
# type: (Any) -> str
|
||||||
return truncate("#%s: %s" % (ticket.id, ticket.values.get("summary")), 60)
|
return truncate("#%s: %s" % (ticket.id, ticket.values.get("summary")), 60)
|
||||||
|
|
||||||
def send_update(ticket, content):
|
def send_update(ticket, content):
|
||||||
|
# type: (Any, str) -> None
|
||||||
client.send_message({
|
client.send_message({
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"to": config.STREAM_FOR_NOTIFICATIONS,
|
"to": config.STREAM_FOR_NOTIFICATIONS,
|
||||||
|
@ -78,6 +86,7 @@ class ZulipPlugin(Component):
|
||||||
implements(ITicketChangeListener)
|
implements(ITicketChangeListener)
|
||||||
|
|
||||||
def ticket_created(self, ticket):
|
def ticket_created(self, ticket):
|
||||||
|
# type: (Any) -> None
|
||||||
"""Called when a ticket is created."""
|
"""Called when a ticket is created."""
|
||||||
content = "%s created %s in component **%s**, priority **%s**:\n" % \
|
content = "%s created %s in component **%s**, priority **%s**:\n" % \
|
||||||
(ticket.values.get("reporter"), markdown_ticket_url(ticket),
|
(ticket.values.get("reporter"), markdown_ticket_url(ticket),
|
||||||
|
@ -90,6 +99,7 @@ class ZulipPlugin(Component):
|
||||||
send_update(ticket, content)
|
send_update(ticket, content)
|
||||||
|
|
||||||
def ticket_changed(self, ticket, comment, author, old_values):
|
def ticket_changed(self, ticket, comment, author, old_values):
|
||||||
|
# type: (Any, str, str, Dict[str, Any]) -> None
|
||||||
"""Called when a ticket is modified.
|
"""Called when a ticket is modified.
|
||||||
|
|
||||||
`old_values` is a dictionary containing the previous values of the
|
`old_values` is a dictionary containing the previous values of the
|
||||||
|
@ -121,6 +131,7 @@ class ZulipPlugin(Component):
|
||||||
send_update(ticket, content)
|
send_update(ticket, content)
|
||||||
|
|
||||||
def ticket_deleted(self, ticket):
|
def ticket_deleted(self, ticket):
|
||||||
|
# type: (Any) -> None
|
||||||
"""Called when a ticket is deleted."""
|
"""Called when a ticket is deleted."""
|
||||||
content = "%s was deleted." % markdown_ticket_url(ticket, heading="Ticket")
|
content = "%s was deleted." % markdown_ticket_url(ticket, heading="Ticket")
|
||||||
send_update(ticket, content)
|
send_update(ticket, content)
|
||||||
|
|
Loading…
Reference in a new issue