diff --git a/libmozdata/hgmozilla.py b/libmozdata/hgmozilla.py index 2438068a..22cf29c7 100644 --- a/libmozdata/hgmozilla.py +++ b/libmozdata/hgmozilla.py @@ -255,6 +255,25 @@ def __init__(self, path, ui=None): self.ui = ui if ui else mercurial.ui.ui() self.repo = hg.repository(self.ui, path) self.haspushlog = hasattr(self.repo, 'pushlog') + try: + self.hgmo = mercurial.extensions.find('hgmo') + except: + self.hgmo = None + + def __addpushdate(self, d, ctx): + if self.haspushlog: + pushinfo = self.repo.pushlog.pushfromchangeset(ctx) + if pushinfo: + # pushdate is a 2-uple with timestamp (UTC) and the timezone of the pusher. + pushdate = mercurial.util.makedate(pushinfo.when) + d['pushdate'] = list(pushdate) + return + + d['pushdate'] = '' + + def __addmetadata(self, d, ctx, onlycheap=False): + if self.hgmo: + self.hgmo.addmetadata(self.repo, ctx, d, onlycheap=onlycheap) def get_filelog(self, paths, rev='tip'): rev = rev.encode('ascii') @@ -274,13 +293,20 @@ def get_filelog(self, paths, rev='tip'): _entry['date'] = list(_fctx.date()) _entry['desc'] = _fctx.description() _entry['node'] = mercurial.node.hex(_fctx.node()) - if self.haspushlog: - pushinfo = self.repo.pushlog.pushfromchangeset(_fctx) - if pushinfo: - # pushdate is a 2-uple with timestamp (UTC) and the timezone of the pusher. - pushdate = mercurial.util.makedate(pushinfo.when) - _entry['pushdate'] = list(pushdate) + self.__addpushdate(_entry, _fctx) entries.reverse() data[path] = entries return data + + def get_revision(self, node='tip'): + node = node.encode('ascii') + ctx = self.repo[node] + data = {'author': ctx.user(), + 'desc': ctx.description(), + 'date': list(ctx.date()), + 'node': mercurial.node.hex(ctx.node())} + self.__addpushdate(data, ctx) + self.__addmetadata(data, ctx) + + return data diff --git a/test-requirements.txt b/test-requirements.txt index f578cf8e..8278b6b1 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,5 @@ coverage flake8 responses +mozbuild>=0.2; python_version < '3.0' + diff --git a/tests/test_hgmozilla.py b/tests/test_hgmozilla.py index 638eabd3..9ffdd6d9 100644 --- a/tests/test_hgmozilla.py +++ b/tests/test_hgmozilla.py @@ -9,6 +9,7 @@ import os import tempfile import time +import shutil if sys.version_info < (3, 0): # NOQA import mercurial # NOQA @@ -22,6 +23,7 @@ def create_repo(self, dest, ui): commands.clone(ui, vct, dest=os.path.join(dest, 'vct.hg')) ui.setconfig('extensions', 'pushlog', os.path.join(dest, 'vct.hg/hgext/pushlog')) + ui.setconfig('extensions', 'hgmo', os.path.join(dest, 'vct.hg/hgext/hgmo')) srcdir = os.path.join(dest, 'test') destdir = os.path.join(dest, 'testwork') @@ -41,21 +43,17 @@ def create_repo(self, dest, ui): In.write(str(i)) with open(myfile2, 'a') as In: In.write(str(i)) - commands.commit(ui, repo, myfile1, myfile2, message='message' + str(i), user='scooper@tbbt.com', addremove=True) + if i == 4: + commands.commit(ui, repo, myfile1, myfile2, message='bug %d -- message, r=hwolowitz, r=affowler' % i, user='scooper@tbbt.com', addremove=True) + else: + commands.commit(ui, repo, myfile1, myfile2, message='message%d' % i, user='scooper@tbbt.com', addremove=True) commands.push(ui, repo, dest=srcdir) time.sleep(1.01) return srcdir - def test_getfilelog(self): - if sys.version_info >= (3, 0): - return - - tmpdst = tempfile.mkdtemp() - ui = mercurial.ui.ui().copy() - hgmo = hgmozilla.HGMozilla(self.create_repo(tmpdst, ui), ui=ui) + def __getfilelog(self, hgmo): data = hgmo.get_filelog(['myfile1', 'myfile2']) - self.assertIn('myfile1', data) self.assertIn('myfile2', data) self.assertEqual(len(data['myfile1']), 5) @@ -74,6 +72,33 @@ def test_getfilelog(self): self.assertEqual(len(data['myfile2'][3]['date']), 2) self.assertIsInstance(data['myfile2'][3]['node'], str) + def __getrevision(self, hgmo): + data = hgmo.get_revision(node='tip') + self.assertEqual(data['author'], 'scooper@tbbt.com') + self.assertEqual(data['desc'], 'bug 4 -- message, r=hwolowitz, r=affowler') + self.assertIsInstance(data['bugs'], list) + self.assertEqual(len(data['bugs']), 1) + self.assertEqual(data['bugs'][0]['no'], '4') + self.assertEqual(data['bugs'][0]['url'], 'https://bugzilla.mozilla.org/show_bug.cgi?id=4') + + self.assertIsInstance(data['reviewers'], list) + self.assertEqual(len(data['reviewers']), 2) + self.assertEqual(data['reviewers'][0]['name'], 'hwolowitz') + self.assertEqual(data['reviewers'][1]['name'], 'affowler') + + def test(self): + if sys.version_info >= (3, 0): + return + + try: + tmpdst = tempfile.mkdtemp() + ui = mercurial.ui.ui().copy() + hgmo = hgmozilla.HGMozilla(self.create_repo(tmpdst, ui), ui=ui) + self.__getfilelog(hgmo) + self.__getrevision(hgmo) + finally: + shutil.rmtree(tmpdst) + class RevisionTest(unittest.TestCase): def test_revision(self):