integrations/trello: Make the zulip_trello script self-contained.

A few users have complained about how hard it is to find the
Trello script on their systems after installing the `zulip`
package. Rishi and I decided that we should instead just ask
the users to download the script directly and run it without
having to install the `zulip` package.

This commit also ensures that the script can be run on both
py2 and py3.
This commit is contained in:
Eeshan Garg 2018-09-14 18:01:13 -02:30
parent 5210e79dbd
commit 71a15bd89e
3 changed files with 19 additions and 5 deletions

View file

@ -29,6 +29,10 @@ exclude = [
"zulip_bots/zulip_bots/terminal.py", "zulip_bots/zulip_bots/terminal.py",
"zulip_bots/zulip_bots/simple_lib.py", "zulip_bots/zulip_bots/simple_lib.py",
"zulip_bots/zulip_bots/tests/test_lib.py", "zulip_bots/zulip_bots/tests/test_lib.py",
# Excluded because this is a self-contained script
# we ask our users to download and run directly and
# py2 and py3 compatibility is required.
"zulip/integrations/trello/zulip_trello.py",
"tools", "tools",
] ]

View file

View file

@ -5,12 +5,13 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import sys import sys
import argparse import argparse
import requests import requests
def get_model_id(options: argparse.Namespace) -> str: def get_model_id(options):
"""get_model_id """get_model_id
Get Model Id from Trello API Get Model Id from Trello API
@ -44,7 +45,7 @@ def get_model_id(options: argparse.Namespace) -> str:
return board_info_json['id'] return board_info_json['id']
def get_webhook_id(options: argparse.Namespace, id_model: str) -> str: def get_webhook_id(options, id_model):
"""get_webhook_id """get_webhook_id
Get webhook id from Trello API Get webhook id from Trello API
@ -81,7 +82,7 @@ def get_webhook_id(options: argparse.Namespace, id_model: str) -> str:
return webhook_info_json['id'] return webhook_info_json['id']
def create_webhook(options: argparse.Namespace) -> None: def create_webhook(options):
"""create_webhook """create_webhook
Create Trello webhook Create Trello webhook
@ -106,8 +107,17 @@ def create_webhook(options: argparse.Namespace) -> None:
print('Success! The webhook for the {} Trello board was successfully created.'.format( print('Success! The webhook for the {} Trello board was successfully created.'.format(
options.trello_board_name)) options.trello_board_name))
def main() -> None: def main():
parser = argparse.ArgumentParser() description = """
zulip_trello.py is a handy little script that allows Zulip users to
quickly set up a Trello webhook.
Note: The Trello webhook instructions available on your Zulip server
may be outdated. Please make sure you follow the updated instructions
at <https://zulipchat.com/integrations/doc/trello>.
"""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--trello-board-name', parser.add_argument('--trello-board-name',
required=True, required=True,
help='The Trello board name.') help='The Trello board name.')