]> git.corax.cc Git - foundry/commitdiff
dispatchbot: Send signrequest when a build succeeds
authorMatthias Kruk <m@m10k.eu>
Sun, 26 Sep 2021 06:55:39 +0000 (15:55 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 26 Sep 2021 06:55:39 +0000 (15:55 +0900)
Because handling of build notifications is not completely implemented
in dispatchbot, no sign requests are emitted when a build has succeeded.
This commit amends the dispatchbot implementation to correctly handle
build notifications, and to send sign requests whenever a successful
build has been observed.

dispatchbot.sh

index 8de69fa37bc55ab5fb25f665742e182fdb58832d..b57ecd5be0cd547101dd8785c6cdbeecab5ce048 100755 (executable)
@@ -2,30 +2,26 @@
 
 emit_signrequest() {
        local endpoint="$1"
-       local buildmsg="$2"
+       local context="$2"
+       local artifacts=("${@:3}")
 
        local signrequest
-       local artifacts
-       local artifact
-       local have_artifacts
-
-       artifacts=()
-       have_artifacts=false
+       local dst
 
-       while read -r artifact; do
-               artifacts+=("$artifact")
-               have_artifacts=true
-       done < <(foundry_msg_build_get_artifacts "$buildmsg")
+       dst="pub/signbot"
 
-       if ! "$have_artifacts"; then
+       if (( ${#artifacts[@]} == 0 )); then
+               log_warn "Nothing to be signed for $context"
                return 1
        fi
 
-       if ! signrequest=$(foundry_msg_signrequest_new "$tid" "${artifacts[@]}"); then
+       if ! signrequest=$(foundry_msg_signrequest_new "$context" "${artifacts[@]}"); then
+               log_error "Could not make sign request for $context"
                return 1
        fi
 
-       if ! ipc_endpoint_send "$endpoint" "pub/signbot" "$signrequest"; then
+       if ! ipc_endpoint_send "$endpoint" "$dst" "$signrequest"; then
+               log_error "Could not send signrequest to $dst"
                return 1
        fi
 
@@ -153,18 +149,39 @@ _handle_build() {
        local endpoint="$1"
        local msg="$2"
 
+       local context
+       local artifacts
+       local artifact
        local result
 
+       artifacts=()
+
+       if ! context=$(foundry_msg_build_get_context "$msg"); then
+               log_warn "Dropping message without context"
+               return 0
+       fi
+
        if ! result=$(foundry_msg_build_get_result "$msg"); then
-               return 1
+               log_warn "Dropping message without result"
+               return 0
        fi
 
-       if (( result == 0 )); then
-               if ! emit_signrequest "$msg"; then
-                       return 1
-               fi
+       if (( result != 0 )); then
+               log_warn "Not emitting sign request for failed build $context"
+               return 0
        fi
 
+       while read -r artifact; do
+               artifacts+=("$artifact")
+       done < <(foundry_msg_build_get_artifacts "$msg")
+
+       if ! emit_signrequest "$endpoint" "$context" "${artifacts[@]}"; then
+               log_error "Could not emit sign request for $context"
+               return 1
+       fi
+
+       log_info "Sign request for $context emitted."
+
        return 0
 }