launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26190
[Merge] ~ilasc/launchpad:add-repack-data-notify into launchpad:master
Ioana Lasc has proposed merging ~ilasc/launchpad:add-repack-data-notify into launchpad:master.
Commit message:
Add repack data to notify endpoint
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/397340
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:add-repack-data-notify into launchpad:master.
diff --git a/lib/lp/code/interfaces/gitapi.py b/lib/lp/code/interfaces/gitapi.py
index e4a91db..acc7fd9 100644
--- a/lib/lp/code/interfaces/gitapi.py
+++ b/lib/lp/code/interfaces/gitapi.py
@@ -50,12 +50,14 @@ class IGitAPI(Interface):
this repository, otherwise False.
"""
- def notify(translated_path):
+ def notify(translated_path, loose_objects=None, packs=None):
"""Notify of a change to the repository at 'translated_path'.
:param translated_path: The translated path to the repository. (We
use translated paths here in order to avoid problems with
repository names etc. being changed during a push.)
+ :param loose_objects: The number of loose objects for the repository.
+ :param packs: The number of packs for the repository.
:returns: A `NotFound` fault if no repository can be found for
'translated_path'; otherwise None.
diff --git a/lib/lp/code/interfaces/gitrepository.py b/lib/lp/code/interfaces/gitrepository.py
index cdb9b27..0e0f096 100644
--- a/lib/lp/code/interfaces/gitrepository.py
+++ b/lib/lp/code/interfaces/gitrepository.py
@@ -900,6 +900,15 @@ class IGitRepositoryEdit(IWebhookTarget):
effective permissions on each of the requested references.
"""
+ def setRepackData(loose_objects, packs):
+ """Sets the repack parameters received from Turnip.
+ :param loose_objects: The number of loose objects that
+ this repository currently has.
+ :param packs: The number of packs that
+ this repository currently has.
+ be either bytes or text).
+ """
+
@operation_parameters(
person=Reference(title=_("Person to check"), schema=IPerson),
paths=List(title=_("Reference paths"), value_type=TextLine()))
diff --git a/lib/lp/code/model/gitrepository.py b/lib/lp/code/model/gitrepository.py
index 91c7264..bada9dc 100644
--- a/lib/lp/code/model/gitrepository.py
+++ b/lib/lp/code/model/gitrepository.py
@@ -337,9 +337,19 @@ class GitRepository(StormBase, WebhookTargetMixin, GitIdentityMixin):
_default_branch = Unicode(name='default_branch', allow_none=True)
+ loose_object_count = Int(name='loose_object_count', allow_none=True)
+ pack_count = Int(name='pack_count', allow_none=True)
+
+ date_last_repacked = DateTime(
+ name='date_last_repacked', tzinfo=pytz.UTC, allow_none=True)
+ date_last_scanned = DateTime(
+ name='date_last_scanned', tzinfo=pytz.UTC, allow_none=True)
+
def __init__(self, repository_type, registrant, owner, target, name,
information_type, date_created, reviewer=None,
- description=None, status=None):
+ description=None, status=None, loose_object_count=None,
+ pack_count=None, date_last_scanned=None,
+ date_last_repacked=None):
super(GitRepository, self).__init__()
self.repository_type = repository_type
self.registrant = registrant
@@ -366,6 +376,10 @@ class GitRepository(StormBase, WebhookTargetMixin, GitIdentityMixin):
else GitRepositoryStatus.AVAILABLE)
self.owner_default = False
self.target_default = False
+ self.loose_object_count = loose_object_count
+ self.pack_count = pack_count
+ self.date_last_repacked = date_last_repacked
+ self.date_last_scanned = date_last_scanned
def _createOnHostingService(
self, clone_from_repository=None, async_create=False):
@@ -623,6 +637,11 @@ class GitRepository(StormBase, WebhookTargetMixin, GitIdentityMixin):
"""See `IGitRepository`."""
return self.branches.order_by(Desc(GitRef.committer_date))
+ def setRepackData(self, loose_objects, packs):
+ self.loose_object_count = loose_objects
+ self.pack_count = packs
+ self.date_last_scanned = UTC_NOW
+
@property
def default_branch(self):
"""See `IGitRepository`."""
diff --git a/lib/lp/code/xmlrpc/git.py b/lib/lp/code/xmlrpc/git.py
index 0ebcde0..73c598d 100644
--- a/lib/lp/code/xmlrpc/git.py
+++ b/lib/lp/code/xmlrpc/git.py
@@ -450,16 +450,19 @@ class GitAPI(LaunchpadXMLRPCView):
logger.info("translatePath succeeded: %s", result)
return result
- def notify(self, translated_path):
+ def notify(self, translated_path, loose_objects=None, packs=None):
"""See `IGitAPI`."""
logger = self._getLogger()
logger.info("Request received: notify('%s')", translated_path)
- repository = getUtility(IGitLookup).getByHostingPath(translated_path)
+ repository = removeSecurityProxy(
+ getUtility(IGitLookup).getByHostingPath(translated_path))
if repository is None:
fault = faults.NotFound(
"No repository found for '%s'." % translated_path)
logger.error("notify failed: %r", fault)
return fault
+ if loose_objects or packs:
+ repository.setRepackData(loose_objects, packs)
getUtility(IGitRefScanJobSource).create(
removeSecurityProxy(repository))
logger.info("notify succeeded")
diff --git a/lib/lp/code/xmlrpc/tests/test_git.py b/lib/lp/code/xmlrpc/tests/test_git.py
index ce3a0a6..c1a3afb 100644
--- a/lib/lp/code/xmlrpc/tests/test_git.py
+++ b/lib/lp/code/xmlrpc/tests/test_git.py
@@ -7,11 +7,13 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
+from datetime import datetime
import hashlib
import uuid
from fixtures import FakeLogger
from pymacaroons import Macaroon
+import pytz
import six
from six.moves import xmlrpc_client
from six.moves.urllib.parse import quote
@@ -2092,6 +2094,20 @@ class TestGitAPI(TestGitAPIMixin, TestCaseWithFactory):
[job] = list(job_source.iterReady())
self.assertEqual(repository, job.repository)
+ def test_notify_set_repack_data(self):
+ # The notify call sets the repack
+ # indicators (loose_objects, packs, date_last_scanned)
+ # when received from Turnip
+ repository = self.factory.makeGitRepository()
+ path = repository.getInternalPath()
+ self.assertIsNone(self.assertDoesNotFault(None, "notify", path, 5, 2))
+
+ self.assertEqual(5, removeSecurityProxy(repository).loose_object_count)
+ self.assertEqual(2, removeSecurityProxy(repository).pack_count)
+ self.assertEqual(
+ datetime.now(pytz.timezone('UTC')).date(),
+ removeSecurityProxy(repository).date_last_scanned.date())
+
def test_authenticateWithPassword(self):
self.assertFault(
faults.Unauthorized, None,