Roll submit hooks into general hook script
authorGreg Brockman <gdb@mit.edu>
Tue, 24 Aug 2010 04:26:58 +0000 (00:26 -0400)
committerGreg Brockman <gdb@mit.edu>
Tue, 24 Aug 2010 05:45:45 +0000 (01:45 -0400)
build-hooks/failed-submit [changed from file to symlink]
build-hooks/post-build
build-hooks/post-submit [changed from file to symlink]
build-hooks/pre-build [changed from file to symlink]

deleted file mode 100755 (executable)
index 6e288c814f8b1627a0bc92305ff6580ca55a5b36..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/sh
-
-set -e
-set -u
-
-escape() {
-    echo "$1" | sed -e 's/@/@@/g'
-}
-
-pocket=$(escape "$1")
-package=$(escape "$2")
-commit=$(escape "$3")
-principal=$(escape "$4")
-
-base=build.hooks.failed_submit.zephyr
-class=$(invirt-getconf "$base.class" 2>/dev/null || :)
-instance=$(invirt-getconf "$base.instance" 2>/dev/null || :)
-zsig=$(invirt-getconf "$base.zsig" 2>/dev/null || :)
-
-if [ -z "$class" ]; then
-  echo "I don't know where to send a commit zephyr!" >&2
-  echo "Please provide a value for $base.class in" >&2
-  echo "your invirt config file." >&2
-  exit 1
-fi
-
-(echo "A new job has @{@color(red)failed} to be submitted to the Invirtibuilder:"
- echo
- echo "pocket: $pocket"
- echo "package: $package"
- echo "commit: $commit"k
- echo "principal: $principal"
- echo
- echo -n "Failure: ";
- ( cat | sed -e 's/@/@@/g' ) ) | zwrite -c "$class" -i "${instance:-$commit}" -s "${zsig:-failed-submit}: $pocket" -d
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..b3ca0242fcf1583721bd213a4b9e3994325bd1f2
--- /dev/null
@@ -0,0 +1 @@
+post-build
\ No newline at end of file
index 10ac757..0fcaee6 100755 (executable)
@@ -76,9 +76,22 @@ Branch %(pocket)s has been advanced to %(short_commit)s.
 (Build %(build_id)s was submitted by %(principal)s at %(inserted_at)s.)""" % values
     return msg
 
 (Build %(build_id)s was submitted by %(principal)s at %(inserted_at)s.)""" % values
     return msg
 
+def submit_completion_msg(succeeded, values, verbose=True, success=lambda x: x, failure=lambda x: x):
+    values = dict(values)
+    if succeeded:
+        values['result'] = success(values['result'])
+    else:
+        values['result'] = failure(values['result'])
+    msg = """Submission of %(commit)s to be built in %(pocket)s %(result)s.
+Build submitted by %(principal)s.""" % values
+    return msg
+
+
 # Names of hooks
 POST_BUILD = 'post-build'
 FAILED_BUILD = 'failed-build'
 # Names of hooks
 POST_BUILD = 'post-build'
 FAILED_BUILD = 'failed-build'
+POST_SUBMIT = 'post-submit'
+FAILED_SUBMIT = 'failed-submit'
 
 # Types of communication
 
 
 # Types of communication
 
@@ -87,9 +100,13 @@ MAIL = 'mail'
 
 message_generators = {
     ZEPHYR : { POST_BUILD : build_completion_msg,
 
 message_generators = {
     ZEPHYR : { POST_BUILD : build_completion_msg,
-               FAILED_BUILD : build_completion_msg },
+               FAILED_BUILD : build_completion_msg,
+               POST_SUBMIT : submit_completion_msg,
+               FAILED_SUBMIT : submit_completion_msg },
     MAIL   : { POST_BUILD : build_completion_msg,
     MAIL   : { POST_BUILD : build_completion_msg,
-               FAILED_BUILD : build_completion_msg }
+               FAILED_BUILD : build_completion_msg,
+               POST_SUBMIT : submit_completion_msg,
+               FAILED_SUBMIT : submit_completion_msg }
     }
 
 def zephyr_escape(m):
     }
 
 def zephyr_escape(m):
@@ -113,6 +130,10 @@ def main():
             hook_config = config.build.hooks.post_build
         elif prog == FAILED_BUILD:
             hook_config = config.build.hooks.failed_build
             hook_config = config.build.hooks.post_build
         elif prog == FAILED_BUILD:
             hook_config = config.build.hooks.failed_build
+        elif prog == POST_SUBMIT:
+            hook_config = config.build.hooks.post_submit
+        elif prog == FAILED_SUBMIT:
+            hook_config = config.build.hooks.failed_submit
         else:
             parser.error('hook script invoked with unrecognized name %s' % prog)
             return 2
         else:
             parser.error('hook script invoked with unrecognized name %s' % prog)
             return 2
@@ -148,6 +169,23 @@ def main():
             assert prog == FAILED_BUILD
             values['result'] = 'failed'
             succeeded = False
             assert prog == FAILED_BUILD
             values['result'] = 'failed'
             succeeded = False
+    elif prog in [POST_SUBMIT, FAILED_SUBMIT]:
+        if len(args) != 4:
+            parser.set_usage('Usage: %prog [options] pocket package commit principal')
+            parser.print_help()
+            return 2
+        values = { 'pocket' : args[0],
+                   'package' : args[1],
+                   'commit' : args[2],
+                   'principal' : args[3],
+                   'default_instance' : 'submission',
+                   'default_subject' : 'Submission %(result)s: %(package)s %(version)s in %(pocket)s'}
+        if prog == POST_SUBMIT:
+            values['result'] = 'succeeded'
+            succeeded = True
+        else:
+            values['result'] = 'failed'
+            succeeded = False
     else:
         raise AssertionError('Impossible state')
 
     else:
         raise AssertionError('Impossible state')
 
deleted file mode 100755 (executable)
index 294818a8b1ea1a8cea92161c5aee2e281cb555ba..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-set -e
-set -u
-
-escape() {
-    echo "$1" | sed -e 's/@/@@/g'
-}
-
-pocket=$(escape "$1")
-package=$(escape "$2")
-commit=$(escape "$3")
-principal=$(escape "$4")
-
-base=build.hooks.post_submit.zephyr
-class=$(invirt-getconf "$base.class" 2>/dev/null || :)
-instance=$(invirt-getconf "$base.instance" 2>/dev/null || :)
-zsig=$(invirt-getconf "$base.zsig" 2>/dev/null || :)
-
-if [ -z "$class" ]; then
-  echo "I don't know where to send a commit zephyr!" >&2
-  echo "Please provide a value for $base.class in" >&2
-  echo "your invirt config file." >&2
-  exit 1
-fi
-
-(echo "A new job has been submitted to the Invirtibuilder:";
- echo;
- echo "pocket: $pocket";
- echo "package: $package";
- echo "commit: $commit";
- echo "principal: $principal") | zwrite -c "$class" -i "${instance:-$commit}" -s "${zsig:-Git}: $pocket" -d
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..b3ca0242fcf1583721bd213a4b9e3994325bd1f2
--- /dev/null
@@ -0,0 +1 @@
+post-build
\ No newline at end of file
deleted file mode 100755 (executable)
index 68c3c572ffa1ce65f4170ea4c2e91ac0fa1942cc..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-set -e
-set -u
-
-escape() {
-    echo "$1" | sed -e 's/@/@@/g'
-}
-
-build_id=$(escape "$1")
-pocket=$(escape "$2")
-package=$(escape "$3")
-commit=$(escape "$4")
-principal=$(escape "$5")
-version=$(escape "$6")
-inserted_at=$(escape "$7")
-
-base=build.hooks.pre_build.zephyr
-class=$(invirt-getconf "$base.class" 2>/dev/null || :)
-instance=$(invirt-getconf "$base.instance" 2>/dev/null || :)
-zsig=$(invirt-getconf "$base.zsig" 2>/dev/null || :)
-
-if [ -z "$class" ]; then
-  echo "I don't know where to send a commit zephyr!" >&2
-  echo "Please provide a value for $base.class in" >&2
-  echo "your invirt config file." >&2
-  exit 1
-fi
-
-(echo "About to begin an Invirtibuild of $package v$version in $pocket."
- echo "from commit $commit.";
- echo
- echo "(Build $build_id was submitted by $principal at $inserted_at.)") | zwrite -c "$class" -i "${instance:-build_$build_id}" -s "${zsig:-pre-build}: $pocket" -d
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..b3ca0242fcf1583721bd213a4b9e3994325bd1f2
--- /dev/null
@@ -0,0 +1 @@
+post-build
\ No newline at end of file