def makeMessageDigest(clone, base, branch): hashes = phlgit_log.get_range_hashes(clone, base, branch) revisions = phlgit_log.make_revisions_from_hashes(clone, hashes) message = revisions[0].subject + "\n\n" for r in revisions: message += r.message return message
def testSimpleFork(self): self._createCommitNewFile("README") self.repo("branch", "fork") self._createCommitNewFile("ONLY_MASTER") self.repo("checkout", "fork") self._createCommitNewFile("ONLY_FORK", "ONLY_FORK", "BODY\nBODY") self._createCommitNewFile("ONLY_FORK2") log = phlgit_log.get_range_to_here_raw_body(self.repo, "master") self.assertIn("ONLY_FORK", log) self.assertNotIn("ONLY_MASTER", log) self.assertNotIn("README", log) hashes = phlgit_log.get_range_to_here_hashes(self.repo, "master") hashes2 = phlgit_log.get_range_hashes(self.repo, "master", "fork") self.assertListEqual(hashes, hashes2) r0 = phlgit_log.make_revision_from_hash(self.repo, hashes[0]) self.assertEqual(r0.subject, "ONLY_FORK") self.assertEqual(r0.message, "BODY\nBODY\n") r1 = phlgit_log.make_revision_from_hash(self.repo, hashes[1]) self.assertEqual(r1.subject, "ONLY_FORK2") self.assertIsNotNone(r1.message) self.assertIsInstance(r1.message, str) committers = phlgit_log.get_author_names_emails_from_hashes( self.repo, hashes) self.assertEqual(len(committers), 1) self.assertEqual(committers[0], (self.authorName, self.authorEmail))
def get_range_hashes(self, start, end): """Return a list of strings of commit hashes from 'start' to 'end'. The list begins with the revision closest to but not including 'start'. Raise a ValueError if any of the returned values are not valid hexadecimal. :start: a reference that log will understand :end: a reference that log will understand :returns: a list of strings of commit hashes from 'start' to 'end'. """ return phlgit_log.get_range_hashes(self._clone, start, end)
def get_range_hashes(self, start, end): """Return a list of strings of commit hashes from 'start' to 'end'. The list begins with the revision closest to but not including 'start'. Raise a ValueError if any of the returned values are not valid hexadecimal. :start: a reference that log will understand :end: a reference that log will understand :returns: a list of strings of commit hashes from 'start' to 'end'. """ return phlgit_log.get_range_hashes(self, start, end)
def getPrimaryNameEmailAndUserFromBranch(clone, conduit, base, branch): hashes = phlgit_log.get_range_hashes(clone, base, branch) if not hashes: raise abdt_exception.AbdUserException("no history to diff") commit = hashes[-1] committer = phlgit_log.get_author_names_emails_from_hashes( clone, [commit])[0] name = committer[0] email = committer[1] user = phlcon_user.query_users_from_emails(conduit, [email])[0] if not user: raise abdt_exception.AbdUserException( "first committer is not a Phabricator user") return name, email, user
def getAnyUserFromBranch(clone, conduit, base, branch): if phlgitu_ref.parse_ref_hash(clone, base) is None: hashes = phlgit_log.get_last_n_commit_hashes_from_ref(clone, 1, branch) else: hashes = phlgit_log.get_range_hashes(clone, base, branch) if not hashes: hashes = phlgit_log.get_last_n_commit_hashes_from_ref(clone, 1, branch) committers = phlgit_log.get_author_names_emails_from_hashes(clone, hashes) emails = [committer[1] for committer in committers] users = phlcon_user.query_users_from_emails(conduit, emails) for user in users: if user: return user raise abdt_exception.NoUsersOnBranchException(branch, base, emails)
def createReview(conduit, gitContext, review_branch): clone = gitContext.clone verifyReviewBranchBase(gitContext, review_branch) # TODO: we should also cc other users on the branch # TODO: if there are emails that don't match up to users then we should # note that on the review and perhaps use the mailer to notify them name, email, user = abdt_conduitgit.getPrimaryNameEmailAndUserFromBranch( clone, conduit, review_branch.remote_base, review_branch.remote_branch) print "- author: " + user used_default_test_plan = False hashes = phlgit_log.get_range_hashes( clone, review_branch.remote_base, review_branch.remote_branch) commit = hashes[-1] parsed = abdt_conduitgit.getFieldsFromCommitHash( conduit, clone, commit) if parsed.errors: used_default_test_plan = True parsed = abdt_conduitgit.getFieldsFromCommitHash( conduit, clone, commit, _DEFAULT_TEST_PLAN) if parsed.errors: print parsed raise abdt_exception.CommitMessageParseException( errors=parsed.errors, fields=parsed.fields, digest=makeMessageDigest( clone, review_branch.remote_base, review_branch.remote_branch)) rawDiff = phlgit_diff.raw_diff_range( clone, review_branch.remote_base, review_branch.remote_branch, _DIFF_CONTEXT_LINES) # if the diff is too big then regen with less context if len(rawDiff) >= MAX_DIFF_SIZE: rawDiff = phlgit_diff.raw_diff_range( clone, review_branch.remote_base, review_branch.remote_branch, _LESS_DIFF_CONTEXT_LINES) # if the diff is still too big then regen with no context if len(rawDiff) >= MAX_DIFF_SIZE: rawDiff = phlgit_diff.raw_diff_range( clone, review_branch.remote_base, review_branch.remote_branch) # if the diff is still too big then error if len(rawDiff) >= MAX_DIFF_SIZE: raise abdt_exception.LargeDiffException( "diff too big", len(rawDiff), MAX_DIFF_SIZE) revisionid = createDifferentialReview( conduit, user, parsed, gitContext, review_branch, rawDiff) if used_default_test_plan: commenter = abdcmnt_commenter.Commenter(conduit, revisionid) commenter.usedDefaultTestPlan(review_branch.branch, _DEFAULT_TEST_PLAN)