2020-04-02 09:59:28 -04:00
|
|
|
#!/usr/bin/env python3
|
2013-05-01 14:36:55 -04:00
|
|
|
#
|
2013-08-06 15:32:15 -04:00
|
|
|
# Zulip notification post-commit hook.
|
2013-05-01 14:36:55 -04:00
|
|
|
#
|
|
|
|
# The "post-commit" script is run after a transaction is completed and a new
|
|
|
|
# revision is created. It is passed arguments on the command line in this
|
|
|
|
# form:
|
|
|
|
# <path> <revision>
|
|
|
|
# For example:
|
|
|
|
# /srv/svn/carols 1843
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
2021-05-28 05:00:04 -04:00
|
|
|
import sys
|
2020-04-18 19:00:35 -04:00
|
|
|
from typing import Any, Dict, Optional, Text, Tuple
|
2016-12-28 09:06:16 -05:00
|
|
|
|
2021-05-28 05:00:04 -04:00
|
|
|
import pysvn
|
|
|
|
|
2013-05-01 14:36:55 -04:00
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
2013-08-07 11:55:22 -04:00
|
|
|
import zulip_svn_config as config
|
2021-05-28 05:00:04 -04:00
|
|
|
|
2013-12-05 17:42:33 -05:00
|
|
|
VERSION = "0.9"
|
2013-05-01 14:36:55 -04:00
|
|
|
|
2013-08-07 12:26:59 -04:00
|
|
|
if config.ZULIP_API_PATH is not None:
|
|
|
|
sys.path.append(config.ZULIP_API_PATH)
|
2013-05-01 14:36:55 -04:00
|
|
|
|
2013-08-07 11:51:03 -04:00
|
|
|
import zulip
|
2021-05-28 05:00:04 -04:00
|
|
|
|
2013-08-07 11:51:03 -04:00
|
|
|
client = zulip.Client(
|
2013-08-07 12:26:59 -04:00
|
|
|
email=config.ZULIP_USER,
|
|
|
|
site=config.ZULIP_SITE,
|
2013-12-05 17:42:33 -05:00
|
|
|
api_key=config.ZULIP_API_KEY,
|
2021-05-28 05:03:46 -04:00
|
|
|
client="ZulipSVN/" + VERSION,
|
|
|
|
) # type: zulip.Client
|
2016-12-28 09:06:16 -05:00
|
|
|
svn = pysvn.Client() # type: pysvn.Client
|
2013-05-01 14:36:55 -04:00
|
|
|
|
2016-12-28 09:06:16 -05:00
|
|
|
path, rev = sys.argv[1:] # type: Tuple[Text, Text]
|
2013-05-01 14:36:55 -04:00
|
|
|
|
|
|
|
# since its a local path, prepend "file://"
|
|
|
|
path = "file://" + path
|
|
|
|
|
2021-05-28 05:03:46 -04:00
|
|
|
entry = svn.log(path, revision_end=pysvn.Revision(pysvn.opt_revision_kind.number, rev))[
|
|
|
|
0
|
|
|
|
] # type: Dict[Text, Any]
|
2020-04-09 20:14:01 -04:00
|
|
|
message = "**{}** committed revision r{} to `{}`.\n\n> {}".format(
|
2021-05-28 05:03:46 -04:00
|
|
|
entry['author'], rev, path.split('/')[-1], entry['revprops']['svn:log']
|
|
|
|
) # type: Text
|
2013-05-01 14:36:55 -04:00
|
|
|
|
2016-12-28 09:06:16 -05:00
|
|
|
destination = config.commit_notice_destination(path, rev) # type: Optional[Dict[Text, Text]]
|
2013-05-01 14:36:55 -04:00
|
|
|
|
2018-01-07 12:21:27 -05:00
|
|
|
if destination is not None:
|
|
|
|
message_data = {
|
|
|
|
"type": "stream",
|
|
|
|
"to": destination["stream"],
|
|
|
|
"subject": destination["subject"],
|
|
|
|
"content": message,
|
|
|
|
} # type: Dict[str, Any]
|
|
|
|
client.send_message(message_data)
|