Example #1
0
 def test_review(self, gerrit_api):
     """Test that a review can be posted by the review API."""
     change_id = self._get_test_change(gerrit_api)["id"]
     review = GerritReview()
     review.set_message("Review from live test")
     review.add_labels({"Code-Review": 1})
     gerrit_api.review(change_id, "current", review)
Example #2
0
class ChecklistGenerator:
    def __init__(self, checklistFile):
        # Get Review Guidelines checklist
        scriptPath = os.path.dirname(os.path.abspath(__file__))
        guideFilepath = os.path.expanduser(scriptPath + "/" + checklistFile)
        if os.path.isfile(guideFilepath) == False:
            print("Error: No checklist file named <" + checklistFile +
                  "> found")
            vprint(scriptPath)
            quit()

        with open(guideFilepath, 'r') as guideFile:
            checklist = []
            for line in guideFile.readlines():
                line = line.rstrip("\n\r")
                checklist.append(line)
            self.checklist = checklist

        self.review = GerritReview()
        self.getChecklistComments(self.checklist)

    # Converts it to GerritReview for the Gerrit REST API
    def getChecklistComments(self, checklist):
        comments = []
        for check in checklist:
            comment = {"filename": "/COMMIT_MSG", "line": 6}
            comment["message"] = check
            comments.append(comment)
        self.review.add_comments(comments)
        vprint(comments)

    # Returns GerritReview object of Review Checklist for posting as inline comments
    def getReview(self):
        return self.review
Example #3
0
    def test_str(self):
        """Test for str function."""
        obj = GerritReview()
        self.assertEqual(str(obj), '{}')

        obj2 = GerritReview(labels={'Verified': 1, 'Code-Review': -1})
        self.assertEqual(
            str(obj2),
            '{"labels": {"Code-Review": -1, "Verified": 1}}')

        obj3 = GerritReview(comments=[{'filename': 'Makefile',
                                       'line': 10, 'message': 'test'}])
        self.assertEqual(
            str(obj3),
            '{"comments": {"Makefile": [{"line": 10, "message": "test"}]}}')

        obj4 = GerritReview(labels={'Verified': 1, 'Code-Review': -1},
                            comments=[{'filename': 'Makefile', 'line': 10,
                                       'message': 'test'}])
        self.assertEqual(
            str(obj4),
            '{"comments": {"Makefile": [{"line": 10, "message": "test"}]},'
            ' "labels": {"Code-Review": -1, "Verified": 1}}')

        obj5 = GerritReview(comments=[
            {'filename': 'Makefile', 'line': 15, 'message': 'test'},
            {'filename': 'Make', 'line': 10, 'message': 'test1'}
        ])
        self.assertEqual(
            str(obj5),
            '{"comments": {"Make": [{"line": 10, "message": "test1"}],'
            ' "Makefile": [{"line": 15, "message": "test"}]}}')
Example #4
0
    def review(self, label=None, vote=1, message=''):
        print("Posting {} review for change: {}".format(
            " {}: {}".format(label, vote) if label else '', self))
        auth = HTTPDigestAuthFromNetrc(url=GERRIT_URL)
        rest = GerritRestAPI(url=GERRIT_URL, auth=auth, verify=GERRIT_VERIFY)
        rev = GerritReview()
        rev.set_message(message)
        if label:
            rev.add_labels({label: vote})

        rest.review(self.id, self.patchset, rev)
Example #5
0
    def test_str(self):
        """Test for str function."""
        obj = GerritReview()
        self.assertEqual(str(obj), "{}")

        obj2 = GerritReview(labels={"Verified": 1, "Code-Review": -1})
        self.assertEqual(str(obj2),
                         '{"labels": {"Code-Review": -1, "Verified": 1}}')

        obj3 = GerritReview(comments=[{
            "filename": "Makefile",
            "line": 10,
            "message": "test"
        }])
        self.assertEqual(
            str(obj3),
            '{"comments": {"Makefile": [{"line": 10, "message": "test"}]}}')

        obj4 = GerritReview(
            labels={
                "Verified": 1,
                "Code-Review": -1
            },
            comments=[{
                "filename": "Makefile",
                "line": 10,
                "message": "test"
            }],
        )
        self.assertEqual(
            str(obj4),
            '{"comments": {"Makefile": [{"line": 10, "message": "test"}]},'
            ' "labels": {"Code-Review": -1, "Verified": 1}}',
        )

        obj5 = GerritReview(comments=[
            {
                "filename": "Makefile",
                "line": 15,
                "message": "test"
            },
            {
                "filename": "Make",
                "line": 10,
                "message": "test1"
            },
        ])
        self.assertEqual(
            str(obj5),
            '{"comments": {"Make": [{"line": 10, "message": "test1"}],'
            ' "Makefile": [{"line": 15, "message": "test"}]}}',
        )
Example #6
0
 def test_review(self, gerrit_api):
     """Test that a review can be posted by the review API."""
     change_id = self._get_test_change(gerrit_api)["id"]
     review = GerritReview()
     review.set_message("Review from live test")
     review.add_labels({"Code-Review": 1})
     review.set_tag("a_test_tag")
     gerrit_api.review(change_id, "current", review)
Example #7
0
    def __init__(self, checklistFile):
        # Get Review Guidelines checklist
        scriptPath = os.path.dirname(os.path.abspath(__file__))
        guideFilepath = os.path.expanduser(scriptPath + "/" + checklistFile)
        if os.path.isfile(guideFilepath) == False:
            print("Error: No checklist file named <" + checklistFile +
                  "> found")
            vprint(scriptPath)
            quit()

        with open(guideFilepath, 'r') as guideFile:
            checklist = []
            for line in guideFile.readlines():
                line = line.rstrip("\n\r")
                checklist.append(line)
            self.checklist = checklist

        self.review = GerritReview()
        self.getChecklistComments(self.checklist)
Example #8
0
    def review(self, label=None, vote=1, message=''):
        print_err("Posting {} review for change: {}".format(
            " {}: {}".format(label, vote) if label else '', self))
        auth = HTTPDigestAuthFromNetrc(url=GERRIT_URL)
        rest = GerritRestAPI(url=GERRIT_URL, auth=auth, verify=GERRIT_VERIFY)
        rev = GerritReview()
        rev.set_message(message)
        if label:
            rev.add_labels({label: vote})

        rest.review(self.id, self.patchset, rev)