# Path: gg/builtins/github.py
# @cli.group()
# @click.option(
#     "-u",
#     "--github-url",
#     default=GITHUB_URL,
#     help=f"URL to GitHub instance (default: {GITHUB_URL})",
# )
# @pass_config
# def github(config, github_url):
#     """For setting up a GitHub API token."""
#     config.github_url = github_url
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):
# 
# Path: gg/state.py
# def load(configfile, branch_name):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:{branch_name}"
#     return read(configfile)[key]
# 
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def load_config(configfile, key):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:_config:{key}"
#     return read(configfile)[key]
# 
# 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 get_default_branch(repo, origin_name):
#     # TODO: Figure out how to do this with GitPython
#     res = subprocess.run(
#         f"git remote show {origin_name}".split(),
#         check=True,
#         capture_output=True,
#         cwd=repo.working_tree_dir,
#     )
#     for line in res.stdout.decode("utf-8").splitlines():
#         if line.strip().startswith("HEAD branch:"):
#             return line.replace("HEAD branch:", "").strip()
# 
#     raise NotImplementedError(f"No remote called {origin_name!r}")
# 
# def info_out(msg):
#     click.echo(msg)
# 
# def is_bugzilla(data):
#     if data.get("bugnumber") and data.get("url"):
#         return "bugzilla" in urlparse(data["url"]).netloc
#     return False
# 
# def is_github(data):
#     if data.get("bugnumber") and data.get("url"):
#         return "github" in urlparse(data["url"]).netloc
#     return False
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))


import os
import re
import time
import click
import git
from gg.builtins import github
from gg.main import cli, pass_config
from gg.state import load, read, load_config
from gg.utils import (
    error_out,
    get_default_branch,
    info_out,
    is_bugzilla,
    is_github,
    success_out,
)

    if untracked_files:
        ordered = sorted(untracked_files.items(), key=lambda x: x[1], reverse=True)
        info_out("NOTE! There are untracked files:")
        for path, age in ordered:
            if os.path.isdir(path):
                path = path + "/"
            print("\t", path.ljust(60), humanize_seconds(age), "old")

        # But only put up this input question if one the files is
        # younger than 12 hours.
        young_ones = [x for x in untracked_files.values() if x < 60 * 60 * 12]
        if young_ones:
            ignore = input("Ignore untracked files? [Y/n] ").lower().strip()
            if ignore.lower().strip() == "n":
                error_out(
                    "\n\tLeaving it up to you to figure out what to do "
                    "with those untracked files."
                )
                return 1
            print("")

    state = read(config.configfile)

    try:
        push_to_origin = load_config(config.configfile, "push_to_origin")
    except KeyError:
        push_to_origin = False

    try:

# Path: gg/builtins/github.py
# @cli.group()
# @click.option(
#     "-u",
#     "--github-url",
#     default=GITHUB_URL,
#     help=f"URL to GitHub instance (default: {GITHUB_URL})",
# )
# @pass_config
# def github(config, github_url):
#     """For setting up a GitHub API token."""
#     config.github_url = github_url
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):
# 
# Path: gg/state.py
# def load(configfile, branch_name):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:{branch_name}"
#     return read(configfile)[key]
# 
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def load_config(configfile, key):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:_config:{key}"
#     return read(configfile)[key]
# 
# 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 get_default_branch(repo, origin_name):
#     # TODO: Figure out how to do this with GitPython
#     res = subprocess.run(
#         f"git remote show {origin_name}".split(),
#         check=True,
#         capture_output=True,
#         cwd=repo.working_tree_dir,
#     )
#     for line in res.stdout.decode("utf-8").splitlines():
#         if line.strip().startswith("HEAD branch:"):
#             return line.replace("HEAD branch:", "").strip()
# 
#     raise NotImplementedError(f"No remote called {origin_name!r}")
# 
# def info_out(msg):
#     click.echo(msg)
# 
# def is_bugzilla(data):
#     if data.get("bugnumber") and data.get("url"):
#         return "bugzilla" in urlparse(data["url"]).netloc
#     return False
# 
# def is_github(data):
#     if data.get("bugnumber") and data.get("url"):
#         return "github" in urlparse(data["url"]).netloc
#     return False
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))


# Path: gg/builtins/commit/gg_commit.py
import os
import re
import time
import click
import git
from gg.builtins import github
from gg.main import cli, pass_config
from gg.state import load, read, load_config
from gg.utils import (
    error_out,
    get_default_branch,
    info_out,
    is_bugzilla,
    is_github,
    success_out,
)


    if untracked_files:
        ordered = sorted(untracked_files.items(), key=lambda x: x[1], reverse=True)
        info_out("NOTE! There are untracked files:")
        for path, age in ordered:
            if os.path.isdir(path):
                path = path + "/"
            print("\t", path.ljust(60), humanize_seconds(age), "old")

        # But only put up this input question if one the files is
        # younger than 12 hours.
        young_ones = [x for x in untracked_files.values() if x < 60 * 60 * 12]
        if young_ones:
            ignore = input("Ignore untracked files? [Y/n] ").lower().strip()
            if ignore.lower().strip() == "n":
                error_out(
                    "\n\tLeaving it up to you to figure out what to do "
                    "with those untracked files."
                )
                return 1
            print("")

    state = read(config.configfile)

    try:
        push_to_origin = load_config(config.configfile, "push_to_origin")
    except KeyError:
        push_to_origin = False

    try:

        fixes_message = load_config(config.configfile, "fixes_message")