Пример #1
0
class GitHubHosterTest(IGittTestCase):
    def setUp(self):
        self.gh = GitHub(GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')))

    def test_master_repositories(self):
        self.assertEqual(
            sorted(map(lambda x: x.full_name, self.gh.master_repositories)), [
                'GitMateIO/gitmate-2', 'GitMateIO/gitmate-2-frontend',
                'gitmate-test-user/empty', 'gitmate-test-user/test'
            ])

    def test_owned_repositories(self):
        self.assertEqual(
            sorted(map(lambda x: x.full_name, self.gh.owned_repositories)),
            ['gitmate-test-user/empty', 'gitmate-test-user/test'])

    def test_write_repositories(self):
        self.assertEqual(
            sorted(map(lambda x: x.full_name, self.gh.write_repositories)), [
                'GitMateIO/IGitt', 'GitMateIO/gitmate-2',
                'GitMateIO/gitmate-2-frontend', 'gitmate-test-user/empty',
                'gitmate-test-user/test', 'sils/gitmate-test'
            ])

    def test_get_repo(self):
        self.assertEqual(
            self.gh.get_repo('gitmate-test-user/test').full_name,
            'gitmate-test-user/test')
Пример #2
0
class GitOrg():
    def __init__(self, name):
        logger = logging.getLogger(__name__ + '.__init__')
        self.name = name
        self.IGH = GitHub(GitHubToken(get_api_key('GH')))
        self.IGL = GitLab(GitLabPrivateToken(get_api_key('GL')))

        logger.info('loading org %s' % name)
        self.REPOS = dict()

        self.gh_repos = {
            repo.full_name.split('/')[-1]: repo
            for repo in filter(
                lambda x: (x.full_name.split('/')[0] == self.name),
                self.IGH.write_repositories)
        }
        self.REPOS.update(self.gh_repos)

        self.gl_repos = {
            repo.full_name.split('/')[-1]: repo
            for repo in filter(
                lambda x: (x.full_name.split('/')[0] == self.name),
                self.IGL.write_repositories)
        }
        self.REPOS.update(self.gl_repos)
        logger.info('loaded org %s with %d repositories' %
                    (name, len(self.REPOS)))

    def get_repo(self, repo_name):
        logger = logging.getLogger(__name__ + '.get_repo')
        if repo_name not in self.REPOS:
            full_name = '%s/%s' % (self.name, repo_name)
            logger.info('loading non-writable repo %s' % full_name)
            try:
                repo = self.IGH.get_repo(full_name)
                # Use `clone_url` to ensure the repository is usable
                repo.clone_url
                self.REPOS[repo_name] = repo
                logger.info('loaded non-writable GitHub repo %s' % full_name)

                return repo
            except Exception as e:
                logger.error('Unable to load GitHub repo %s: %s' %
                             (full_name, e))
            try:
                repo = self.IGL.get_repo(full_name)
                # Use `clone_url` to ensure the repository is usable
                repo.clone_url
                logger.info('loaded non-writable GitLab repo %s' % full_name)
                self.REPOS[repo_name] = repo
            except Exception as e:
                logger.error('Unable to load GitLab repo %s: %s' %
                             (full_name, e))

        return self.REPOS[repo_name]
Пример #3
0
class GitOrg():
    def __init__(self, name):
        self.name = name
        self.IGH = GitHub(GitHubToken(get_api_key('GH')))
        self.IGL = GitLab(GitLabPrivateToken(get_api_key('GL')))

        print('loading org %s' % name)
        self.REPOS = dict()

        self.gh_repos = {
            repo.full_name.split('/')[-1]: repo
            for repo in filter(
                lambda x: (x.full_name.split('/')[0] == self.name),
                self.IGH.write_repositories)
        }
        self.REPOS.update(self.gh_repos)

        self.gl_repos = {
            repo.full_name.split('/')[-1]: repo
            for repo in filter(
                lambda x: (x.full_name.split('/')[0] == self.name),
                self.IGL.write_repositories)
        }
        self.REPOS.update(self.gl_repos)
        print('loaded org %s' % name)

    def get_repo(self, repo_name):
        if repo_name not in self.REPOS:
            full_name = '%s/%s' % (self.name, repo_name)
            print('loading non-writable repo %s' % full_name)
            try:
                repo = self.IGH.get_repo(full_name)
                repo.identifier
                self.REPOS[repo_name] = repo
            except Exception:
                print('Unable to load GitHub repo %s' % full_name)
            try:
                repo = self.IGL.get_repo(full_name)
                repo.identifier
                self.REPOS[repo_name] = repo
            except Exception:
                print('Unable to load GitLab repo %s' % full_name)

        return self.REPOS[repo_name]