← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/codeimport-create-hosting into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/codeimport-create-hosting into lp:launchpad with lp:~cjwatson/launchpad/codeimport-worker-refactor as a prerequisite.

Commit message:
Create repository on hosting service when creating a Git-targeted code import.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1469459 in Launchpad itself: "import external code into a LP git repo (natively)"
  https://bugs.launchpad.net/launchpad/+bug/1469459

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/codeimport-create-hosting/+merge/308132

This is normally done by the XML-RPC endpoint that calls IGitNamespace.createRepository, but code import creation doesn't go through that.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/codeimport-create-hosting into lp:launchpad.
=== modified file 'lib/lp/code/mail/tests/test_codeimport.py'
--- lib/lp/code/mail/tests/test_codeimport.py	2016-10-03 17:00:56 +0000
+++ lib/lp/code/mail/tests/test_codeimport.py	2016-10-11 14:42:21 +0000
@@ -11,6 +11,7 @@
     RevisionControlSystems,
     TargetRevisionControlSystems,
     )
+from lp.code.tests.helpers import GitHostingFixture
 from lp.services.mail import stub
 from lp.testing import (
     login_person,
@@ -95,6 +96,7 @@
 
     def test_git_to_git_import(self):
         # Test the email for a new git-to-git import.
+        self.useFixture(GitHostingFixture())
         eric = self.factory.makePerson(name='eric')
         fooix = self.factory.makeProduct(name='fooix')
         # Eric needs to be logged in for the mail to be sent.

=== modified file 'lib/lp/code/model/codeimport.py'
--- lib/lp/code/model/codeimport.py	2016-10-03 17:00:56 +0000
+++ lib/lp/code/model/codeimport.py	2016-10-11 14:42:21 +0000
@@ -59,6 +59,7 @@
     )
 from lp.code.interfaces.codeimportevent import ICodeImportEventSet
 from lp.code.interfaces.codeimportjob import ICodeImportJobWorkflow
+from lp.code.interfaces.githosting import IGitHostingClient
 from lp.code.interfaces.gitnamespace import get_git_namespace
 from lp.code.interfaces.gitrepository import IGitRepository
 from lp.code.mail.codeimport import code_import_updated
@@ -308,6 +309,8 @@
             import_target = namespace.createRepository(
                 repository_type=GitRepositoryType.IMPORTED, name=branch_name,
                 registrant=registrant)
+            hosting_path = import_target.getInternalPath()
+            getUtility(IGitHostingClient).create(hosting_path)
 
         code_import = CodeImport(
             registrant=registrant, owner=owner, target=import_target,

=== modified file 'lib/lp/code/model/tests/test_codeimport.py'
--- lib/lp/code/model/tests/test_codeimport.py	2016-10-03 17:00:56 +0000
+++ lib/lp/code/model/tests/test_codeimport.py	2016-10-11 14:42:21 +0000
@@ -43,6 +43,7 @@
     )
 from lp.code.model.codeimportresult import CodeImportResult
 from lp.code.tests.codeimporthelpers import make_running_import
+from lp.code.tests.helpers import GitHostingFixture
 from lp.registry.interfaces.person import IPersonSet
 from lp.testing import (
     login,
@@ -66,15 +67,22 @@
             "supports_source_cvs": True,
             "supports_source_svn": True,
             "supports_source_bzr": True,
+            "needs_hosting_fixture": False,
             }),
         ("GitRepository", {
             "target_rcs_type": TargetRevisionControlSystems.GIT,
             "supports_source_cvs": False,
             "supports_source_svn": False,
             "supports_source_bzr": False,
+            "needs_hosting_fixture": True,
             }),
         ]
 
+    def setUp(self, *args, **kwargs):
+        super(TestCodeImportBase, self).setUp(*args, **kwargs)
+        if self.needs_hosting_fixture:
+            self.hosting_fixture = self.useFixture(GitHostingFixture())
+
 
 class TestCodeImportCreation(TestCodeImportBase):
     """Test the creation of CodeImports."""
@@ -159,6 +167,11 @@
             code_import.review_status)
         # A job is created for the import.
         self.assertIsNot(None, code_import.import_job)
+        if self.needs_hosting_fixture:
+            # The repository is created on the hosting service.
+            self.assertEqual(
+                (code_import.git_repository.getInternalPath(),),
+                self.hosting_fixture.create.extract_args()[0])
 
     def test_git_import_reviewed(self):
         """A new git import is always reviewed by default."""
@@ -175,6 +188,11 @@
             code_import.review_status)
         # A job is created for the import.
         self.assertIsNot(None, code_import.import_job)
+        if self.needs_hosting_fixture:
+            # The repository is created on the hosting service.
+            self.assertEqual(
+                (code_import.git_repository.getInternalPath(),),
+                self.hosting_fixture.create.extract_args()[0])
 
     def test_bzr_import_reviewed(self):
         """A new bzr import is always reviewed by default."""
@@ -352,7 +370,8 @@
 
     def setUp(self):
         # Log in a VCS Imports member.
-        TestCaseWithFactory.setUp(self, 'david.allouche@xxxxxxxxxxxxx')
+        super(TestCodeImportStatusUpdate, self).setUp(
+            'david.allouche@xxxxxxxxxxxxx')
         self.import_operator = getUtility(IPersonSet).getByEmail(
             'david.allouche@xxxxxxxxxxxxx')
         # Remove existing jobs.
@@ -484,7 +503,7 @@
     layer = LaunchpadFunctionalLayer
 
     def setUp(self):
-        TestCaseWithFactory.setUp(self)
+        super(TestCodeImportResultsAttribute, self).setUp()
         self.code_import = self.factory.makeCodeImport(
             target_rcs_type=self.target_rcs_type)
 
@@ -550,7 +569,7 @@
     layer = LaunchpadZopelessLayer
 
     def setUp(self):
-        TestCaseWithFactory.setUp(self)
+        super(TestConsecutiveFailureCount, self).setUp()
         login('no-priv@xxxxxxxxxxxxx')
         self.machine = self.factory.makeCodeImportMachine()
         self.machine.setOnline()
@@ -692,7 +711,7 @@
 
     def setUp(self):
         # Log in a VCS Imports member.
-        TestCaseWithFactory.setUp(self)
+        super(TestTryFailingImportAgain, self).setUp()
         login_person(getUtility(ILaunchpadCelebrities).vcs_imports.teamowner)
 
     def test_mustBeFailing(self):
@@ -751,7 +770,7 @@
 
     def setUp(self):
         # We have to be logged in to request imports
-        TestCaseWithFactory.setUp(self, user='no-priv@xxxxxxxxxxxxx')
+        super(TestRequestImport, self).setUp(user='no-priv@xxxxxxxxxxxxx')
 
     def test_requestsJob(self):
         code_import = self.factory.makeCodeImport(

=== modified file 'lib/lp/code/model/tests/test_codeimportjob.py'
--- lib/lp/code/model/tests/test_codeimportjob.py	2016-10-11 14:42:21 +0000
+++ lib/lp/code/model/tests/test_codeimportjob.py	2016-10-11 14:42:21 +0000
@@ -43,6 +43,7 @@
     make_finished_import,
     make_running_import,
     )
+from lp.code.tests.helpers import GitHostingFixture
 from lp.services.config import config
 from lp.services.database.constants import UTC_NOW
 from lp.services.librarian.interfaces import ILibraryFileAliasSet
@@ -1160,6 +1161,7 @@
         super(TestCodeImportJobMacaroonIssuer, self).setUp()
         login_for_code_imports()
         self.pushConfig("codeimport", macaroon_secret_key="some-secret")
+        self.useFixture(GitHostingFixture())
 
     def makeJob(self, target_rcs_type=TargetRevisionControlSystems.GIT):
         code_import = self.factory.makeCodeImport(

=== modified file 'lib/lp/code/tests/helpers.py'
--- lib/lp/code/tests/helpers.py	2016-09-07 03:43:36 +0000
+++ lib/lp/code/tests/helpers.py	2016-10-11 14:42:21 +0000
@@ -7,6 +7,7 @@
 __all__ = [
     'add_revision_to_branch',
     'get_non_existant_source_package_branch_unique_name',
+    'GitHostingFixture',
     'make_erics_fooix_project',
     'make_linked_package_branch',
     'make_merge_proposal_without_reviewers',


Follow ups