@@ -51,9 +51,39 @@ while read -r old new ref; do
)
# call asynchronously so push isn't blocked
- echo "gitfoss-ci-runner trigger \"${payload_args[@]}\"\n"
- echo "gitfoss-ci-runner trigger \"${payload_args[@]}\"\n" >> /var/log/gitfoss/ci.log
- /usr/bin/gitfoss-ci-runner trigger "${payload_args[@]}";
+ # echo "gitfoss-ci-runner trigger \"${payload_args[@]}\"\n"
+ # echo "gitfoss-ci-runner trigger \"${payload_args[@]}\"\n" >> /var/log/gitfoss/ci.log
+ # /usr/bin/gitfoss-ci-runner trigger "${payload_args[@]}";
+
+ # Minimal safe post-receive snippet: build JSON from payload_args array and POST with curl
+ # Requires: bash, curl, jq (jq recommended for correctness)
+ CI_HOST="https://gitfoss.dev"
+ AUTH_TOKEN="REPLACE_WITH_TOKEN"
+ ORG="${org_name:-org}"
+ repo_name="${repo_name%.git}"
+ REPO="${repo_name:-repo}"
+
+ # payload_args is assumed to be an array like:
+ # payload_args=( "--repo" "org/repo" "--ref" "refs/heads/main" "--ref-type" "branch" ... )
+
+ # Build JSON robustly using jq
+ json=$(
+ # convert --key value pairs into null-separated key and value list, then jq to object
+ printf '%s\n' "${payload_args[@]}" |
+ awk 'NR%2{key=$0; getline; val=$0; sub(/^--/,"",key); printf "%s\0%s\0", key, val}' |
+ jq -Rn '
+ [inputs | split("\u0000")[]] as $a |
+ ($a | length) as $n |
+ reduce range(0; $n/2 | floor) as $i ({}; . + { ($a[$i*2]) : $a[$i*2+1] })
+ '
+ )
+
+ # POST to endpoint
+ curl -s -X POST "${CI_HOST}/${ORG}/${REPO}/pipelines/trigger" \
+ -H "Authorization: Bearer ${AUTH_TOKEN}" \
+ -H "Content-Type: application/json" \
+ -d "$json"
+
done
exit 0