Ejemplo n.º 1
0
    def test_fetch_from_date(self):
        """Test fetch method with from date"""

        mock_check_ouput.side_effect = mock_check_ouput

        gerrit = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2)
        from_date = datetime.datetime(2018, 3, 5)
        reviews = [review for review in gerrit.fetch(from_date=from_date)]

        self.assertIsNotNone(gerrit.client)
        self.assertEqual(len(reviews), 4)

        review = reviews[0]
        self.assertEqual(review['category'], CATEGORY_REVIEW)
        self.assertEqual(len(review['data']['comments']), 5)
        self.assertEqual(review['data']['owner']['username'], 'gehel')
        self.assertEqual(len(review['data']['patchSets']), 2)

        review = reviews[1]
        self.assertEqual(review['category'], CATEGORY_REVIEW)
        self.assertEqual(len(review['data']['comments']), 26)
        self.assertEqual(review['data']['owner']['username'], "lucaswerkmeister-wmde")
        self.assertEqual(len(review['data']['patchSets']), 1)

        review = reviews[2]
        self.assertEqual(review['category'], CATEGORY_REVIEW)
        self.assertEqual(len(review['data']['comments']), 13)
        self.assertEqual(review['data']['owner']['username'], "jayprakash12345")
        self.assertEqual(len(review['data']['patchSets']), 3)

        review = reviews[3]
        self.assertEqual(review['category'], CATEGORY_REVIEW)
        self.assertEqual(len(review['data']['comments']), 8)
        self.assertEqual(review['data']['owner']['username'], "elukey")
        self.assertEqual(len(review['data']['patchSets']), 2)
Ejemplo n.º 2
0
    def test_serch_fields(self):
        """Test whether the search_fields is properly set"""

        mock_check_ouput.side_effect = mock_check_ouput

        gerrit = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2)
        reviews = [review for review in gerrit.fetch(from_date=None)]

        self.assertIsNotNone(gerrit.client)
        self.assertEqual(len(reviews), 5)

        review = reviews[0]
        self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id'])
        self.assertEqual(review['data']['project'], 'operations/puppet')
        self.assertEqual(review['data']['project'], review['search_fields']['project_name'])
        self.assertEqual(review['data']['id'], 'I99a07b8e55560db3ddc00e0c8c30c62b65136556')
        self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])

        review = reviews[1]
        self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id'])
        self.assertEqual(review['data']['project'], 'mediawiki/extensions/Wikibase')
        self.assertEqual(review['data']['project'], review['search_fields']['project_name'])
        self.assertEqual(review['data']['id'], 'I9ad743250f37c3be369888b1b9be80d8d332f62f')
        self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])

        review = reviews[2]
        self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id'])
        self.assertEqual(review['data']['project'], 'operations/mediawiki-config')
        self.assertEqual(review['data']['project'], review['search_fields']['project_name'])
        self.assertEqual(review['data']['id'], 'I9992907ef53f122b54ef2c64146da513477db025')
        self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])

        review = reviews[3]
        self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id'])
        self.assertEqual(review['data']['project'], 'operations/puppet')
        self.assertEqual(review['data']['project'], review['search_fields']['project_name'])
        self.assertEqual(review['data']['id'], 'I3d8e4685095da4b6a53e826c8a73ec13e4d562d2')
        self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])

        review = reviews[4]
        self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id'])
        self.assertEqual(review['data']['project'], 'operations/mediawiki-config')
        self.assertEqual(review['data']['project'], review['search_fields']['project_name'])
        self.assertEqual(review['data']['id'], 'I9992907ef53f122b54ef2c64146da513477db025')
        self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])
Ejemplo n.º 3
0
reviewerNames = {}
approverNames = {}
uploaderIdx = 0
authorIdx = 0
ownerIdx = 0
reviewerIdx = 0
approverIdx = 0
dateN = datetime.datetime(2019, 12, 18, 0, 0)
dateLast = datetime.datetime(2020, 6, 23, 0, 0).timestamp()


def Str(elem):
    return str(elem).encode("utf-8").decode()


for review in repo.fetch(from_date=dateN):
    reviewProjectName = str(review['data']['project']).lower()
    if not (projectName in reviewProjectName):
        continue

    if (review['data']['createdOn']) > dateLast:
        continue
    reviewData.write(
        str(review['data']['project']) + '/\\' +
        Str(review['data']['number']) + '/\\' + Str(review['data']['id']) +
        '/\\' + Str(review['data']['subject']) + '/\\' +
        Str(review['updated_on']) + '/\\' + Str(review['data']['createdOn']) +
        '/\\' + Str(review['data']['status']) + '\n')
    ownerEmail = ''
    if 'email' in review['data']['owner']:
        ownerEmail = Str(review['data']['owner']['email'])
Ejemplo n.º 4
0
#! /usr/bin/env python3

import datetime

from perceval.backends.core.gerrit import Gerrit

# hostname of the Gerrit instance
hostname = 'gerrit.opnfv.org'
# user for sshing to the Gerrit instance
user = '******'
# retrieve only reviews changed since this date
from_date = datetime.datetime.now() - datetime.timedelta(days=1)
# create a Gerrit object, pointing to hostname, using user for ssh access
repo = Gerrit(url=hostname, user=user)

# fetch all reviews as an iterator, and iterate it printing each review id
for review in repo.fetch(from_date=from_date):
    print("Review:", review['data']['number'], review['data']['url'], end='')
    print(review['data']['status'], review['data']['open'])
    print("  Patchsets:")
    for patch in review['data']['patchSets']:
        print("    ", patch['number'], "Draft:", patch['isDraft'],
              patch['kind'])
    print("  Comments:")
    for comment in review['data']['comments']:
        print("    Comment:")
        for line in comment['message'].splitlines():
            print("      ", line)