diff --git a/util/git-replay-merge.sh b/util/git-replay-merge.sh index 964c5a1603..729e60d351 100755 --- a/util/git-replay-merge.sh +++ b/util/git-replay-merge.sh @@ -16,6 +16,13 @@ SELF="${SELF/-/ }" STATE_FILE=".git/REPLAY_MERGE" DONT_PUSH=${DONT_PUSH:=false} +DONT_ACCEPT=${DONT_ACCEPT:=false} + +GITLAB_API_ENDPOINT=${GITLAB_API_ENDPOINT:=https://gitlab.isc.org/api/v4} +GITLAB_URI=${GITLAB_URI:=$(echo $GITLAB_API_ENDPOINT | cut -f 1-3 -d /)} +GITLAB_PROJECT_ID=${GITLAB_PROJECT_ID:=1} +GITLAB_PROJECT_GROUP=${GITLAB_PROJECT_GROUP:=isc-projects} +GITLAB_PROJECT_NAME=${GITLAB_PROJECT_NAME:=bind9} die() { for MESSAGE in "$@"; do @@ -172,7 +179,22 @@ resume() { REPLAY_COMMIT_TITLE="$(git show --format="%b" "${SOURCE_COMMIT}" 2>&1 | head -1)" - gitlab create_merge_request 1 "${REPLAY_COMMIT_TITLE}" "{source_branch: '${REPLAY_BRANCH}', target_branch: '${TARGET_BRANCH}'}" + MERGE_REQUEST_BASE_URI="${GITLAB_URI}/${GITLAB_PROJECT_GROUP}/${GITLAB_PROJECT_NAME}/merge_requests/" + + MERGE_REQUEST_ID=$(gitlab create_merge_request "${GITLAB_PROJECT_ID}" "(${TARGET_BRANCH}) ${REPLAY_COMMIT_TITLE}" "{source_branch: '${REPLAY_BRANCH}', target_branch: '${TARGET_BRANCH}'}" | grep opened | cut -f 15 -d \| | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + + if [[ -z "$MERGE_REQUEST_ID" ]]; then + die "Creating MR failed." + fi + + REPLAY_HASH=$(git show-ref --hash --heads "${REPLAY_BRANCH}") + +# gitlab accept_merge_request ${GITLAB_PROJECT_ID} ${MERGE_REQUEST_ID} "{should_remove_source_branch: true, merge_when_pipeline_succeeds: true, sha: '$REPLAY_HASH'}" + + echo "================================================================================" + echo "=== Your new MR !${MERGE_REQUEST_ID} has been created" + echo "=== ${MERGE_REQUEST_BASE_URI}${MERGE_REQUEST_ID} ===" + echo "================================================================================" cleanup exit 0 @@ -189,6 +211,8 @@ cleanup() { rm -f "${STATE_FILE}" } +cd $(git rev-parse --show-toplevel) + next_action="go" while [[ $# -ge 1 ]]; do case "$1" in