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.
This commit is contained in:
parent
048fa79a7c
commit
1de6613825
|
@ -2,12 +2,22 @@
|
||||||
|
|
||||||
Usage :
|
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 API KEY
|
||||||
- The Trello TOKEN,
|
- The Trello TOKEN
|
||||||
- The Zulip webhook URL
|
- The Zulip webhook URL
|
||||||
|
- Trello board name
|
||||||
|
- Trello board ID
|
||||||
|
|
||||||
2. Execute the script :
|
2. Execute the script :
|
||||||
|
|
||||||
$ python zulip_trello.py <trello_board_name> <trello_board_id>
|
$ python zulip_trello.py --trello-board-name <trello_board_name> \
|
||||||
|
--trello-board-id <trello_board_id> \
|
||||||
|
--trello-api-key <trello_api_key> \
|
||||||
|
--trello-token <trello_token> \
|
||||||
|
--zulip-webhook-url <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).
|
||||||
|
|
|
@ -10,33 +10,6 @@ import sys
|
||||||
import argparse
|
import argparse
|
||||||
import requests
|
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:
|
def get_model_id(options: argparse.Namespace) -> str:
|
||||||
"""get_model_id
|
"""get_model_id
|
||||||
|
|
||||||
|
@ -53,8 +26,8 @@ def get_model_id(options: argparse.Namespace) -> str:
|
||||||
)
|
)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'key': configuration.TRELLO_API_KEY,
|
'key': options.trello_api_key,
|
||||||
'token': configuration.TRELLO_TOKEN,
|
'token': options.trello_token,
|
||||||
}
|
}
|
||||||
|
|
||||||
trello_response = requests.get(
|
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/'
|
trello_api_url = 'https://api.trello.com/1/webhooks/'
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'key': configuration.TRELLO_API_KEY,
|
'key': options.trello_api_key,
|
||||||
'token': configuration.TRELLO_TOKEN,
|
'token': options.trello_token,
|
||||||
'description': 'Webhook for Zulip integration (From Trello {} to Zulip)'.format(
|
'description': 'Webhook for Zulip integration (From Trello {} to Zulip)'.format(
|
||||||
options.trello_board_name,
|
options.trello_board_name,
|
||||||
),
|
),
|
||||||
'callbackURL': configuration.ZULIP_WEBHOOK_URL,
|
'callbackURL': options.zulip_webhook_url,
|
||||||
'idModel': id_model
|
'idModel': id_model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,11 +133,27 @@ def create_webhook(options: argparse.Namespace) -> None:
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('trello_board_name', help='The Trello board name.')
|
parser.add_argument('--trello-board-name',
|
||||||
parser.add_argument('trello_board_id', help='The Trello board short id.')
|
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()
|
options = parser.parse_args()
|
||||||
check_configuration()
|
|
||||||
create_webhook(options)
|
create_webhook(options)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -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=<TRELLO_API_KEY>&name=Issue+Manager&expiration=never&response_type=token&scope=read
|
|
||||||
#
|
|
||||||
# Take care to replace <TRELLO_API_KEY> with the appropriate value
|
|
||||||
TRELLO_TOKEN = ""
|
|
||||||
|
|
||||||
# ZULIP_WEBHOOK_URL
|
|
||||||
#
|
|
||||||
# The webhook URL that Trello will query
|
|
||||||
ZULIP_WEBHOOK_URL = ""
|
|
Loading…
Reference in a new issue