mypy: Annotate *api/integrations/perforce/zulip_change-commit.py*.
This commit is contained in:
parent
88bdcd61b8
commit
7f123585a2
|
@ -44,6 +44,7 @@ import git_p4
|
||||||
__version__ = "0.1"
|
__version__ = "0.1"
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(__file__))
|
sys.path.insert(0, os.path.dirname(__file__))
|
||||||
|
from typing import Any, Dict, Optional, Text
|
||||||
import zulip_perforce_config as config
|
import zulip_perforce_config as config
|
||||||
|
|
||||||
if config.ZULIP_API_PATH is not None:
|
if config.ZULIP_API_PATH is not None:
|
||||||
|
@ -54,11 +55,11 @@ client = zulip.Client(
|
||||||
email=config.ZULIP_USER,
|
email=config.ZULIP_USER,
|
||||||
site=config.ZULIP_SITE,
|
site=config.ZULIP_SITE,
|
||||||
api_key=config.ZULIP_API_KEY,
|
api_key=config.ZULIP_API_KEY,
|
||||||
client="ZulipPerforce/" + __version__)
|
client="ZulipPerforce/" + __version__) # type: zulip.Client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
changelist = int(sys.argv[1])
|
changelist = int(sys.argv[1]) # type: int
|
||||||
changeroot = sys.argv[2]
|
changeroot = sys.argv[2] # type: str
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("Wrong number of arguments.\n\n", end=' ', file=sys.stderr)
|
print("Wrong number of arguments.\n\n", end=' ', file=sys.stderr)
|
||||||
print(__doc__, file=sys.stderr)
|
print(__doc__, file=sys.stderr)
|
||||||
|
@ -68,22 +69,23 @@ except ValueError:
|
||||||
print(__doc__, file=sys.stderr)
|
print(__doc__, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
metadata = git_p4.p4_describe(changelist)
|
metadata = git_p4.p4_describe(changelist) # type: Dict[str, str]
|
||||||
|
|
||||||
destination = config.commit_notice_destination(changeroot, changelist)
|
destination = config.commit_notice_destination(changeroot, changelist) # type: Optional[Dict[str, str]]
|
||||||
if destination is None:
|
if destination is None:
|
||||||
# Don't forward the notice anywhere
|
# Don't forward the notice anywhere
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
message = """**{0}** committed revision @{1} to `{2}`.
|
message = "**{0}** committed revision @{1} to `{2}`.\n\n> {3}".format(
|
||||||
|
metadata["user"],
|
||||||
> {3}
|
metadata["change"],
|
||||||
""".format(metadata["user"], metadata["change"], changeroot, metadata["desc"])
|
changeroot,
|
||||||
|
metadata["desc"]) # type: str
|
||||||
|
|
||||||
message_data = {
|
message_data = {
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"to": destination["stream"],
|
"to": destination["stream"],
|
||||||
"subject": destination["subject"],
|
"subject": destination["subject"],
|
||||||
"content": message,
|
"content": message,
|
||||||
}
|
} # type: Dict[str, Any]
|
||||||
client.send_message(message_data)
|
client.send_message(message_data)
|
||||||
|
|
Loading…
Reference in a new issue