Skip to content

Commit

Permalink
Just... So much....
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarrarom committed Apr 23, 2021
1 parent 6276f72 commit 38da03e
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .get import get
from .update import update
from .create import create
from .config import config
from .jira_config import config
2 changes: 1 addition & 1 deletion create/comment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import requests
from get.issues import get_issues
from shared_functions import get_config
from jiractl_shared_functions import get_config


def get_issues_autocomp(ctx, args, incomplete):
Expand Down
2 changes: 1 addition & 1 deletion create/issue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import os
import requests
from shared_functions import get_config
from jiractl_shared_functions import get_config

@click.command()
@click.option('--summary', '-s', help="the summary of the issue to be created", prompt=True, required=True)
Expand Down
2 changes: 1 addition & 1 deletion get/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import json
import yaml
from shared_functions import get_config
from jiractl_shared_functions import get_config

from rich import print as rprint

Expand Down
2 changes: 1 addition & 1 deletion get/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml
import re
import os
from shared_functions import get_config
from jiractl_shared_functions import get_config

from rich import print as rprint
from tabulate import tabulate
Expand Down
2 changes: 1 addition & 1 deletion get/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import json
import yaml
from shared_functions import get_config
from jiractl_shared_functions import get_config

from rich import print as rprint
from tabulate import tabulate
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion config/remove.py → jira_config/remove.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from shared_functions import write_config_file, get_config
from jiractl_shared_functions import write_config_file, get_config

def get_keys(ctx, args, incomplete):
config = get_config()
Expand Down
2 changes: 1 addition & 1 deletion config/set.py → jira_config/set.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from shared_functions import get_config, write_config_file
from jiractl_shared_functions import get_config, write_config_file

@click.command(name='set')
@click.option('--key', '-k', help="The key to be set in this command", required=True, prompt=True)
Expand Down
2 changes: 1 addition & 1 deletion config/show.py → jira_config/show.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click
import rich
from shared_functions import get_config
from jiractl_shared_functions import get_config

@click.command(name="show")
@click.argument('key', required=False)
Expand Down
20 changes: 7 additions & 13 deletions jiractl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import get
import update
import create
import config
import jira_config

from shared_functions import write_config_file, get_config
from jiractl_shared_functions import write_config_file, get_config

@click.group()
@click.pass_context
Expand All @@ -20,9 +20,9 @@ def jira(ctx):
if ctx.invoked_subcommand != 'login':
try:
config = get_config()
config['api_endpoint'] = config['endpoint'] + "/rest/api"
except KeyError:
rich.print("You should authenticate with 'jira login' first!")
config['api_endpoint'] = config['endpoint'] + "/rest/api"
[os.environ.setdefault(key, config[key]) for key in config if key not in ['app_dir', 'endpoint', 'config_file_path', 'authenticated', 'headers']]


Expand All @@ -45,16 +45,10 @@ def login(ctx, apikey, endpoint):


jira.add_command(login)

def add_all_commands(group):
for client in [method_name for method_name in dir(group)
if callable(getattr(group, method_name))]:
jira.add_command(getattr(group, client))

groups = [get, update, create, config]

for group in groups:
add_all_commands(group)
jira.add_command(jira_config.config)
jira.add_command(get.get)
jira.add_command(update.update)
jira.add_command(create.create)

if __name__ == '__main__':
jira()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
import os
import json

APP_NAME = '.jiractl'
CONFIG_FILE = 'config.json'

def get_headers(config):
return {"Authorization": f"Bearer {config.get('apikey')}",
"Content-Type": "application/json",
"Accept": "application/json"}

def get_config():
app_dir = click.get_app_dir(APP_NAME)
config_file_path = os.path.join(app_dir, CONFIG_FILE)
app_name = '.jiractl'
config_file = 'config.json'
app_dir = click.get_app_dir(app_name)
config_file_path = os.path.join(app_dir, config_file)
config = read_configfile(config_file_path)
config['authenticated'] = True
config['headers'] = get_headers(config)
Expand All @@ -38,11 +37,13 @@ def read_configfile(config_file_path: str) -> dict:
return config_dict

def create_default_configfile():
app_dir = click.get_app_dir(APP_NAME)
app_name = '.jiractl'
config_file = 'config.json'
app_dir = click.get_app_dir(app_name)
if not os.path.isdir(app_dir):
os.mkdir(app_dir)
config = {}
write_config_file(os.path.join(app_dir, CONFIG_FILE), config)
write_config_file(os.path.join(app_dir, config_file), config)

def write_config_file(file_path, data):
if data.get('headers'): del data['headers']
Expand Down
5 changes: 5 additions & 0 deletions jiractl_shared_functions/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from click import BadParameter

class Sorry(BadParameter):
def __init__(self, message):
super().__init__('Oh hey there! Sorry bud, but ' + message + '!')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='fancy-jira',
version='0.0.5',
version='0.0.6',
author='Gui Martins',
url='https://fancywhale.ca/',
author_email='[email protected]',
Expand Down
3 changes: 0 additions & 3 deletions shared_functions/exceptions.py

This file was deleted.

2 changes: 1 addition & 1 deletion update/issue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click
import requests
from shared_functions import get_config
from jiractl_shared_functions import get_config


@click.command()
Expand Down

0 comments on commit 38da03e

Please sign in to comment.