Exemple #1
0
def yield_revisions(conduit, args):
    revision_list = phlcon_differential.query(conduit, args.ids)

    use_cache = not bool(args.ids)

    history = {}

    if use_cache:
        cache_filename = '.linteratecache'
        if os.path.isfile(cache_filename):
            with open(cache_filename) as cache_file:
                history = json.load(cache_file)

        # filter out revisions with nothing new
        # be careful to convert revision.id to string or it won't match history
        revision_list = filter(
            lambda x: set(history.get(x.phid, [])) != set(x.diffs),
            revision_list)

    for revision in revision_list:
        diff = phlcon_differential.get_revision_diff(conduit, revision.id)
        with phlsys_fs.chtmpdir_context() as temp_dir:
            try:
                phlcon_differential.write_diff_files(diff, temp_dir)
            except phlcon_differential.WriteDiffError as e:
                if not args.silent:
                    print('skipping revision ', revision.id, ':', e)
            else:
                yield revision

        history[revision.phid] = revision.diffs

        if use_cache:
            with open(cache_filename, 'w') as cache_file:
                json.dump(history, cache_file)
def yield_revisions(conduit, args):
    revision_list = phlcon_differential.query(conduit, args.ids)

    use_cache = not bool(args.ids)

    history = {}

    if use_cache:
        cache_filename = '.linteratecache'
        if os.path.isfile(cache_filename):
            with open(cache_filename) as cache_file:
                history = json.load(cache_file)

        # filter out revisions with nothing new
        # be careful to convert revision.id to string or it won't match history
        revision_list = filter(
            lambda x: set(history.get(x.phid, [])) != set(x.diffs),
            revision_list)

    for revision in revision_list:
        diff = phlcon_differential.get_revision_diff(conduit, revision.id)
        with phlsys_fs.chtmpdir_context() as temp_dir:
            try:
                phlcon_differential.write_diff_files(diff, temp_dir)
            except phlcon_differential.WriteDiffError as e:
                if not args.silent:
                    print('skipping revision ', revision.id, ':', e)
            else:
                yield revision

        history[revision.phid] = revision.diffs

        if use_cache:
            with open(cache_filename, 'w') as cache_file:
                json.dump(history, cache_file)
 def _get_author_user(self, revisionid):
     # TODO: these queries are very expensive, cache them
     revision = phlcon_differential.query(
         self._multi_conduit, [revisionid])[0]
     author_user = phlcon_user.query_usernames_from_phids(
         self._multi_conduit, [revision.authorPHID])[0]
     return author_user
 def _get_author_user(self, revisionid):
     # TODO: these queries are very expensive, cache them
     revision = phlcon_differential.query(self._multi_conduit,
                                          [revisionid])[0]
     author_user = phlcon_user.query_usernames_from_phids(
         self._multi_conduit, [revision.authorPHID])[0]
     return author_user
def processUpdatedBranch(
        mailer, conduit, gitContext, review_branch, working_branch):
    abdte = abdt_exception
    if working_branch is None:
        print "create review for " + review_branch.branch
        tryCreateReview(
            mailer, conduit, gitContext, review_branch, mail_on_fail=True)
    else:
        commenter = abdcmnt_commenter.Commenter(conduit, working_branch.id)
        if abdt_naming.isStatusBadPreReview(working_branch):
            hasChanged = not phlgit_branch.is_identical(
                gitContext.clone,
                review_branch.remote_branch,
                working_branch.remote_branch)
            print "try again to create review for " + review_branch.branch
            phlgit_push.delete(
                gitContext.clone,
                working_branch.branch,
                gitContext.remote)
            tryCreateReview(
                mailer,
                conduit,
                gitContext,
                review_branch,
                mail_on_fail=hasChanged)
        else:
            print "update review for " + review_branch.branch
            revision = phlcon_differential.query(
                conduit, [working_branch.id])[0]
            author_user = phlcon_user.query_usernames_from_phids(
                conduit, [revision.authorPHID])[0]
            try:
                updateReview(
                    conduit,
                    gitContext,
                    review_branch,
                    working_branch,
                    author_user)
            except abdte.LandingException as e:
                print "landing exception"
                abdt_workingbranch.pushBadLand(
                    gitContext, review_branch, working_branch)
                commenter.exception(e)
                with phlsys_conduit.act_as_user_context(conduit, author_user):
                    phlcon_differential.create_comment(
                        conduit,
                        working_branch.id,
                        action=phlcon_differential.Action.rethink)
            except abdte.AbdUserException as e:
                print "user exception"
                abdt_workingbranch.pushBadInReview(
                    gitContext, review_branch, working_branch)
                commenter.exception(e)
    def testCreateUpdateEmptyRevision(self):
        conduit = phlsys_conduit.Conduit(
            self.test_data.TEST_URI, self.test_data.PHAB.user, self.test_data.PHAB.certificate
        )
        author = phldef_conduit.ALICE.user
        with phlsys_conduit.act_as_user_context(conduit, author):
            revision_id = phlcon_differential.create_empty_revision(conduit)

        revision_list = phlcon_differential.query(conduit, [revision_id])
        self.assertEqual(len(revision_list), 1)

        with phlsys_conduit.act_as_user_context(conduit, author):
            phlcon_differential.update_revision_empty(conduit, revision_id)
Exemple #7
0
    def testCreateUpdateEmptyRevision(self):
        conduit = phlsys_conduit.Conduit(
            self.test_data.TEST_URI,
            self.test_data.PHAB.user,
            self.test_data.PHAB.certificate)
        author = phldef_conduit.ALICE.user
        with phlsys_conduit.act_as_user_context(conduit, author):
            revision_id = phlcon_differential.create_empty_revision(conduit)

        revision_list = phlcon_differential.query(conduit, [revision_id])
        self.assertEqual(len(revision_list), 1)

        with phlsys_conduit.act_as_user_context(conduit, author):
            phlcon_differential.update_revision_empty(conduit, revision_id)
 def revision_list_status(revision_list):
     return phlcon_differential.query(conduit, revision_list)
    def testCreateEmptyRevision(self):
        revision_id = abdt_conduit.createEmptyRevision(
            self.conduit, self.test_data.ALICE.user)

        revision_list = phlcon_differential.query(self.conduit, [revision_id])
        self.assertEqual(len(revision_list), 1)
    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 testNullQuery(self):
     phlcon_differential.query(self.conduit)
 def _getState(self, revisionid):
     return phlcon_differential.query(self.conduit, [revisionid])[0].status
 def revision_list_status(revision_list):
     return phlcon_differential.query(conduit, revision_list)
Exemple #14
0
 def _getState(self, revisionid):
     return phlcon_differential.query(self.conduit, [revisionid])[0].status
Exemple #15
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)
Exemple #16
0
 def testNullQuery(self):
     phlcon_differential.query(self.conduit)