Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions libmozdata/hgmozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage
flake8
responses
mozbuild>=0.2; python_version < '3.0'

43 changes: 34 additions & 9 deletions tests/test_hgmozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import tempfile
import time
import shutil

if sys.version_info < (3, 0): # NOQA
import mercurial # NOQA
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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):
Expand Down