From 2dd7e322245e5587ce053fdd893e0094e43d3701 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 1 Aug 2021 13:41:49 +0900 Subject: [PATCH] dispatchbot: Send buildrequest upon receipt of a merge notification When a merge into the master/stable branch of a repository has taken place, foundry should trigger a build from the updated source code. This commit modifies dispatchbot to watch the "merges" topic and send a buildrequest to the buildbots whenever a merge to a master or stable branch has been performed. --- dispatchbot.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/dispatchbot.sh b/dispatchbot.sh index b4cf26f..d344056 100755 --- a/dispatchbot.sh +++ b/dispatchbot.sh @@ -32,6 +32,35 @@ emit_signrequest() { return 0 } +emit_buildrequest() { + local endpoint="$1" + local mergemsg="$2" + + local context + local repository + local branch + local buildreq + + if ! context=$(foundry_msg_merge_get_context "$mergemsg") || + ! repository=$(foundry_msg_merge_get_repository "$mergemsg") || + ! branch=$(foundry_msg_merge_get_destination_branch "$mergemsg"); then + log_error "Malformed merge message" + return 1 + fi + + if ! buildreq=$(foundry_msg_buildrequest_new "$context" \ + "$repository" \ + "$branch"); then + return 1 + fi + + if ! ipc_endpoint_send "$endpoint" "pub/buildbot" "$buildreq"; then + return 1 + fi + + return 0 +} + emit_testrequest() { local endpoint="$1" local commitmsg="$2" @@ -210,13 +239,6 @@ _handle_commit() { fi case "$branch" in - "stable") - if ! emit_buildrequest "$endpoint" "$msg" \ - "$repository" "$branch"; then - return 1 - fi - ;; - "testing") if ! emit_testrequest "$endpoint" "$msg" \ "$repository" "$branch"; then @@ -263,6 +285,26 @@ _handle_sign() { return 0 } +_handle_merge() { + local endpoint="$1" + local msg="$2" + + local branch + + if ! branch=$(foundry_msg_merge_get_destination_branch "$msg"); then + log_error "Malformed message" + return 1 + fi + + if [[ "$branch" == "master" ]] || [[ "$branch" == "stable" ]]; then + if ! emit_buildrequest "$endpoint" "$msg"; then + return 1 + fi + fi + + return 0 +} + _handle_notification() { local endpoint="$1" local msg="$2" @@ -290,6 +332,10 @@ _handle_notification() { _handle_sign "$endpoint" "$fmsg" ;; + "$__foundry_msg_type_merge") + _handle_merge "$endpoint" "$fmsg" + ;; + 255) log_warn "Invalid message received" return 1 @@ -312,6 +358,7 @@ _route_messages() { topics=("commits" "tests" + "merges" "builds" "signs") -- 2.47.3