]> git.corax.cc Git - foundry/commitdiff
include/msg/*: Place all foundry messages in a base message
authorMatthias Kruk <m@m10k.eu>
Sun, 11 Jul 2021 06:32:19 +0000 (15:32 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 11 Jul 2021 06:32:19 +0000 (15:32 +0900)
To make foundry messages easily distinguishable, they should each be
placed in a base message that contains a property for the message type.
This commit modifies the modules for all of the foundry message types
so that they are enclosed in a base message.

include/msg/build.sh
include/msg/buildrequest.sh
include/msg/commit.sh
include/msg/dist.sh
include/msg/distrequest.sh
include/msg/merge.sh
include/msg/mergerequest.sh
include/msg/sign.sh
include/msg/signrequest.sh
include/msg/test.sh
include/msg/testrequest.sh

index a724ebbd913368157d52fc9ec367d2caf5d5a5d2..1c8c601f8481647eb368ca989b510bd77054c4d1 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_build_msgtype="build"
+
        return 0
 }
 
@@ -20,6 +22,7 @@ foundry_msg_build_new() {
        local artifact_array
        local log_array
        local json
+       local msg
 
        if ! artifact_array=$(json_array "${__foundry_msg_build_new_artifacts[@]}"); then
                return 1
@@ -39,7 +42,11 @@ foundry_msg_build_new() {
                return 1
        fi
 
-       echo "$json"
+       if ! msg=$(foundry_msg_new "$__foundry_msg_build_msgtype" "$json"); then
+               return 1
+       fi
+
+       echo "$msg"
        return 0
 }
 
@@ -48,7 +55,7 @@ foundry_msg_build_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -61,7 +68,7 @@ foundry_msg_build_get_repository() {
 
         local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -74,7 +81,7 @@ foundry_msg_build_get_branch() {
 
        local branch
 
-       if ! branch=$(json_object_get "$msg" "branch"); then
+       if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then
                return 1
        fi
 
@@ -87,7 +94,7 @@ foundry_msg_build_get_commit() {
 
        local commit
 
-       if ! commit=$(json_object_get "$msg" "commit"); then
+       if ! commit=$(foundry_msg_get_data_field "$msg" "commit"); then
                return 1
        fi
 
@@ -100,7 +107,7 @@ foundry_msg_build_get_result() {
 
        local result
 
-       if ! result=$(json_object_get "$msg" "result"); then
+       if ! result=$(foundry_msg_get_data_field "$msg" "result"); then
                return 1
        fi
 
@@ -113,7 +120,7 @@ foundry_msg_build_get_logs() {
 
        local logs
 
-       if ! logs=$(json_object_get "$msg" "logs[]"); then
+       if ! logs=$(foundry_msg_get_data_field "$msg" "logs[]"); then
                return 1
        fi
 
@@ -133,7 +140,7 @@ foundry_msg_build_get_artifacts() {
        query='artifacts[] | "\(.checksum) \(.uri)"'
        artifacts=()
 
-       if ! raw_artifacts=$(json_object_get "$msg" "$query"); then
+       if ! raw_artifacts=$(foundry_msg_get_data_field "$msg" "$query"); then
                return 1
        fi
 
index a75e92acbf99790c6e205b98a0f7d4df1448cae5..dc27d19c1988fb3545f78a16169265d345396228 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_buildrequest_msgtype="buildrequest"
+
        return 0
 }
 
@@ -15,6 +17,7 @@ foundry_msg_buildrequest_new() {
        local commit="$4"
 
        local json
+       local msg
 
        if ! json=$(json_object "tid" "$tid"               \
                                "repository" "$repository" \
@@ -23,7 +26,11 @@ foundry_msg_buildrequest_new() {
                return 1
        fi
 
-       echo "$json"
+       if ! msg=$(foundry_msg_new "$__foundry_msg_buildrequest_msgtype" "$json"); then
+               return 1
+       fi
+
+       echo "$msg"
        return 0
 }
 
@@ -32,7 +39,7 @@ foundry_msg_buildrequest_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -45,7 +52,7 @@ foundry_msg_buildrequest_get_repository() {
 
        local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -58,7 +65,7 @@ foundry_msg_buildrequest_get_branch() {
 
        local branch
 
-       if ! branch=$(json_object_get "$msg" "branch"); then
+       if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then
                return 1
        fi
 
@@ -71,7 +78,7 @@ foundry_msg_buildrequest_get_commit() {
 
        local commit
 
-       if ! commit=$(json_object_get "$msg" "commit"); then
+       if ! commit=$(foundry_msg_get_data_field "$msg" "commit"); then
                return 1
        fi
 
index d3b23b87101df168106e3452a5b694db98f60a1e..65befea77539681a2aeac3f51ae084340ff86802 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_commit_msgtype="commit"
+
        return 0
 }
 
@@ -13,29 +15,20 @@ foundry_msg_commit_new() {
        local branch="$2"
        local commit="$3"
 
+       local data
        local msg
 
-       if ! msg=$(json_object "repository" "$repository" \
-                              "commit"     "$commit"     \
-                              "branch"     "$branch"); then
+       if ! data=$(json_object "repository" "$repository" \
+                               "commit"     "$commit"     \
+                               "branch"     "$branch"); then
                return 1
        fi
 
-       echo "$msg"
-       return 0
-}
-
-_foundry_msg_commit_get_field() {
-       local msg="$1"
-       local field="$2"
-
-       local value
-
-       if ! value=$(echo "$msg" | jq -e -r ".$field"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_commit_msgtype" "$data"); then
                return 1
        fi
 
-       echo "$value"
+       echo "$msg"
        return 0
 }
 
@@ -44,7 +37,7 @@ foundry_msg_commit_get_repository() {
 
        local repository
 
-       if ! repository=$(_foundry_msg_commit_get_field "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -57,7 +50,7 @@ foundry_msg_commit_get_branch() {
 
        local branch
 
-       if ! branch=$(_foundry_msg_commit_get_field "$msg" "branch"); then
+       if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then
                return 1
        fi
 
@@ -70,7 +63,7 @@ foundry_msg_commit_get_commit() {
 
        local commit
 
-       if ! commit=$(_foundry_msg_commit_get_field "$msg" "commit"); then
+       if ! commit=$(foundry_msg_get_data_field "$msg" "commit"); then
                return 1
        fi
 
index 198859987834b53a88425a11ef22808a02fd0816..b018b30e8c1a749b1a36be6b6c545b4f4b7e86cb 100644 (file)
@@ -5,48 +5,31 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_dist_msgtype="dist"
+
        return 0
 }
 
 foundry_msg_dist_new() {
        local tid="$1"
        local repository="$2"
-       local artifact_data=("${@:3}")
+       local artifacts=("${@:3}")
 
+       local artifacts_json
+       local json
        local msg
-       local artifacts
-       local artifact_array
-       local i
 
-       if (( ${#artifact_data} & 1 != 0 )); then
+       if ! artifacts_json=$(json_array "${artifacts[@]}"); then
                return 1
        fi
 
-       artifacts=()
-
-       for (( i = 0; i + 1 < ${#artifact_data[@]}; i += 2 )); do
-               local artifact
-               local uri
-               local checksum
-
-               uri="${artifact_data[$i]}"
-               checksum="${artifact_data[$((i + 1))]}"
-
-               if ! artifact=$(foundry_msg_artifact_new "$uri" \
-                                                        "$checksum"); then
-                       return 1
-               fi
-
-               artifacts+=("$artifact")
-       done
-
-       if ! artifact_array=$(json_array "${artifacts[@]}"); then
+        if ! json=$(json_object "tid"        "$tid"           \
+                               "repository" "$repository"    \
+                               "artifacts"  "$artifacts_json"); then
                return 1
        fi
 
-        if ! msg=$(json_object "tid"        "$tid"           \
-                              "repository" "$repository"    \
-                              "artifacts"  "$artifact_array"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_dist_msgtype" "$json"); then
                return 1
        fi
 
@@ -59,7 +42,7 @@ foundry_msg_dist_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -72,7 +55,7 @@ foundry_msg_dist_get_repository() {
 
        local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -92,7 +75,7 @@ foundry_msg_dist_get_artifacts() {
        query='artifacts[] | "\(.checksum) \(.uri)"'
        artifacts=()
 
-       if ! raw_artifacts=$(json_object_get "$msg" "$query"); then
+       if ! raw_artifacts=$(foundry_msg_get_data_field "$msg" "$query"); then
                return 1
        fi
 
index 7f9f53e55e2c3074ab79348969c0cec67064ef3e..823c1d03a6721bcb19271368d9b822c78a5bdffe 100644 (file)
@@ -5,46 +5,33 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_distrequest_msgtype="distrequest"
+
        return 0
 }
 
 foundry_msg_distrequest_new() {
        local tid="$1"
-       local artifact_data=("${@:2}")
+       local artifacts=("${@:2}")
 
-       local artifacts_array
-       local artifacts
-       local distrequest
-       local i
+       local artifacts_json
+       local json
+       local msg
 
-       if ! (( $# & 1 )); then
-               # Invalid number of arguments
+       if ! artifacts_json=$(json_array "${artifacts[@]}"); then
                return 1
        fi
 
-       artifacts=()
-
-       for (( i = 0; (i + 1) < $#; i += 2 )); do
-               local artifact
-
-               if ! artifact=$(foundry_msg_artifact_new "${artifact_data[$i]}" \
-                                                        "${artifact_data[$((i+1))]}"); then
-                       continue
-               fi
-
-               artifacts+=("$artifact")
-       done
-
-       if ! artifacts_array=$(json_array "${artifacts[@]}"); then
+       if ! json=$(json_object "tid"       "$tid"           \
+                               "artifacts" "$artifacts_json"); then
                return 1
        fi
 
-       if ! distrequest=$(json_object "tid"       "$tid"            \
-                                      "artifacts" "$artifacts_array"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_distrequest_msgtype" "$json"); then
                return 1
        fi
 
-       echo "$distrequest"
+       echo "$msg"
        return 0
 }
 
@@ -53,7 +40,7 @@ foundry_msg_distrequest_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$distrequest" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$distrequest" "tid"); then
                return 1
        fi
 
@@ -69,14 +56,17 @@ foundry_msg_distrequest_get_artifacts() {
        local artifact
        local checksum
        local uri
+       local query
+
+       query='artifacts[] | "\(.checksum) \(.uri)"'
 
-       if ! raw_artifacts=$(json_object_get "$distrequest" 'artifacts[] | "\(.checksum) \(.uri)"'); then
+       if ! raw_artifacts=$(foundry_msg_get_data_field "$distrequest" \
+                                                       "$query"); then
                return 1
        fi
 
        while read -r checksum uri; do
-               if ! artifact=$(json_object "uri" "$uri" \
-                                           "checksum" "$checksum"); then
+               if ! artifact=$(foundry_msg_artifact_new "$uri" "$checksum"); then
                        return 1
                fi
 
index 3c3ae9f0db8045469b4b746b51535f109a318aa7..412a5bc35ab08aca57b7b659e9294e22deb52cdc 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_merge_msgtype="merge"
+
        return 0
 }
 
@@ -17,6 +19,7 @@ foundry_msg_merge_new() {
        local log="$6"
 
        local json
+       local msg
 
        if ! json=$(json_object "tid"        "$tid"        \
                                "repository" "$repository" \
@@ -27,7 +30,11 @@ foundry_msg_merge_new() {
                return 1
        fi
 
-       echo "$json"
+       if ! msg=$(foundry_msg_new "$__foundry_msg_merge_msgtype" "$json"); then
+               return 1
+       fi
+
+       echo "$msg"
        return 0
 }
 
@@ -36,7 +43,7 @@ foundry_msg_merge_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -49,7 +56,7 @@ foundry_msg_merge_get_repository() {
 
        local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -62,7 +69,7 @@ foundry_msg_merge_get_source_branch() {
 
        local srcbranch
 
-       if ! srcbranch=$(json_object_get "$msg" "source_branch"); then
+       if ! srcbranch=$(foundry_msg_get_data_field "$msg" "srcbranch"); then
                return 1
        fi
 
@@ -75,7 +82,7 @@ foundry_msg_merge_get_destination_branch() {
 
        local dstbranch
 
-       if ! dstbranch=$(json_object_get "$msg" "destination_branch"); then
+       if ! dstbranch=$(foundry_msg_get_data_field "$msg" "dstbranch"); then
                return 1
        fi
 
@@ -88,7 +95,7 @@ foundry_msg_merge_get_status() {
 
        local status
 
-       if ! status=$(json_object_get "$msg" "status"); then
+       if ! status=$(foundry_msg_get_data_field "$msg" "status"); then
                return 1
        fi
 
@@ -101,7 +108,7 @@ foundry_msg_merge_get_log() {
 
        local log
 
-       if ! log=$(json_object_get "$msg" "log"); then
+       if ! log=$(foundry_msg_get_data_field "$msg" "log"); then
                return 1
        fi
 
index b95a5fa21baa6f080c9cbfe1dabeee369364706f..ad70eff09e00635928e1987b02fe30567a1f3e78 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_mergerequest_msgtype="mergerequest"
+
        return 0
 }
 
@@ -15,6 +17,7 @@ foundry_msg_mergerequest_new() {
        local dstbranch="$4"
 
        local json
+       local msg
 
        if ! json=$(json_object "tid" "$tid"                     \
                                "repository" "$repository"       \
@@ -23,7 +26,12 @@ foundry_msg_mergerequest_new() {
                return 1
        fi
 
-       echo "$json"
+       if ! msg=$(foundry_msg_new "$__foundry_msg_mergerequest_msgtype" \
+                                  "$json"); then
+               return 1
+       fi
+
+       echo "$msg"
        return 0
 }
 
@@ -32,10 +40,11 @@ foundry_msg_mergerequest_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
+       echo "$tid"
        return 0
 }
 
@@ -44,7 +53,7 @@ foundry_msg_mergerequest_get_repository() {
 
        local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -57,7 +66,7 @@ foundry_msg_mergerequest_get_source_branch() {
 
        local srcbranch
 
-       if ! srcbranch=$(json_object_get "$msg" "source_branch"); then
+       if ! srcbranch=$(foundry_msg_get_data_field "$msg" "source_branch"); then
                return 1
        fi
 
@@ -70,7 +79,7 @@ foundry_msg_mergerequest_get_destination_branch() {
 
        local dstbranch
 
-       if ! dstbranch=$(json_object_get "$msg" "destination_branch"); then
+       if ! dstbranch=$(foundry_msg_get_data_field "$msg" "destination_branch"); then
                return 1
        fi
 
index eff9e358a3fb37e7489dd35f9f529d6548bc92b0..7fb3e706f6c432d66239dd74e627c1a7a1a31429 100644 (file)
@@ -5,48 +5,31 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_sign_msgtype="sign"
+
        return 0
 }
 
 foundry_msg_sign_new() {
        local tid="$1"
        local key="$2"
-       local artifact_data=("${@:3}")
+       local artifacts=("${@:3}")
 
+       local artifacts_json
+       local json
        local msg
-       local artifacts
-       local artifact_array
-       local i
 
-       if (( ${#artifact_data} & 1 != 0 )); then
+       if ! artifacts_json=$(json_array "${artifacts[@]}"); then
                return 1
        fi
 
-       artifacts=()
-
-       for (( i = 0; i + 1 < ${#artifact_data[@]}; i += 2 )); do
-               local artifact
-               local uri
-               local checksum
-
-               uri="${artifact_data[$i]}"
-               checksum="${artifact_data[$((i + 1))]}"
-
-               if ! artifact=$(foundry_msg_artifact_new "$uri" \
-                                                        "$checksum"); then
-                       return 1
-               fi
-
-               artifacts+=("$artifact")
-       done
-
-       if ! artifact_array=$(json_array "${artifacts[@]}"); then
+       if ! json=$(json_object "tid"       "$tid"           \
+                               "key"       "$key"           \
+                               "artifacts" "$artifacts_json"); then
                return 1
        fi
 
-        if ! msg=$(json_object "tid"       "$tid"           \
-                              "key"       "$key"           \
-                              "artifacts" "$artifact_array"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_sign_msgtype" "$json"); then
                return 1
        fi
 
@@ -59,7 +42,7 @@ foundry_msg_sign_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -72,7 +55,7 @@ foundry_msg_sign_get_key() {
 
        local key
 
-       if ! key=$(json_object_get "$msg" "key"); then
+       if ! key=$(foundry_msg_get_data_field "$msg" "key"); then
                return 1
        fi
 
@@ -92,7 +75,7 @@ foundry_msg_sign_get_artifacts() {
        query='artifacts[] | "\(.checksum) \(.uri)"'
        artifacts=()
 
-       if ! raw_artifacts=$(json_object_get "$msg" "$query"); then
+       if ! raw_artifacts=$(foundry_msg_get_data_field "$msg" "$query"); then
                return 1
        fi
 
index b11e101a8fe928792ceacbaf3c3bc5fb17d91935..bc162e0420d8e6aabf4f0df100ec2c958efd01c1 100644 (file)
@@ -5,46 +5,33 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_signrequest_msgtype="signrequest"
+
        return 0
 }
 
 foundry_msg_signrequest_new() {
        local tid="$1"
-       local artifact_data=("${@:2}")
+       local artifacts=("${@:2}")
 
-       local artifacts_array
-       local artifacts
-       local signrequest
-       local i
+       local artifacts_json
+       local json
+       local msg
 
-       if ! (( $# & 1 )); then
-               # Invalid number of arguments
+       if ! artifacts_json=$(json_array "${artifacts[@]}"); then
                return 1
        fi
 
-       artifacts=()
-
-       for (( i = 0; (i + 1) < $#; i += 2 )); do
-               local artifact
-
-               if ! artifact=$(foundry_msg_artifact_new "${artifact_data[$i]}" \
-                                                        "${artifact_data[$((i+1))]}"); then
-                       continue
-               fi
-
-               artifacts+=("$artifact")
-       done
-
-       if ! artifacts_array=$(json_array "${artifacts[@]}"); then
+       if ! json=$(json_object "tid"       "$tid"            \
+                               "artifacts" "$artifacts_json"); then
                return 1
        fi
 
-       if ! signrequest=$(json_object "tid"       "$tid"            \
-                                      "artifacts" "$artifacts_array"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_signrequest_msgtype" "$json"); then
                return 1
        fi
 
-       echo "$signrequest"
+       echo "$msg"
        return 0
 }
 
@@ -53,7 +40,7 @@ foundry_msg_signrequest_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$signrequest" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$signrequest" "tid"); then
                return 1
        fi
 
@@ -73,7 +60,7 @@ foundry_msg_signrequest_get_artifacts() {
        query='artifacts[] | "\(.checksum) \(.uri)"'
        artifacts=()
 
-       if ! raw_artifacts=$(json_object_get "$signrequest" "$query"); then
+       if ! raw_artifacts=$(foundry_msg_get_data_field "$signrequest" "$query"); then
                return 1
        fi
 
index 8aa16e3840414d3a7d1bc983318717e33034ce2c..f5ceea945f503c642b408665610a9aa9146779da 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_test_msgtype="test"
+
        return 0
 }
 
@@ -16,19 +18,24 @@ foundry_msg_test_new() {
        local result="$5"
        local logs=("${@:6}")
 
-       local logs_array
+       local logs_json
+       local json
        local msg
 
-       if ! logs_array=$(json_array "${logs[@]}"); then
+       if ! logs_json=$(json_array "${logs[@]}"); then
+               return 1
+       fi
+
+       if ! json=$(json_object "tid"        "$tid"        \
+                               "repository" "$repository" \
+                               "branch"     "$branch"     \
+                               "commit"     "$commit"     \
+                               "result"     "$result"     \
+                               "logs"       "$logs_json"); then
                return 1
        fi
 
-       if ! msg=$(json_object "tid"        "$tid"        \
-                              "repository" "$repository" \
-                              "branch"     "$branch"     \
-                              "commit"     "$commit"     \
-                              "result"     "$result"     \
-                              "logs"       "$logs_array"); then
+       if ! msg=$(foundry_msg_new "$__foundry_msg_test_msgtype" "$json"); then
                return 1
        fi
 
@@ -41,7 +48,7 @@ foundry_msg_test_get_tid() {
 
        local tid
 
-       if ! tid=$(json_object_get "$msg" "tid"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -54,7 +61,7 @@ foundry_msg_test_get_repository() {
 
        local repository
 
-       if ! repository=$(json_object_get "$msg" "repository"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -67,7 +74,7 @@ foundry_msg_test_get_branch() {
 
        local branch
 
-       if ! branch=$(json_object_get "$msg" "branch"); then
+       if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then
                return 1
        fi
 
@@ -80,7 +87,7 @@ foundry_msg_test_get_commit() {
 
        local commit
 
-       if ! commit=$(json_object_get "$msg" "commit"); then
+       if ! commit=$(foundry_msg_get_data_field "$msg" "commit"); then
                return 1
        fi
 
@@ -93,7 +100,7 @@ foundry_msg_test_get_result() {
 
        local result
 
-       if ! result=$(json_object_get "$msg" "result"); then
+       if ! result=$(foundry_msg_get_data_field "$msg" "result"); then
                return 1
        fi
 
@@ -106,7 +113,7 @@ foundry_msg_test_get_logs() {
 
        local logs
 
-       if ! logs=$(json_object_get "$msg" "logs[]"); then
+       if ! logs=$(foundry_msg_get_data_field "$msg" "logs[]"); then
                return 1
        fi
 
index ab9324c632fcafe91667ce92562d42d0ae2a56cd..d353a19f522cfc00c69b7bccd5c5f51477482f01 100644 (file)
@@ -5,6 +5,8 @@ __init() {
                return 1
        fi
 
+       declare -gxr __foundry_msg_testrequest_msgtype="testrequest"
+
        return 0
 }
 
@@ -15,6 +17,7 @@ foundry_msg_testrequest_new() {
        local commit="$4"
 
        local json
+       local msg
 
        if ! json=$(json_object "tid" "$tid"               \
                                "repository" "$repository" \
@@ -23,7 +26,11 @@ foundry_msg_testrequest_new() {
                return 1
        fi
 
-       echo "$json"
+       if ! msg=$(foundry_msg_new "$__foundry_msg_testrequest_msgtype" "$json"); then
+               return 1
+       fi
+
+       echo "$msg"
        return 0
 }
 
@@ -32,7 +39,7 @@ foundry_msg_testrequest_get_tid() {
 
        local tid
 
-       if ! tid=$(jq -e -r ".tid" <<< "$msg"); then
+       if ! tid=$(foundry_msg_get_data_field "$msg" "tid"); then
                return 1
        fi
 
@@ -46,7 +53,7 @@ foundry_msg_testrequest_get_repository() {
 
        local repository
 
-       if ! repository=$(jq -e -r ".repository" <<< "$msg"); then
+       if ! repository=$(foundry_msg_get_data_field "$msg" "repository"); then
                return 1
        fi
 
@@ -59,7 +66,7 @@ foundry_msg_testrequest_get_branch() {
 
        local branch
 
-       if ! branch=$(jq -e -r ".branch" <<< "$msg"); then
+       if ! branch=$(foundry_msg_get_data_field "$msg" "branch"); then
                return 1
        fi
 
@@ -72,7 +79,7 @@ foundry_msg_testrequest_get_commit() {
 
        local commit
 
-       if ! commit=$(jq -e -r ".commit" <<< "$msg"); then
+       if ! commit=$(foundry_msg_get_data_field "$msg" "commit"); then
                return 1
        fi