Move some of the build diff logic to the buildfarm package.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 20 Dec 2010 00:17:38 +0000 (01:17 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 20 Dec 2010 00:17:38 +0000 (01:17 +0100)
buildfarm/build.py
import-and-analyse.py

index e8f9664..fae37a1 100644 (file)
@@ -614,3 +614,26 @@ class BuildResultStore(object):
         if build is None:
             raise NoSuchBuildError(tree, host, compiler)
         return build
+
+
+class BuildDiff(object):
+    """Represents the difference between two builds."""
+
+    def __init__(self, tree, old, new):
+        self.tree = tree
+        self.old = old
+        self.new = new
+        self.new_rev = new.revision_details()
+        self.new_status = new.status()
+
+        self.old_rev = old.revision_details()
+        self.old_status = old.status()
+
+    def is_regression(self):
+        """Is there a regression in new build since old build?"""
+        return self.new_status.regressed_since(self.old_status)
+
+    def revisions(self):
+        """Returns the revisions introduced since old in new."""
+        branch = self.tree.get_branch()
+        return branch.log(from_rev=self.new.revision, exclude_revs=set([self.old.revision]))
index 9df77a3..375c4ba 100755 (executable)
@@ -11,6 +11,7 @@ on recent commits.
 """
 
 from buildfarm.build import (
+    BuildDiff,
     MissingRevisionInfo,
     NoSuchBuildError,
     )
@@ -37,23 +38,17 @@ smtp.connect()
 
 def check_and_send_mails(cur, old):
     t = buildfarm.trees[cur.tree]
+    diff = BuildDiff(t, old, cur)
 
-    cur_rev = cur.revision_details()
-    cur_status = cur.status()
-
-    old_rev = old.revision_details()
-    old_status = old.status()
-
-    if not cur_status.regressed_since(old_status):
+    if not diff.is_regression():
         if opts.verbose >= 3:
-            print "... hasn't regressed since %s: %s" % (old_rev, old_status)
+            print "... hasn't regressed since %s: %s" % (diff.old_rev, diff.old_status)
         return
 
-    branch = t.get_branch()
     recipients = set()
     change_log = ""
 
-    for rev in branch.log(from_rev=cur.revision, exclude_revs=set([old.revision])):
+    for rev in diff.revisions():
         recipients.add(rev.author)
         recipients.add(rev.committer)
         change_log += """
@@ -82,15 +77,15 @@ The build may have been broken by one of the following commits:
         "change_log": change_log,
         "scm": t.scm,
         "branch": t.branch,
-        "cur_rev": cur_rev,
-        "old_rev": old_rev,
-        "cur_status": cur_status,
-        "old_status": old_status,
+        "cur_rev": diff.new_rev,
+        "old_rev": diff.old_rev,
+        "cur_status": diff.new_status,
+        "old_status": diff.old_status,
         "build_link": build_uri("http://build.samba.org/build.cgi", cur)
         }
 
     msg = MIMEText(body)
-    msg["Subject"] = "BUILD of %s:%s BROKEN on %s with %s AT REVISION %s" % (cur.tree, t.branch, cur.host, cur.compiler, cur_rev)
+    msg["Subject"] = "BUILD of %s:%s BROKEN on %s with %s AT REVISION %s" % (cur.tree, t.branch, cur.host, cur.compiler, diff.new_rev)
     msg["From"] = "\"Build Farm\" <build@samba.org>"
     msg["To"] = ",".join(recipients)
     if not opts.dry_run: