From 1de661382523105df85aa3a82010d33d1b48bf06 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Fri, 14 Sep 2018 17:24:40 -0230 Subject: [PATCH] integrations/trello: Stop using config files in the Trello script. A few users have complained about how hard it is to find the Trello script on their systems after installing the `zulip` package. One way to solve this issue is to make the Trello script a part of the exported console scripts in the zulip package, which would mean that the user would not have to navigate to a particular directory in order to find the script, but could run it from a terminal directly. However, to make this happen, we need to minimize the script's reliance on external configuration files, because we don't want the user to have to figure out where the config file lives. --- zulip/integrations/trello/README.md | 18 ++++-- zulip/integrations/trello/zulip_trello.py | 59 ++++++++----------- .../trello/zulip_trello_config.py | 43 -------------- 3 files changed, 38 insertions(+), 82 deletions(-) delete mode 100644 zulip/integrations/trello/zulip_trello_config.py 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 = ""