# Path: gg/utils.py
# def error_out(msg, raise_abort=True):
#     click.echo(click.style(msg, fg="red"))
#     if raise_abort:
#         raise click.Abort
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))
# 
# def info_out(msg):
#     click.echo(msg)
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def update(configfile, data):
#     state = read(configfile)
#     state.update(data)
#     write(configfile, state)
# 
# def remove(configfile, key):
#     state = read(configfile)
#     del state[key]
#     write(configfile, state)
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):


import json
import getpass
import urllib.parse
import click
import requests
from gg.utils import error_out, success_out, info_out
from gg.state import read, update, remove
from gg.main import cli, pass_config
    if credentials:
        # cool! let's use that
        base_url = credentials["bugzilla_url"]
        params["api_key"] = credentials["api_key"]

    url = urllib.parse.urljoin(base_url, "/rest/bug/")
    assert url.startswith("https://"), url
    response = requests.get(url, params=params)
    response.raise_for_status()
    if response.status_code == 200:
        data = response.json()
        bug = data["bugs"][0]

        bug_url = urllib.parse.urljoin(base_url, f"/show_bug.cgi?id={bug['id']}")
        return bug["summary"], bug_url
    return None, None


@bugzilla.command()
@click.option(
    "-b", "--bugnumber", type=int, help="Optionally test fetching a specific bug"
)
@pass_config
def test(config, bugnumber):
    """Test your saved Bugzilla API Key."""
    state = read(config.configfile)
    credentials = state.get("BUGZILLA")
    if not credentials:
        error_out("No API Key saved. Run: gg bugzilla login")
    if config.verbose:

# Path: gg/utils.py
# def error_out(msg, raise_abort=True):
#     click.echo(click.style(msg, fg="red"))
#     if raise_abort:
#         raise click.Abort
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))
# 
# def info_out(msg):
#     click.echo(msg)
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def update(configfile, data):
#     state = read(configfile)
#     state.update(data)
#     write(configfile, state)
# 
# def remove(configfile, key):
#     state = read(configfile)
#     del state[key]
#     write(configfile, state)
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):


# Path: gg/builtins/bugzilla.py
import json
import getpass
import urllib.parse
import click
import requests
from gg.utils import error_out, success_out, info_out
from gg.state import read, update, remove
from gg.main import cli, pass_config

    if credentials:
        # cool! let's use that
        base_url = credentials["bugzilla_url"]
        params["api_key"] = credentials["api_key"]

    url = urllib.parse.urljoin(base_url, "/rest/bug/")
    assert url.startswith("https://"), url
    response = requests.get(url, params=params)
    response.raise_for_status()
    if response.status_code == 200:
        data = response.json()
        bug = data["bugs"][0]

        bug_url = urllib.parse.urljoin(base_url, f"/show_bug.cgi?id={bug['id']}")
        return bug["summary"], bug_url
    return None, None


@bugzilla.command()
@click.option(
    "-b", "--bugnumber", type=int, help="Optionally test fetching a specific bug"
)
@pass_config
def test(config, bugnumber):
    """Test your saved Bugzilla API Key."""
    state = read(config.configfile)
    credentials = state.get("BUGZILLA")
    if not credentials:
        error_out("No API Key saved. Run: gg bugzilla login")
    if config.verbose:

        info_out(f"Using: {credentials['bugzilla_url']}")