diff --git a/zulip/integrations/trello/README.md b/zulip/integrations/trello/README.md index 9a15e38..552c2f4 100644 --- a/zulip/integrations/trello/README.md +++ b/zulip/integrations/trello/README.md @@ -2,12 +2,22 @@ Usage : -1. Fill the needed information in `zulip_trello_config.py` : +1. Make sure you have all of the relevant Trello credentials before + executing the script: - - The Trello API KEY, - - The Trello TOKEN, + - The Trello API KEY + - The Trello TOKEN - The Zulip webhook URL + - Trello board name + - Trello board ID 2. Execute the script : - $ python zulip_trello.py + $ python zulip_trello.py --trello-board-name \ + --trello-board-id \ + --trello-api-key \ + --trello-token \ + --zulip-webhook-url + +For more information, please see Zulip's documentation on how to set up +a Trello integration [here](https://zulipchat.com/integrations/doc/trello). diff --git a/zulip/integrations/trello/zulip_trello.py b/zulip/integrations/trello/zulip_trello.py index 3513792..5a95830 100755 --- a/zulip/integrations/trello/zulip_trello.py +++ b/zulip/integrations/trello/zulip_trello.py @@ -10,33 +10,6 @@ import sys import argparse import requests -import zulip_trello_config as configuration - - -def check_configuration() -> None: - """check_configuration - - Check if configuration fields have been populated in - zulip_trello_config.py - """ - - errors = [] - - if not configuration.TRELLO_API_KEY: - errors.append('Error: TRELLO_API_KEY is not defined in zulip_trello_config.py') - - if not configuration.TRELLO_TOKEN: - errors.append('Error: TRELLO_TOKEN is not defined in zulip_trello_config.py') - - if not configuration.ZULIP_WEBHOOK_URL: - errors.append('Error: ZULIP_WEBHOOK_URL is not defined in zulip_trello_config.py') - - if len(errors) > 0: - for error in errors: - print(error) - - sys.exit(1) - def get_model_id(options: argparse.Namespace) -> str: """get_model_id @@ -53,8 +26,8 @@ def get_model_id(options: argparse.Namespace) -> str: ) params = { - 'key': configuration.TRELLO_API_KEY, - 'token': configuration.TRELLO_TOKEN, + 'key': options.trello_api_key, + 'token': options.trello_token, } trello_response = requests.get( @@ -86,12 +59,12 @@ def get_webhook_id(options: argparse.Namespace, id_model: str) -> str: trello_api_url = 'https://api.trello.com/1/webhooks/' data = { - 'key': configuration.TRELLO_API_KEY, - 'token': configuration.TRELLO_TOKEN, + 'key': options.trello_api_key, + 'token': options.trello_token, 'description': 'Webhook for Zulip integration (From Trello {} to Zulip)'.format( options.trello_board_name, ), - 'callbackURL': configuration.ZULIP_WEBHOOK_URL, + 'callbackURL': options.zulip_webhook_url, 'idModel': id_model } @@ -160,11 +133,27 @@ def create_webhook(options: argparse.Namespace) -> None: def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument('trello_board_name', help='The Trello board name.') - parser.add_argument('trello_board_id', help='The Trello board short id.') + parser.add_argument('--trello-board-name', + required=True, + help='The Trello board name.') + parser.add_argument('--trello-board-id', + required=True, + help=('The Trello board short ID. Can usually be found ' + 'in the URL of the Trello board.')) + parser.add_argument('--trello-api-key', + required=True, + help=('Visit https://trello.com/1/appkey/generate to generate ' + 'an APPLICATION_KEY (need to be logged into Trello).')) + parser.add_argument('--trello-token', + required=True, + help=('Visit https://trello.com/1/appkey/generate and under ' + '`Developer API Keys`, click on `Token` and generate ' + 'a Trello access token.')) + parser.add_argument('--zulip-webhook-url', + required=True, + help='The webhook URL that Trello will query.') options = parser.parse_args() - check_configuration() create_webhook(options) if __name__ == '__main__': diff --git a/zulip/integrations/trello/zulip_trello_config.py b/zulip/integrations/trello/zulip_trello_config.py deleted file mode 100644 index 39c239f..0000000 --- a/zulip/integrations/trello/zulip_trello_config.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright © 2014 Zulip, Inc. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - - -### REQUIRED CONFIGURATION ### - -# TRELLO_API_KEY -# -# Visit https://trello.com/1/appkey/generate to generate -# an APPLICATION_KEY (needs to be logged into Trello) -TRELLO_API_KEY = "" - -# TRELLO_TOKEN -# -# To generate a Trello read access Token, visit (needs to be logged into Trello) -# https://trello.com/1/authorize?key=&name=Issue+Manager&expiration=never&response_type=token&scope=read -# -# Take care to replace with the appropriate value -TRELLO_TOKEN = "" - -# ZULIP_WEBHOOK_URL -# -# The webhook URL that Trello will query -ZULIP_WEBHOOK_URL = ""