From a1029cc54e4ca1e5c45d9c7adef3675badf730e9 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 10 Sep 2021 07:17:22 +0900 Subject: [PATCH] dispatchbot: Send build requests when a merge was detected Dispatchbot does not correctly handle merge messages, causing it to fail to emit a build request when a merge has occurred. This commit changes the way dispatchbot handles merge messages, so that a build request is emitted whenever a merge was detected on a "master" or "stable" branch. --- dispatchbot.sh | 86 +++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/dispatchbot.sh b/dispatchbot.sh index df63157..8de69fa 100755 --- a/dispatchbot.sh +++ b/dispatchbot.sh @@ -34,23 +34,16 @@ emit_signrequest() { emit_buildrequest() { local endpoint="$1" - local mergemsg="$2" + local context="$2" + local repository="$3" + local branch="$4" - 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" \ + if ! buildreq=$(foundry_msg_buildrequest_new "$context" \ "$repository" \ "$branch"); then + log_error "Could not make build request" return 1 fi @@ -104,41 +97,6 @@ emit_testrequest() { return 0 } -emit_buildrequest() { - local endpoint="$1" - local commitmsg="$2" - - local repository - local branch - local commit - local tid - - local buildrequest - - if ! repository=$(foundry_msg_commit_get_repository "$commitmsg") || - ! branch=$(foundry_msg_commit_get_branch "$commitmsg") || - ! commit=$(foundry_msg_commit_get_commit "$commitmsg"); then - return 1 - fi - - if ! tid=$( false ); then - return 1 - fi - - if ! buildrequest=$(foundry_msg_buildrequest_new "$tid" \ - "$repository" \ - "$branch" \ - "$commit"); then - return 1 - fi - - if ! ipc_endpoint_send "$endpoint" "pub/buildbot" "$buildrequest"; then - return 1 - fi - - return 0 -} - emit_distrequest() { local endpoint="$1" local signmsg="$2" @@ -304,17 +262,39 @@ _handle_merge() { local endpoint="$1" local msg="$2" + local context + local repository local branch + local accepted_branches + + accepted_branches=( + "master" + "stable" + ) + + if ! context=$(foundry_msg_merge_get_context "$msg"); then + log_warn "Dropping merge message without context" + return 0 + fi + + if ! repository=$(foundry_msg_merge_get_repository "$msg"); then + log_warn "Dropping merge message without repository (context $context)" + return 0 + fi if ! branch=$(foundry_msg_merge_get_destination_branch "$msg"); then - log_error "Malformed message" - return 1 + log_warn "Dropping merge message for $context@$repository without destination branch" + return 0 fi - if [[ "$branch" == "master" ]] || [[ "$branch" == "stable" ]]; then - if ! emit_buildrequest "$endpoint" "$msg"; then - return 1 - fi + if ! array_contains "$branch" "${accepted_branches[@]}"; then + log_info "Ignoring merge message for $context@$repository#$branch" + return 0 + fi + + if ! emit_buildrequest "$endpoint" "$context" "$repository" "$branch"; then + log_error "Could not send build request for $repository#$branch" + return 1 fi return 0 -- 2.47.3