Ejemplo n.º 1
0
    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)))
Ejemplo n.º 2
0
    def __init__(self, token, group, **kargs):
        super().__init__(**kargs)

        self._group = group
        self._token = GitHubToken(token)
        self._org = GitHubOrganization(self._token, self._group)

        self._status_provider = []
        for i in enumerate(self.StatusProvider):
            self._status_provider.append(self.StatusProvider[i[0]](
                self._group))
Ejemplo n.º 3
0
    def __init__(self, bot, name=None):
        super().__init__(bot, name)

        teams = dict()
        try:
            gh = github3.login(token=os.environ.get('GH_TOKEN'))
            assert gh is not None
        except AssertionError:
            self.log.error(
                'Cannot create github object, please check GH_TOKEN')
        else:
            self.GH3_ORG = gh.organization(self.GH_ORG_NAME)
            for team in self.GH3_ORG.teams():
                teams[team.name] = team

        self._teams = teams

        self.IGH = GitHub(GitHubToken(os.environ.get('GH_TOKEN')))
        self.IGL = GitLab(GitLabPrivateToken(os.environ.get('GL_TOKEN')))

        self.REPOS = dict()

        try:
            self.gh_repos = {
                repo.full_name.split('/')[-1]: repo
                for repo in filter(
                    lambda x: (x.full_name.split('/')[0] == self.GH_ORG_NAME),
                    self.IGH.write_repositories)
            }
        except RuntimeError:
            self.log.exception(
                'Something went wrong in fetching github repos.')
        else:
            self.REPOS.update(self.gh_repos)

        try:
            self.gl_repos = {
                repo.full_name.split('/')[-1]: repo
                for repo in filter(
                    lambda x: (x.full_name.split('/')[0] == self.GL_ORG_NAME),
                    self.IGL.write_repositories)
            }
        except RuntimeError:  # pragma: no cover, for logging
            self.log.exception(
                'Something went wrong in fetching gitlab repos.')
        else:
            self.REPOS.update(self.gl_repos)

        self.invited_users = set()
        self.hello_world_users = set()
Ejemplo n.º 4
0
 def newcomer_issue_check(user, iss):
     """
     True if:  Issue is not labeled `difficulty/newcomer` and
               user is not a newcomer.
     False if: A `difficulty/newcomer` issue is already assigned
               to the user.
     """
     if (self.is_newcomer_issue(iss)
             and self.is_team_member(user, 'newcomers')):
         search_query = 'user:coala assignee:{} ' \
                        'label:difficulty/newcomer'.format(user)
         result = GitHub.raw_search(
             GitHubToken(self.config['GH_TOKEN']), search_query)
         return not (sum(1 for _ in result) >= 1)
     else:
         return True
Ejemplo n.º 5
0
def get_ihoster(url):
    global _IGH, _IGL
    if url.resource == 'github.com':
        if not _IGH:
            # Allow unauthenticated requests
            try:
                token = get_api_key('GH')
            except Exception:
                token = None
            _IGH = GitHub(GitHubToken(token))
        return _IGH
    elif url.resource == 'gitlab.com':
        if not _IGL:
            # https://gitlab.com/gitmate/open-source/IGitt/issues/114
            _IGL = GitLab(GitLabPrivateToken(get_api_key('GL')))

        return _IGL
Ejemplo n.º 6
0
 def newcomer_issue_check(user, iss):
     """
     True if:  Issue is not labeled `difficulty/newcomer` and
               user is not a newcomer.
     False if: A `difficulty/newcomer` issue is already assigned
               to the user.
     """
     if (self.is_newcomer_issue(iss)
             and self.TEAMS[self.GH_ORG_NAME +
                            ' newcomers'].is_member(user)):
         search_query = 'user:coala assignee:{} ' \
                        'label:difficulty/newcomer'.format(user)
         result = GitHub.raw_search(
             GitHubToken(os.environ.get('GH_TOKEN')), search_query)
         return not (sum(1 for _ in result) >= 1)
     else:
         return True
Ejemplo n.º 7
0
    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_github(token):
  return GitHub(GitHubToken(token))