# Path: ghtools/exceptions.py
# class GithubError(Exception):
#     pass
# 
# Path: ghtools/identifier.py
# class Identifier(_Identifier):
#     """
# 
#     A simple identifier of an object in the GitHub API, usually created from a
#     string passed in on the command line.
# 
#     Users can reference a repository on a specific GitHub using the form::
# 
#         <github_name>:<org_name>/<repo_name>
# 
#     Where ``github_name`` is optional (defaulting to 'public').
# 
#     The repository can also be omitted in order to refer to an Organisation::
# 
#         <github_name>:<org_name>
# 
#     Again, ``github_name`` is optional.
# 
#     """
# 
#     @classmethod
#     def from_string(cls, identstring):
# 
#         parts = identstring.split(':', 1)
# 
#         if len(parts) == 1:
#             github = DEFAULT_GITHUB
#             remainder = parts[0]
#         else:
#             github, remainder = parts
# 
#         parts = remainder.split('/', 1)
# 
#         if len(parts) == 1:
#             org = parts[0]
#             repo = None
#         else:
#             org, repo = parts
# 
#         return Identifier(github, org, repo)
# 
#     def __str__(self):
#         out = ''
#         if self.github != DEFAULT_GITHUB:
#             out += self.github + ':'
#         out += self.org
#         if self.repo is not None:
#             out += '/{0}'.format(self.repo)
#         return out
# 
# Path: ghtools/util.py
# def make_client(identifier):
#     """
#     Make a GithubAPIClient suitable for interacting with the passed identifier
#     """
# 
#     return GithubAPIClient(nickname=identifier.github)


import itertools
import logging
from ghtools.exceptions import GithubError
from ghtools.identifier import Identifier
from ghtools.util import make_client


log = logging.getLogger(__name__)


class Repo(object):

    def __init__(self, repo, client=None):
        self._ident = Identifier.from_string(repo)

        if self._ident.repo is None:
            raise GithubError("Invalid repo string '{0}'".format(repo))

        self.org = self._ident.org
        self.repo = self._ident.repo
        self.client = client or make_client(self._ident)

    @property
    def ssh_url(self):
        res = self.client.get('/repos/{0}'.format(self.org_repo))
        return res.json()['ssh_url']

    @property
    def wiki_ssh_url(self):
        ssh_url = self.ssh_url
        if not ssh_url.endswith('.git'):

# Path: ghtools/exceptions.py
# class GithubError(Exception):
#     pass
# 
# Path: ghtools/identifier.py
# class Identifier(_Identifier):
#     """
# 
#     A simple identifier of an object in the GitHub API, usually created from a
#     string passed in on the command line.
# 
#     Users can reference a repository on a specific GitHub using the form::
# 
#         <github_name>:<org_name>/<repo_name>
# 
#     Where ``github_name`` is optional (defaulting to 'public').
# 
#     The repository can also be omitted in order to refer to an Organisation::
# 
#         <github_name>:<org_name>
# 
#     Again, ``github_name`` is optional.
# 
#     """
# 
#     @classmethod
#     def from_string(cls, identstring):
# 
#         parts = identstring.split(':', 1)
# 
#         if len(parts) == 1:
#             github = DEFAULT_GITHUB
#             remainder = parts[0]
#         else:
#             github, remainder = parts
# 
#         parts = remainder.split('/', 1)
# 
#         if len(parts) == 1:
#             org = parts[0]
#             repo = None
#         else:
#             org, repo = parts
# 
#         return Identifier(github, org, repo)
# 
#     def __str__(self):
#         out = ''
#         if self.github != DEFAULT_GITHUB:
#             out += self.github + ':'
#         out += self.org
#         if self.repo is not None:
#             out += '/{0}'.format(self.repo)
#         return out
# 
# Path: ghtools/util.py
# def make_client(identifier):
#     """
#     Make a GithubAPIClient suitable for interacting with the passed identifier
#     """
# 
#     return GithubAPIClient(nickname=identifier.github)


# Path: ghtools/github/repo.py
import itertools
import logging
from ghtools.exceptions import GithubError
from ghtools.identifier import Identifier
from ghtools.util import make_client



log = logging.getLogger(__name__)


class Repo(object):

    def __init__(self, repo, client=None):
        self._ident = Identifier.from_string(repo)

        if self._ident.repo is None:
            raise GithubError("Invalid repo string '{0}'".format(repo))

        self.org = self._ident.org
        self.repo = self._ident.repo
        self.client = client or make_client(self._ident)

    @property
    def ssh_url(self):
        res = self.client.get('/repos/{0}'.format(self.org_repo))
        return res.json()['ssh_url']

    @property
    def wiki_ssh_url(self):
        ssh_url = self.ssh_url
        if not ssh_url.endswith('.git'):

            raise GithubError("ssh_url doesn't end with '.git', bailing!")