]> git.corax.cc Git - foundry/commitdiff
dispatchbot: Create a new context for test requests
authorMatthias Kruk <m@m10k.eu>
Fri, 3 Sep 2021 13:00:54 +0000 (22:00 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 3 Sep 2021 13:00:54 +0000 (22:00 +0900)
The function that is responsible for sending test requests in
dispatchbot calls `false' (as a placeholder) where a new foundry
context should be created, preventing the function from sending a
test request.
This commit changes dispatchbot so that it creates a new context
before sending a test request.

dispatchbot.sh

index d3440560681ce633edd031ab9a670db8a1fb27cc..23570146370320f893c03b80ab6ca4790a5d328a 100755 (executable)
@@ -68,7 +68,8 @@ emit_testrequest() {
        local repository
        local branch
        local commit
-       local tid
+       local context
+       local project
 
        local testrequest
 
@@ -78,17 +79,24 @@ emit_testrequest() {
                return 1
        fi
 
-       if ! tid=$( false ); then
+       project="${repository##*/}"
+
+       if ! context=$(foundry_context_new "$project"); then
                return 1
        fi
 
-       if ! testrequest=$(foundry_msg_testrequest_new "$tid" \
+       log_debug "Created context $context for $project"
+
+       if ! testrequest=$(foundry_msg_testrequest_new "$context"    \
                                                       "$repository" \
-                                                      "$branch" \
+                                                      "$branch"     \
                                                       "$commit"); then
+               log_error "Could not make test request"
                return 1
        fi
 
+       log_debug "Sending test request $endpoint -> pub/testbot"
+
        if ! ipc_endpoint_send "$endpoint" "pub/testbot" "$testrequest"; then
                return 1
        fi
@@ -240,6 +248,8 @@ _handle_commit() {
 
        case "$branch" in
                "testing")
+                       log_debug "Commit on \"testing\" branch -> sending test request"
+
                        if ! emit_testrequest "$endpoint" "$msg" \
                                              "$repository" "$branch"; then
                                return 1
@@ -311,41 +321,36 @@ _handle_notification() {
 
        local fmsg
        local type
+       declare -A handlers
 
-       fmsg=$(foundry_msg_from_ipc_msg "$msg")
-       type="$?"
+       handlers["build"]=_handle_build
+       handlers["commit"]=_handle_commit
+       handlers["test"]=_handle_test
+       handlers["sign"]=_handle_sign
+       handlers["merge"]=_handle_merge
 
-       case "$type" in
-               "$__foundry_msg_type_build")
-                       _handle_build "$endpoint" "$fmsg"
-                       ;;
-
-               "$__foundry_msg_type_commit")
-                       _handle_commit "$endpoint" "$fmsg"
-                       ;;
+       if ! fmsg=$(ipc_msg_get_data "$msg"); then
+               log_warn "Dropping message without data"
+               return 1
+       fi
 
-               "$__foundry_msg_type_test")
-                       _handle_test "$endpoint" "$fmsg"
-                       ;;
+       if ! type=$(foundry_msg_get_type "$fmsg"); then
+               log_warn "Dropping message without type"
+               return 1
+       fi
 
-               "$__foundry_msg_type_sign")
-                       _handle_sign "$endpoint" "$fmsg"
-                       ;;
+       log_debug "Received $type message"
 
-               "$__foundry_msg_type_merge")
-                       _handle_merge "$endpoint" "$fmsg"
-                       ;;
+       if ! array_contains "$type" "${!handlers[@]}"; then
+               log_warn "Unexpected message type: $type"
+               return 1
+       fi
 
-               255)
-                       log_warn "Invalid message received"
-                       return 1
-                       ;;
+       log_debug "Message is handled by ${handlers[$type]}"
 
-               *)
-                       log_warn "Unexpected message type: $type"
-                       return 1
-                       ;;
-       esac
+       if ! "${handlers[$type]}" "$endpoint" "$fmsg"; then
+               return 1
+       fi
 
        return 0
 }
@@ -406,7 +411,7 @@ main() {
                return 1
        fi
 
-       if ! include "log" "opt" "ipc" "inst" "foundry/msg"; then
+       if ! include "log" "opt" "ipc" "inst" "foundry/msg" "foundry/context"; then
                return 1
        fi