def _createRevision(self, title):
     diff = """diff --git a/ b/"""
     message = title + "\n\ntest plan: no test plan"
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
     create_response = phlcon_differential.create_revision(self.conduit, diff_response.id, parse_response.fields)
     return create_response.revisionid
    def update_revision(self, revisionid, raw_diff, message):
        """Update an existing Differential revision with a new diff.

        :revisionid: id of the Differential revision to update
        :raw_diff: raw output string from e.g. 'git diff master...'
        :message: string message to annotate the update event with
        :returns: None

        """
        # do some sanity checks before committing to the expensive operation
        # of storing a diff in Differential
        status = self._reviewstate_cache.get_status(revisionid)
        if status == phlcon_differential.ReviewStates.closed:
            raise abdt_exception.AbdUserException(
                "can't update a closed revision")

        author_user = self._get_author_user(revisionid)
        with phlsys_conduit.act_as_user_context(self._conduit, author_user):
            diffid = phlcon_differential.create_raw_diff(
                self._conduit, raw_diff).id
            try:
                phlcon_differential.update_revision(
                    self._conduit, revisionid, diffid, [], message)
            except phlcon_differential.UpdateClosedRevisionError:
                raise abdt_exception.AbdUserException(
                    "CONDUIT: can't update a closed revision")
        self._log(
            'conduit-updaterev',
            'updated {} as {}'.format(revisionid, author_user))
def createDifferentialReview(
        conduit, user, parsed, gitContext, review_branch, rawDiff):
    clone = gitContext.clone
    phlgit_checkout.new_branch_force_based_on(
        clone, review_branch.branch, review_branch.remote_branch)

    with phlsys_conduit.act_as_user_context(conduit, user):
        print "- creating diff"
        diffid = phlcon_differential.create_raw_diff(conduit, rawDiff).id

        print "- creating revision"
        review = phlcon_differential.create_revision(
            conduit, diffid, parsed.fields)
        print "- created " + str(review.revisionid)

        workingBranch = abdt_naming.makeWorkingBranchName(
            abdt_naming.WB_STATUS_OK,
            review_branch.description,
            review_branch.base,
            review.revisionid)

        print "- pushing working branch: " + workingBranch
        phlgit_push.push_asymmetrical(
            clone, review_branch.branch, workingBranch, gitContext.remote)

    print "- commenting on " + str(review.revisionid)
    commenter = abdcmnt_commenter.Commenter(conduit, review.revisionid)
    commenter.createdReview(review_branch.branch, review_branch.base)

    return review.revisionid
Example #4
0
    def create_revision_as_user(self, raw_diff, fields, username):
        """Return the id of a newly created revision based on specified args.

        See phlcon_differential.MessageFields for some examples of valid input
        for specified 'fields'.

        :raw_diff: raw output string from e.g. 'git diff master...'
        :fields: dict of string attributes, required: 'title' and 'testPlan'
        :username: username for the author of the revision
        :returns: id of created revision

        """
        as_user_conduit = self._make_as_user_conduit(username)

        with self._log_context(
                'conduit-createrev',
                'create as {}'.format(username)) as log:

            diffid = phlcon_differential.create_raw_diff(
                as_user_conduit, raw_diff).id

            review = phlcon_differential.create_revision(
                as_user_conduit, diffid, fields)

            log.append(review.revisionid)

        return review.revisionid
    def _createNonEmptyRevision(self, title):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""

        message = "{}\n\nTest Plan: this is the plan".format(title)

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        get_diff_response = phlcon_differential._get_diff(self.conduit, diff_id=diff_response.id)
        self.assertEqual(get_diff_response.id, diff_response.id)

        parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(self.conduit, diff_response.id, parse_response.fields)

        return create_response.revisionid
    def update_revision(self, revisionid, raw_diff, message):
        """Update an existing Differential revision with a new diff.

        :revisionid: id of the Differential revision to update
        :raw_diff: raw output string from e.g. 'git diff master...'
        :message: string message to annotate the update event with
        :returns: None

        """
        # do some sanity checks before committing to the expensive operation
        # of storing a diff in Differential
        state = self._reviewstate_cache.get_state(revisionid)
        if state.status == phlcon_differential.ReviewStates.closed:
            raise abdt_exception.AbdUserException(
                "can't update a closed revision")

        author_user = self._get_author_user(revisionid)
        as_user_conduit = self._make_as_user_conduit(author_user)

        with self._log_context(
                'conduit-updaterev',
                'update {} as {}'.format(revisionid, author_user)):

            diffid = phlcon_differential.create_raw_diff(
                as_user_conduit, raw_diff).id
            try:
                phlcon_differential.update_revision(as_user_conduit,
                                                    revisionid, diffid, [],
                                                    message)
            except phlcon_differential.UpdateClosedRevisionError:
                raise abdt_exception.AbdUserException(
                    "CONDUIT: can't update a closed revision")
    def create_revision_as_user(self, raw_diff, fields, username):
        """Return the id of a newly created revision based on specified args.

        See phlcon_differential.MessageFields for some examples of valid input
        for specified 'fields'.

        :raw_diff: raw output string from e.g. 'git diff master...'
        :fields: dict of string attributes, required: 'title' and 'testPlan'
        :username: username for the author of the revision
        :returns: id of created revision

        """
        as_user_conduit = self._make_as_user_conduit(username)

        with self._log_context('conduit-createrev',
                               'create as {}'.format(username)) as log:

            diffid = phlcon_differential.create_raw_diff(
                as_user_conduit, raw_diff).id

            review = phlcon_differential.create_revision(
                as_user_conduit, diffid, fields)

            log.append(review.revisionid)

        return review.revisionid
Example #8
0
    def _createNonEmptyRevision(self, title):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""

        message = "{}\n\nTest Plan: this is the plan".format(title)

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        return create_response.revisionid
 def testUpdateStrangeFields(self):
     revisionid = self._createRevision("testUpdateStrangeFields")
     message = "test\n\nmeh: blah\nstrange: blah\n123: blah\ntest plan: hmm"
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
     print str(parse_response.fields)
     phlcon_differential.update_revision(self.conduit, revisionid, diff_response.id, parse_response.fields, "update")
Example #10
0
 def _createRevision(self, title):
     diff = """diff --git a/ b/"""
     message = title + "\n\ntest plan: no test plan"
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(
         self.conduit, message)
     create_response = phlcon_differential.create_revision(
         self.conduit, diff_response.id, parse_response.fields)
     return create_response.revisionid
Example #11
0
 def testUpdateStrangeFields(self):
     revisionid = self._createRevision("testUpdateStrangeFields")
     message = "test\n\nmeh: blah\nstrange: blah\n123: blah\ntest plan: hmm"
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(
         self.conduit, message)
     print(str(parse_response.fields))
     phlcon_differential.update_revision(
         self.conduit,
         revisionid,
         diff_response.id,
         parse_response.fields,
         "update")
    def testCreateDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -1,3 +1,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""
        raw_diff_response = phlcon_differential.create_raw_diff(
            self.conduit, diff)
        get_diff_response = phlcon_differential._get_diff(
            self.conduit,
            diff_id=raw_diff_response.id)

        diff_response = phlcon_differential.create_diff(
            self.conduit,
            changes_dict=get_diff_response.changes,
            source_machine="test_machine",
            source_path="source_path",
            branch="branch",
            source_control_system="git",  # svn or git
            source_control_path="control_path",
            source_control_base_revision="0",
            lint_status="none",
            unit_status="none",
            bookmark=None,
            parent_revision_id=None,
            creation_method="arcanist daemon",
            author_phid=None,
            arcanist_project="project",
            repository_uuid=None)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        # rely on create_revision to raise if we get anything seriously wrong
        phlcon_differential.create_revision(
            self.conduit, diff_response["diffid"], parse_response.fields)
    def create_revision_as_user(self, raw_diff, fields, username):
        """Return the id of a newly created revision based on specified args.

        See phlcon_differential.MessageFields for some examples of valid input
        for specified 'fields'.

        :raw_diff: raw output string from e.g. 'git diff master...'
        :fields: dict of string attributes, required: 'title' and 'testPlan'
        :username: username for the author of the revision
        :returns: id of created revision

        """
        with phlsys_conduit.act_as_user_context(self._conduit, username):
            diffid = phlcon_differential.create_raw_diff(
                self._conduit, raw_diff).id
            review = phlcon_differential.create_revision(
                self._conduit, diffid, fields)
        return review.revisionid
    def testCreateCloseRawDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""

        diff2 = """
diff --git a/readme b/readme
index d4711bb..1c634f5 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,5 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
+another line
"""

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        get_diff_response = phlcon_differential._get_diff(
            self.conduit, diff_id=diff_response.id)
        self.assertEqual(get_diff_response.id, diff_response.id)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.needs_review)

        diff2_response = phlcon_differential.create_raw_diff(
            self.conduit, diff2)

        update_response = phlcon_differential.update_revision(
            self.conduit,
            create_response.revisionid, diff2_response.id,
            parse_response.fields, "updated with new diff")
        self.assertEqual(
            update_response.revisionid, create_response.revisionid)
        self.assertEqual(update_response.uri, create_response.uri)

        comment_response = phlcon_differential.create_comment(
            self.reviewerConduit, create_response.revisionid, action="accept")
        self.assertEqual(
            comment_response.revisionid, create_response.revisionid)
        self.assertEqual(comment_response.uri, create_response.uri)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.accepted)

        phlcon_differential.close(self.conduit, create_response.revisionid)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.closed)
 def testUpdateNoFields(self):
     revisionid = self._createRevision("testUpdateNoFields")
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     phlcon_differential.update_revision(
         self.conduit, revisionid, diff_response.id, [], "update")
Example #16
0
    def testCreateCloseRawDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""

        diff2 = """
diff --git a/readme b/readme
index d4711bb..1c634f5 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,5 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
+another line
"""

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.needs_review)

        diff2_response = phlcon_differential.create_raw_diff(
            self.conduit, diff2)

        update_response = phlcon_differential.update_revision(
            self.conduit,
            create_response.revisionid, diff2_response.id,
            parse_response.fields, "updated with new diff")
        self.assertEqual(
            update_response.revisionid, create_response.revisionid)
        self.assertEqual(update_response.uri, create_response.uri)

        comment_response = phlcon_differential.create_comment(
            self.reviewerConduit, create_response.revisionid, action="accept")
        self.assertEqual(
            comment_response.revisionid, create_response.revisionid)
        self.assertEqual(comment_response.uri, create_response.uri)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.accepted)

        phlcon_differential.close(self.conduit, create_response.revisionid)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.closed)
Example #17
0
 def testUpdateNoFields(self):
     revisionid = self._createRevision("testUpdateNoFields")
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     phlcon_differential.update_revision(
         self.conduit, revisionid, diff_response.id, [], "update")