Exemple #1
0
    def test_format_text_split_long_link(self):
        original = ('https://blueprints.launchpad.net/stackalytics/+spec/'
                    'stackalytics-core')
        expected = ('https://​blueprints.launchpad.net/​'
                    'stackalytics/​+spec/​stackalytics-core')

        self.assertEqual(expected, utils.format_text(original))
Exemple #2
0
def make_commit_message(record):
    s = record['message']
    module = record['module']
    # NOTE(aostapenko) Keeping default value here not to brake links
    # with existing storage data
    gerrit_hostname = record.get('gerrit_hostname', 'review.opendev.org')

    s = utils.format_text(s)

    # insert links
    s = re.sub(
        re.compile('(blueprint\s+)([\w-]+)', flags=re.IGNORECASE),
        r'\1<a href="https://blueprints.launchpad.net/' + module +
        r'/+spec/\2" class="ext_link">\2</a>', s)
    s = re.sub(
        re.compile('(bug[\s#:]*)([\d]{5,7})', flags=re.IGNORECASE),
        r'\1<a href="https://bugs.launchpad.net/bugs/\2" '
        r'class="ext_link">\2</a>', s)
    # NOTE(aostapenko) Setting http here as it's common practice to redirect
    # http -> https, but not vice versa
    s = re.sub(
        r'\s+(I[0-9a-f]{40})',
        r' <a href="http://%s/#/q/\1" ' % gerrit_hostname +
        r'class="ext_link">\1</a>', s)

    s = utils.unwrap_text(s)
    return s
    def test_format_text_split_long_link(self):
        original = ('https://blueprints.launchpad.net/stackalytics/+spec/'
                    'stackalytics-core')
        expected = ('https://&#8203;blueprints.launchpad.net/&#8203;'
                    'stackalytics/&#8203;+spec/&#8203;stackalytics-core')

        self.assertEqual(expected, utils.format_text(original))
Exemple #4
0
def extend_record(record):
    record = vault.extend_record(record)
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        review = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        patch = vault.get_memory_storage().get_record_by_primary_key(
            utils.get_patch_id(record['review_id'], record['patch']))
        if not review or not patch:
            return None

        _extend_by_parent_info(record, review, 'parent_')
        _extend_by_parent_info(record, patch, 'patch_')
    elif record['record_type'] == 'patch':
        review = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        _extend_by_parent_info(record, review, 'parent_')
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])
    elif record['record_type'] in ['bugr', 'bugf']:
        record['number'] = record['web_link'].split('/')[-1]
        record['title'] = filter_bug_title(record['title'])
        record['status_class'] = re.sub('\s+', '', record['status'])

    elif record['record_type'] == 'tr':
        record['date_str'] = format_date(record['date'])  # no need for hours

    return record
Exemple #5
0
def extend_record(record):
    record = vault.extend_record(record)
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        review = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        patch = vault.get_memory_storage().get_record_by_primary_key(
            utils.get_patch_id(record['review_id'], record['patch']))
        if not review or not patch:
            return None

        _extend_by_parent_info(record, review, 'parent_')
        _extend_by_parent_info(record, patch, 'patch_')
    elif record['record_type'] == 'patch':
        review = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        _extend_by_parent_info(record, review, 'parent_')
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])
    elif record['record_type'] in ['bugr', 'bugf']:
        record['number'] = record['web_link'].split('/')[-1]
        record['title'] = filter_bug_title(record['title'])
        record['status_class'] = re.sub('\s+', '', record['status'])

    elif record['record_type'] == 'tr':
        record['date_str'] = format_date(record['date'])  # no need for hours

    return record
Exemple #6
0
def make_commit_message(record):
    s = record['message']

    s = utils.format_text(s)

    # insert links
    s = re.sub(
        re.compile('(bug[\s#:]*)([\d]{5,7})', flags=re.IGNORECASE),
        r'\1<a href="https://bugs.launchpad.net/bugs/\2" '
        r'class="ext_link">\2</a>', s)
    s = re.sub(
        r'\s+(I[0-9a-f]{40})',
        r' <a href="https://review.openstack.org/#q,\1,n,z" '
        r'class="ext_link">\1</a>', s)

    s = utils.unwrap_text(s)
    return s
Exemple #7
0
def get_activity_json(records):
    start_record = int(flask.request.args.get('start_record') or 0)
    page_size = int(flask.request.args.get('page_size') or
                    DEFAULT_RECORDS_LIMIT)
    result = []
    memory_storage_inst = get_memory_storage()
    for record in records:
        if record['record_type'] == 'commit':
            commit = record.copy()
            commit['branches'] = ','.join(commit['branches'])
            if 'correction_comment' not in commit:
                commit['correction_comment'] = ''
            commit['message'] = make_commit_message(record)
            _extend_record(commit)
            result.append(commit)
        elif record['record_type'] == 'mark':
            review = record.copy()
            parent = memory_storage_inst.get_record_by_primary_key(
                review['review_id'])
            if parent:
                review['review_attempt'] = parent.get('review_attempt')
                review['subject'] = parent['subject']
                review['url'] = parent['url']
                review['parent_author_link'] = make_link(
                    parent['author_name'], '/',
                    {'user_id': parent['user_id'],
                     'company': ''})
                _extend_record(review)
                result.append(review)
        elif record['record_type'] == 'email':
            email = record.copy()
            _extend_record(email)
            email['email_link'] = email.get('email_link') or ''
            result.append(email)
        elif ((record['record_type'] == 'bpd') or
             (record['record_type'] == 'bpc')):
            blueprint = record.copy()
            _extend_record(blueprint)
            blueprint['summary'] = utils.format_text(record['summary'])
            if 'mention_date' in record:
                blueprint['mention_date_str'] = format_datetime(
                    record['mention_date'])
            result.append(blueprint)

    result.sort(key=lambda x: x['date'], reverse=True)
    return result[start_record:start_record + page_size]
Exemple #8
0
def make_commit_message(record):
    s = record['message']
    module = record['module']

    s = utils.format_text(s)

    # insert links
    s = re.sub(re.compile('(blueprint\s+)([\w-]+)', flags=re.IGNORECASE),
               r'\1<a href="https://blueprints.launchpad.net/' +
               module + r'/+spec/\2" class="ext_link">\2</a>', s)
    s = re.sub(re.compile('(bug[\s#:]*)([\d]{5,7})', flags=re.IGNORECASE),
               r'\1<a href="https://bugs.launchpad.net/bugs/\2" '
               r'class="ext_link">\2</a>', s)
    s = re.sub(r'\s+(I[0-9a-f]{40})',
               r' <a href="https://review.openstack.org/#q,\1,n,z" '
               r'class="ext_link">\1</a>', s)

    s = utils.unwrap_text(s)
    return s
Exemple #9
0
def extend_record(record):
    record = record.copy()
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        if not parent:
            return None

        parent = parent.copy()
        _extend_record_common_fields(parent)
        for k, v in parent.iteritems():
            record['parent_%s' % k] = v

        record['review_number'] = parent.get('review_number')
        record['subject'] = parent['subject']
        record['url'] = parent['url']
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])

    return record
Exemple #10
0
def extend_record(record):
    record = record.copy()
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        if not parent:
            return None

        parent = parent.copy()
        _extend_record_common_fields(parent)
        for k, v in parent.iteritems():
            record['parent_%s' % k] = v

        record['review_number'] = parent.get('review_number')
        record['subject'] = parent['subject']
        record['url'] = parent['url']
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])

    return record
Exemple #11
0
def _extend_record(record):
    if record['record_type'] == 'commit':
        commit = record.copy()
        commit['branches'] = ','.join(commit['branches'])
        if 'correction_comment' not in commit:
            commit['correction_comment'] = ''
        commit['message'] = make_commit_message(record)
        _extend_record_common_fields(commit)
        return commit
    elif record['record_type'] == 'mark':
        review = record.copy()
        parent = get_memory_storage().get_record_by_primary_key(
            review['review_id'])
        if parent:
            review['review_number'] = parent.get('review_number')
            review['subject'] = parent['subject']
            review['url'] = parent['url']
            review['parent_author_link'] = make_link(
                parent['author_name'], '/',
                {'user_id': parent['user_id'],
                 'company': ''})
            _extend_record_common_fields(review)
            return review
    elif record['record_type'] == 'email':
        email = record.copy()
        _extend_record_common_fields(email)
        email['email_link'] = email.get('email_link') or ''
        return email
    elif ((record['record_type'] == 'bpd') or
          (record['record_type'] == 'bpc')):
        blueprint = record.copy()
        _extend_record_common_fields(blueprint)
        blueprint['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            blueprint['mention_date_str'] = format_datetime(
                record['mention_date'])
        blueprint['blueprint_link'] = make_blueprint_link(
            blueprint['name'], blueprint['module'])
        return blueprint
Exemple #12
0
def make_commit_message(record):
    s = record['message']
    module = record['module']
    # NOTE(aostapenko) Keeping default value here not to brake links
    # with existing storage data
    gerrit_hostname = record.get('gerrit_hostname', 'review.openstack.org')

    s = utils.format_text(s)

    # insert links
    s = re.sub(re.compile('(blueprint\s+)([\w-]+)', flags=re.IGNORECASE),
               r'\1<a href="https://blueprints.launchpad.net/' +
               module + r'/+spec/\2" class="ext_link">\2</a>', s)
    s = re.sub(re.compile('(bug[\s#:]*)([\d]{5,7})', flags=re.IGNORECASE),
               r'\1<a href="https://bugs.launchpad.net/bugs/\2" '
               r'class="ext_link">\2</a>', s)
    # NOTE(aostapenko) Setting http here as it's common practice to redirect
    # http -> https, but not vice versa
    s = re.sub(r'\s+(I[0-9a-f]{40})',
               r' <a href="http://%s/#/q/\1" ' % gerrit_hostname +
               r'class="ext_link">\1</a>', s)

    s = utils.unwrap_text(s)
    return s
Exemple #13
0
    def test_format_text_split_full_class_path_middle_line(self):
        original = 'some text tests.unit.benchmark.scenarios.test_base wide'
        expected = ('some text tests.&#8203;unit.&#8203;benchmark.&#8203;'
                    'scenarios.&#8203;test_base wide')

        self.assertEqual(expected, utils.format_text(original))
Exemple #14
0
    def test_format_text_split_full_class_path_middle_line(self):
        original = 'some text tests.unit.benchmark.scenarios.test_base wide'
        expected = ('some text tests.&#8203;unit.&#8203;benchmark.&#8203;'
                    'scenarios.&#8203;test_base wide')

        self.assertEqual(expected, utils.format_text(original))