# Path: gg/main.py
# class Config:
#     def __init__(self):
#         self.verbose = False  # default
#         self.configfile = DEFAULT_CONFIGFILE
#         try:
#             self.repo = get_repo()
#         except git.InvalidGitRepositoryError as exception:
#             error_out(f"{exception.args[0]} is not a git repository")
# 
# 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/testing.py
# class Response:
#     def __init__(self, content, status_code=200):
#         self.content = content
#         self.status_code = status_code
# 
#     def json(self):
#         return self.content


import json
from click.testing import CliRunner
from gg.main import Config
from gg.builtins import github
from gg.testing import Response
    config = Config()
    config.configfile = temp_configfile
    # config.bugzilla_url = 'https://bugs.example.com'

    title, url = github.get_title(config, "peterbe", "gg", 1)
    assert title == "This is the title"
    assert url == "https://github.com/peterbe/gg/issues/1"


def test_find_pull_requests(temp_configfile, mocker):
    rget = mocker.patch("requests.get")
    getpass = mocker.patch("getpass.getpass")
    getpass.return_value = "somelongapitokenhere"

    with open(temp_configfile, "w") as f:
        saved = {
            "GITHUB": {
                "token": "somelongapitokenhere",
                "login": "peterbe",
                "github_url": "https://enterprise.github.com",
            }
        }
        json.dump(saved, f)

    def mocked_get(url, params, headers):
        assert url == "https://api.github.com/repos/myorg/myrepo/pulls"
        assert headers["Authorization"] == "token somelongapitokenhere"
        return Response([])

    rget.side_effect = mocked_get

# Path: gg/main.py
# class Config:
#     def __init__(self):
#         self.verbose = False  # default
#         self.configfile = DEFAULT_CONFIGFILE
#         try:
#             self.repo = get_repo()
#         except git.InvalidGitRepositoryError as exception:
#             error_out(f"{exception.args[0]} is not a git repository")
# 
# 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/testing.py
# class Response:
#     def __init__(self, content, status_code=200):
#         self.content = content
#         self.status_code = status_code
# 
#     def json(self):
#         return self.content


# Path: tests/test_github.py
import json
from click.testing import CliRunner
from gg.main import Config
from gg.builtins import github
from gg.testing import Response

    config = Config()
    config.configfile = temp_configfile
    # config.bugzilla_url = 'https://bugs.example.com'

    title, url = github.get_title(config, "peterbe", "gg", 1)
    assert title == "This is the title"
    assert url == "https://github.com/peterbe/gg/issues/1"


def test_find_pull_requests(temp_configfile, mocker):
    rget = mocker.patch("requests.get")
    getpass = mocker.patch("getpass.getpass")
    getpass.return_value = "somelongapitokenhere"

    with open(temp_configfile, "w") as f:
        saved = {
            "GITHUB": {
                "token": "somelongapitokenhere",
                "login": "peterbe",
                "github_url": "https://enterprise.github.com",
            }
        }
        json.dump(saved, f)

    def mocked_get(url, params, headers):
        assert url == "https://api.github.com/repos/myorg/myrepo/pulls"
        assert headers["Authorization"] == "token somelongapitokenhere"
        return Response([])

    rget.side_effect = mocked_get

    config = Config()