当前位置: 首页>>代码示例>>Python>>正文


Python GitHub.iter_orgs方法代码示例

本文整理汇总了Python中github3.GitHub.iter_orgs方法的典型用法代码示例。如果您正苦于以下问题:Python GitHub.iter_orgs方法的具体用法?Python GitHub.iter_orgs怎么用?Python GitHub.iter_orgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github3.GitHub的用法示例。


在下文中一共展示了GitHub.iter_orgs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GitHubConnector

# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import iter_orgs [as 别名]
class GitHubConnector(object):

    def __init__(self):

        self.git_hub = GitHub(settings.GITHUB_USER, settings.GITHUB_PASS)
        self.orgs = list(self.git_hub.iter_orgs())

        # As of 10/3/2013, the default rate limit was 5000/hr.
        # Should your code loop infinitely, this exception will
        # leave enough requests to debug the problem without
        # having to wait an hour.
        if self.git_hub.ratelimit_remaining < 500:
            raise Exception('You have only 500 GitHub requests left for this hour')

    def get_issues_for_repo(self, repo_name=None, github_id=None, repo_tuple=None):
        repos = self.git_hub.iter_all_repos()
        for repo in repos:
            if repo_name and repo_name == repo.name:
                return list(repo.iter_issues())
            elif github_id and github_id == repo.id:
                return list(repo.iter_issues())
            elif repo_tuple and repo_tuple[1] == repo.name:
                return list(repo.iter_issues())

    def get_all_issues(self):
        issues = []
        for org in self.orgs:
            org_repos = org.iter_repos()
            for repo in org_repos:
                issues += list(repo.iter_issues(state='open'))
                issues += list(repo.iter_issues(state='closed'))
        return issues

    def get_repos_for_org(self, org_login=None, org_id=None):
        for org in self.orgs:
            org_json = org.to_json()
            if org_json["login"] == org_login or org_json["id"] == org_id:
                return list(org.iter_repos())

    def get_all_repos(self):
        repos = []
        for org in self.orgs:
            org_repos = org.iter_repos()
            for repo in org_repos:
                repos.append(repo)
        return repos
开发者ID:wbrefvem,项目名称:worklog,代码行数:48,代码来源:gh_connect.py

示例2: __init__

# 需要导入模块: from github3 import GitHub [as 别名]
# 或者: from github3.GitHub import iter_orgs [as 别名]
class Github:
    def __init__(self, _ask_credentials=None, _ask_2fa=None):
        self.last_error = None

        self._ask_credentials = _ask_credentials
        self._ask_2fa = _ask_2fa

        self.gh = GitHub(token=self._get_authorization_token())
        self.user = self.gh.user()

    def _get_authorization_token(self):
        if not config.has('github', 'token') or \
           not config.get('github', 'token'):
            if not self._ask_credentials:
                raise RuntimeError('Github Token is not set in the '
                                   'configuration and no function was set to '
                                   'ask for credentials')

            token = self._gen_authorization_token()
            config.set('github', 'token', token)
            config.save()

        return config.get('github', 'token')

    def _gen_authorization_token(self, counter=0, creds=None):
        """
        This function creates the authorization token for AerisCloud.
        If an existing token exists for this computer, it adds a #N counter
        next to the name.
        """
        if creds:
            user, pwd = creds['user'], creds['pwd']
        else:
            (user, pwd) = self._ask_credentials()

        note = 'AerisCloud on %s' % (node())
        if counter > 0:
            note += ' #%d' % counter

        try:
            auth = authorize(user, pwd, ['repo', 'read:org'], note=note,
                             two_factor_callback=self._ask_2fa)
            return auth.token
        except GitHubError as e:
            if not e.errors or e.errors[0]['code'] != 'already_exists':
                raise

            # token exists, increment counter
            counter += 1
            return self._gen_authorization_token(counter=counter,
                                                 creds={'user': user,
                                                        'pwd': pwd})

    def get_organizations(self):
        return [org for org in self.gh.iter_orgs()]

    def get_repo(self, name, fork=False):
        """
        Find a repository in the available ogranizations, if fork is set to
        True it will try forking it to the user's account
        """
        # check on the user
        repo = self.gh.repository(self.user.login, name)

        if repo:
            return repo, None

        if not config.has('github', 'organizations'):
            return False, None

        # then on configured organization
        organizations = config.get('github', 'organizations').split(',')

        for org in organizations:
            repo = self.gh.repository(org, name)
            if repo:
                break

        if not repo:
            return False, None

        if not fork:
            return repo, None

        return repo.create_fork(), repo
开发者ID:AerisCloud,项目名称:AerisCloud,代码行数:87,代码来源:github.py


注:本文中的github3.GitHub.iter_orgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。