← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:ci-build-upload-job-repr into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:ci-build-upload-job-repr into launchpad:master.

Commit message:
Give CIBuildUploadJobs a more informative __repr__

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/425196

This is useful when hunting through job runner logs.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:ci-build-upload-job-repr into launchpad:master.
diff --git a/lib/lp/soyuz/model/archivejob.py b/lib/lp/soyuz/model/archivejob.py
index 499e83d..6fc15b2 100644
--- a/lib/lp/soyuz/model/archivejob.py
+++ b/lib/lp/soyuz/model/archivejob.py
@@ -248,6 +248,20 @@ class CIBuildUploadJob(ArchiveJobDerived):
         derived.job.requester = requester
         return derived
 
+    def __repr__(self):
+        """Returns an informative representation of the job."""
+        parts = [
+            "%s to upload %r to %s %s" % (
+                self.__class__.__name__,
+                self.ci_build,
+                self.archive.reference,
+                self.target_distroseries.getSuite(self.target_pocket),
+                ),
+            ]
+        if self.target_channel is not None:
+            parts.append(" {%s}" % self.target_channel)
+        return "<%s>" % "".join(parts)
+
     def getOopsVars(self):
         vars = super().getOopsVars()
         vars.extend([
diff --git a/lib/lp/soyuz/tests/test_archivejob.py b/lib/lp/soyuz/tests/test_archivejob.py
index 51eb6f2..922a267 100644
--- a/lib/lp/soyuz/tests/test_archivejob.py
+++ b/lib/lp/soyuz/tests/test_archivejob.py
@@ -154,6 +154,32 @@ class TestCIBuildUploadJob(TestCaseWithFactory):
 
     layer = LaunchpadZopelessLayer
 
+    def test_repr_no_channel(self):
+        archive = self.factory.makeArchive()
+        distroseries = self.factory.makeDistroSeries(
+            distribution=archive.distribution)
+        build = self.factory.makeCIBuild()
+        job = CIBuildUploadJob.create(
+            build, build.git_repository.owner, archive, distroseries,
+            PackagePublishingPocket.RELEASE)
+        self.assertEqual(
+            "<CIBuildUploadJob to upload %r to %s %s>" % (
+                build, archive.reference, distroseries.name),
+            repr(job))
+
+    def test_repr_channel(self):
+        archive = self.factory.makeArchive()
+        distroseries = self.factory.makeDistroSeries(
+            distribution=archive.distribution)
+        build = self.factory.makeCIBuild()
+        job = CIBuildUploadJob.create(
+            build, build.git_repository.owner, archive, distroseries,
+            PackagePublishingPocket.RELEASE, target_channel="edge")
+        self.assertEqual(
+            "<CIBuildUploadJob to upload %r to %s %s {edge}>" % (
+                build, archive.reference, distroseries.name),
+            repr(job))
+
     def test_getOopsVars(self):
         archive = self.factory.makeArchive()
         distroseries = self.factory.makeDistroSeries(