示例#1
0
 def search_authors(self, query=""):
     ret_limit = 100
     c = Commits(index.Connector())
     ret = c.es.search(index=c.index,
                       q=query,
                       df="author_name",
                       size=10000,
                       default_operator="AND",
                       _source_includes=["author_name", "author_email"])
     ret = ret['hits']['hits']
     if not len(ret):
         return {}
     idents = Contributors()
     authors = dict([(d['_source']['author_email'],
                      d['_source']['author_name']) for d in ret])
     result = {}
     _idents = idents.get_idents_by_emails(list(authors.keys())[:ret_limit])
     for iid, ident in _idents.items():
         email = ident['default-email']
         name = ident['name'] or authors[email]
         result[utils.encrypt(xorkey, iid)] = {
             'name': name,
             'gravatar':
             hashlib.md5(email.encode(errors='ignore')).hexdigest()
         }
     result = OrderedDict(
         sorted(list(result.items()), key=lambda t: t[1]['name']))
     return result
示例#2
0
    def contributor(self, cid=None):
        if not cid:
            abort(404,
                  detail="No contributor specified")

        c = Commits(index.Connector())
        idents = Contributors()

        try:
            cid = utils.decrypt(xorkey, cid)
        except Exception:
            abort(404,
                  detail="The cid is incorrectly formated")

        _, ident = idents.get_ident_by_id(cid)
        if not ident:
            # No ident has been declared for that contributor
            ident = list(idents.get_idents_by_emails(cid).values())[0]
        mails = ident['emails']
        name = ident['name']
        if not name:
            raw_names = c.get_commits_author_name_by_emails([cid])
            if cid not in raw_names:
                # TODO: get_commits_author_name_by_emails must
                # support look by committer email too
                name = 'Unnamed'
            else:
                name = raw_names[cid]

        infos = {}
        infos['name'] = name
        infos['mails_amount'] = len(mails)
        infos['gravatar'] = hashlib.md5(
            ident['default-email'].encode(errors='ignore')).hexdigest()
        return infos
示例#3
0
 def search_authors(self, query=""):
     ret_limit = 100
     c = Commits(index.Connector())
     ret = c.es.search(
         index=c.index, doc_type=c.dbname,
         q=query, df="author_name", size=10000,
         default_operator="AND",
         _source_include=["author_name", "author_email"])
     ret = ret['hits']['hits']
     if not len(ret):
         return {}
     idents = Contributors()
     authors = dict([(d['_source']['author_email'],
                      d['_source']['author_name']) for d in ret])
     result = {}
     _idents = idents.get_idents_by_emails(list(authors.keys())[:ret_limit])
     for iid, ident in _idents.items():
         email = ident['default-email']
         name = ident['name'] or authors[email]
         result[utils.encrypt(xorkey, iid)] = {
             'name': name,
             'gravatar': hashlib.md5(
                 email.encode(errors='ignore')).hexdigest()}
     result = OrderedDict(
         sorted(list(result.items()), key=lambda t: t[1]['name']))
     return result
示例#4
0
    def commits(self, pid=None, tid=None, cid=None, gid=None,
                start=0, limit=10,
                dfrom=None, dto=None, inc_merge_commit=None,
                inc_repos=None, metadata=None, exc_groups=None,
                inc_groups=None):

        c = Commits(index.Connector())
        projects_index = Projects()
        idents = Contributors()

        query_kwargs = utils.resolv_filters(
            projects_index, idents, pid, tid, cid, gid,
            dfrom, dto, inc_repos, inc_merge_commit,
            metadata, exc_groups, inc_groups)
        query_kwargs.update(
            {'start': start, 'limit': limit})

        resp = c.get_commits(**query_kwargs)

        for cmt in resp[2]:
            # Get extra metadata keys
            extra = set(cmt.keys()) - set(PROPERTIES.keys())
            cmt['metadata'] = list(extra)
            cmt['repos'] = [r for r in cmt['repos']
                            if not r.startswith('meta_ref: ')]
            # Compute link to access commit diff based on the
            # URL template provided in projects.yaml
            cmt['gitwebs'] = [
                projects_index.get_gitweb_link(r) %
                {'sha': cmt['sha']} for r in cmt['repos']]
            cmt['projects'] = utils.get_projects_from_references(
                projects_index, cmt['repos'])
            # Also remove the URI part
            cmt['repos'] = [":".join(p.split(':')[-2:]) for
                            p in cmt['repos']]
            # Request the ident index to fetch author/committer name/email
            for elm in ('author', 'committer'):
                ident = list(idents.get_idents_by_emails(
                    cmt['%s_email' % elm]).values())[0]
                cmt['%s_email' % elm] = ident['default-email']
                if ident['name']:
                    cmt['%s_name' % elm] = ident['name']
            # Convert the TTL to something human readable
            cmt['ttl'] = str((datetime.fromtimestamp(cmt['ttl']) -
                              datetime.fromtimestamp(0)))
            cmt['author_gravatar'] = \
                hashlib.md5(cmt['author_email'].encode(
                    errors='ignore')).hexdigest()
            cmt['committer_gravatar'] = \
                hashlib.md5(cmt['committer_email'].encode(
                    errors='ignore')).hexdigest()
            if len(cmt['commit_msg']) > 80:
                cmt['commit_msg'] = cmt['commit_msg'][0:76] + '...'
            # Add cid and ccid
            cmt['cid'] = utils.encrypt(xorkey, cmt['author_email'])
            cmt['ccid'] = utils.encrypt(xorkey, cmt['committer_email'])
            # Remove email details
            del cmt['author_email']
            del cmt['committer_email']
        return resp
示例#5
0
    def authors(self, pid=None, tid=None, cid=None, gid=None,
                dfrom=None, dto=None, inc_merge_commit=None,
                inc_repos=None, metadata=None, exc_groups=None,
                inc_groups=None):

        projects_index = Projects()
        idents = Contributors()

        query_kwargs = utils.resolv_filters(
            projects_index, idents, pid, tid, cid, gid,
            dfrom, dto, inc_repos, inc_merge_commit,
            metadata, exc_groups, inc_groups)

        c = Commits(index.Connector())
        if not c.get_commits_amount(**query_kwargs):
            return []
        ret = c.get_authors_histo(**query_kwargs)[1]
        for bucket in ret:
            _idents = idents.get_idents_by_emails(bucket['authors_email'])
            bucket['value'] = len(_idents)
            bucket['date'] = bucket['key_as_string']
            del bucket['authors_email']
            del bucket['doc_count']
            del bucket['key_as_string']
            del bucket['key']

        return ret
示例#6
0
    def contributor(self, cid=None):
        if not cid:
            abort(404, detail="No contributor specified")

        c = Commits(index.Connector())
        idents = Contributors()

        try:
            cid = utils.decrypt(xorkey, cid)
        except Exception:
            abort(404, detail="The cid is incorrectly formated")

        _, ident = idents.get_ident_by_id(cid)
        if not ident:
            # No ident has been declared for that contributor
            ident = list(idents.get_idents_by_emails(cid).values())[0]
        mails = ident['emails']
        name = ident['name']
        if not name:
            raw_names = c.get_commits_author_name_by_emails([cid])
            if cid not in raw_names:
                # TODO: get_commits_author_name_by_emails must
                # support look by committer email too
                name = 'Unnamed'
            else:
                name = raw_names[cid]

        infos = {}
        infos['name'] = name
        infos['mails_amount'] = len(mails)
        infos['gravatar'] = hashlib.md5(
            ident['default-email'].encode(errors='ignore')).hexdigest()
        return infos
示例#7
0
    def authors(self,
                pid=None,
                tid=None,
                cid=None,
                gid=None,
                dfrom=None,
                dto=None,
                inc_merge_commit=None,
                inc_repos=None,
                metadata=None,
                exc_groups=None,
                inc_groups=None):

        projects_index = Projects()
        idents = Contributors()

        query_kwargs = utils.resolv_filters(projects_index, idents, pid, tid,
                                            cid, gid, dfrom, dto, inc_repos,
                                            inc_merge_commit, metadata,
                                            exc_groups, inc_groups)

        c = Commits(index.Connector())
        if not c.get_commits_amount(**query_kwargs):
            return []
        ret = c.get_authors_histo(**query_kwargs)[1]
        for bucket in ret:
            _idents = idents.get_idents_by_emails(bucket['authors_email'])
            bucket['value'] = len(_idents)
            bucket['date'] = bucket['key_as_string']
            del bucket['authors_email']
            del bucket['doc_count']
            del bucket['key_as_string']
            del bucket['key']

        return ret
示例#8
0
    def index(self, prefix=None, nameonly='false', withstats='false'):
        ci = Commits(index.Connector())
        contributors_index = Contributors()
        groups = contributors_index.get_groups()
        if nameonly == 'true':
            ret = dict([(k, None) for k in groups.keys()])
            if prefix:
                ret = dict([(k, None) for k in ret.keys() if
                            k.lower().startswith(prefix)])
            return ret
        ret_groups = {}
        for group, data in groups.items():
            if prefix and not group.lower().startswith(prefix.lower()):
                continue
            rg = {'members': {},
                  'description': data['description'],
                  'domains': data.get('domains', [])}
            emails = data['emails'].keys()
            members = contributors_index.get_idents_by_emails(emails)
            for id, member in members.items():
                member['gravatar'] = hashlib.md5(
                    member['default-email']).hexdigest()
                # TODO(fbo): bounces should be a list of bounce
                # Let's deactivate that for now
                # member['bounces'] = bounces
                del member['emails']
                if not member['name']:
                    # Try to find it among commits
                    suggested = ci.get_commits_author_name_by_emails(
                        [member['default-email']])
                    name = suggested.get(member['default-email'],
                                         'Unknown name')
                    member['name'] = name
                del member['default-email']
                rg['members'][utils.encrypt(xorkey, id)] = member

            if withstats == 'true':
                # TODO(fbo): This endpoint needs to handle some filters like
                # dates bounces to return more accurate stats

                # Fetch the number of projects and repos contributed to
                p_filter = {}
                query_kwargs = {
                    'mails': data['emails'],
                    'merge_commit': False,
                    'repos': p_filter,
                }
                projects = Projects()
                tops_ctl = tops.TopProjectsController()
                top_projects = tops_ctl.gbycommits(
                    ci, projects, query_kwargs, False)
                top_repos = tops_ctl.gbycommits(
                    ci, projects, query_kwargs, True)
                rg['projects_amount'] = len(top_projects)
                rg['repos_amount'] = len(top_repos)

            ret_groups[group] = rg

        return ret_groups
示例#9
0
    def index(self, prefix=None, nameonly='false', withstats='false',
              pid=None, dfrom=None, dto=None, inc_merge_commit=None):
        ci = Commits(index.Connector())
        contributors_index = Contributors()
        groups = contributors_index.get_groups()
        if withstats == 'true':
            projects_index = Projects()
        if nameonly == 'true':
            ret = dict([(k, None) for k in groups.keys()])
            if prefix:
                ret = dict([(k, None) for k in ret.keys() if
                            k.lower().startswith(prefix)])
            return ret
        ret_groups = {}
        for group, data in groups.items():
            if prefix and not group.lower().startswith(prefix.lower()):
                continue
            rg = {'members': {},
                  'description': data.get('description', ''),
                  'domains': data.get('domains', [])}
            emails = list(data['emails'].keys())
            members = contributors_index.get_idents_by_emails(emails)
            for id, member in members.items():
                member['gravatar'] = hashlib.md5(
                    member['default-email'].encode(
                        errors='ignore')).hexdigest()
                # TODO(fbo): bounces should be a list of bounce
                # Let's deactivate that for now
                # member['bounces'] = bounces
                del member['emails']
                if not member['name']:
                    # Try to find it among commits
                    suggested = ci.get_commits_author_name_by_emails(
                        [member['default-email']])
                    name = suggested.get(member['default-email'],
                                         'Unnamed')
                    member['name'] = name
                del member['default-email']
                rg['members'][utils.encrypt(xorkey, id)] = member

            if withstats == 'true':
                # Fetch the number of projects and repos contributed to
                query_kwargs = utils.resolv_filters(
                    projects_index, contributors_index, pid, None, None, group,
                    dfrom, dto, None, inc_merge_commit, None, None, None)

                repos = [r for r in ci.get_repos(**query_kwargs)[1]
                         if not r.startswith('meta_ref: ')]
                projects = utils.get_projects_from_references(
                    projects_index, repos)
                rg['repos_amount'] = len(repos)
                rg['projects_amount'] = len(projects)

            ret_groups[group] = rg

        return ret_groups
示例#10
0
    def contributor(self, cid=None):
        if not cid:
            abort(404,
                  detail="No contributor specified")

        try:
            cid = utils.decrypt(xorkey, cid)
        except Exception:
            abort(404,
                  detail="The cid is incorrectly formated")
        c = Commits(index.Connector())
        idents = Contributors()
        projects = Projects()
        _, ident = idents.get_ident_by_id(cid)
        if not ident:
            # No ident has been declared for that contributor
            ident = idents.get_idents_by_emails(cid).values()[0]
        mails = ident['emails']
        name = ident['name']
        if not name:
            raw_names = c.get_commits_author_name_by_emails([cid])
            if cid not in raw_names:
                # TODO: get_commits_author_name_by_emails must
                # support look by committer email too
                name = 'Unnamed'
            else:
                name = raw_names[cid]

        p_filter = {}
        query_kwargs = {
            'mails': mails,
            'merge_commit': False,
            'repos': p_filter,
        }

        tops_ctl = tops.TopProjectsController()
        top_projects = tops_ctl.gbycommits(c, projects, query_kwargs, False)
        top_repos = tops_ctl.gbycommits(c, projects, query_kwargs, True)

        infos = {}
        infos['name'] = name
        infos['mails_amount'] = len(mails)
        infos['projects_amount'] = len(top_projects)
        infos['repos_amount'] = len(top_repos)
        infos['gravatar'] = hashlib.md5(ident['default-email']).hexdigest()
        return infos
示例#11
0
    def index(self,
              prefix=None,
              nameonly='false',
              withstats='false',
              pid=None,
              dfrom=None,
              dto=None,
              inc_merge_commit=None):
        ci = Commits(index.Connector())
        contributors_index = Contributors()
        groups = contributors_index.get_groups()
        if withstats == 'true':
            projects_index = Projects()
        if nameonly == 'true':
            ret = dict([(k, None) for k in groups.keys()])
            if prefix:
                ret = dict([(k, None) for k in ret.keys()
                            if k.lower().startswith(prefix)])
            return ret
        ret_groups = {}
        for group, data in groups.items():
            if prefix and not group.lower().startswith(prefix.lower()):
                continue
            rg = {
                'members': {},
                'description': data.get('description', ''),
                'domains': data.get('domains', [])
            }
            emails = list(data['emails'].keys())
            members = contributors_index.get_idents_by_emails(emails)
            for id, member in members.items():
                member['gravatar'] = hashlib.md5(
                    member['default-email'].encode(
                        errors='ignore')).hexdigest()
                # TODO(fbo): bounces should be a list of bounce
                # Let's deactivate that for now
                # member['bounces'] = bounces
                del member['emails']
                if not member['name']:
                    # Try to find it among commits
                    suggested = ci.get_commits_author_name_by_emails(
                        [member['default-email']])
                    name = suggested.get(member['default-email'], 'Unnamed')
                    member['name'] = name
                del member['default-email']
                rg['members'][utils.encrypt(xorkey, id)] = member

            if withstats == 'true':
                # Fetch the number of projects and repos contributed to
                query_kwargs = utils.resolv_filters(
                    projects_index, contributors_index, pid, None, None, group,
                    dfrom, dto, None, inc_merge_commit, None, None, None)

                repos = [
                    r for r in ci.get_repos(**query_kwargs)[1]
                    if not r.startswith('meta_ref: ')
                ]
                projects = utils.get_projects_from_references(
                    projects_index, repos)
                rg['repos_amount'] = len(repos)
                rg['projects_amount'] = len(projects)

            ret_groups[group] = rg

        return ret_groups