|
150 | 150 | - "git diff --cached --stat" |
151 | 151 | - "git commit -m \"${GIT_COMMIT_MESSAGE}\"" |
152 | 152 | - "if [ -n \"${GIT_PUSH_TOKEN}\" ]; then CURRENT_URL=$(git remote get-url origin); PUSH_URL=$(echo \"${CURRENT_URL}\" | sed \"s|://[^@]*@|://oauth2:${GIT_PUSH_TOKEN}@|\"); git remote set-url origin \"${PUSH_URL}\"; fi" |
| 153 | + - "git fetch origin ${CI_COMMIT_REF_NAME}" |
| 154 | + - "git rebase origin/${CI_COMMIT_REF_NAME}" |
153 | 155 | - "git push origin HEAD:${CI_COMMIT_REF_NAME}" |
154 | 156 | - "echo '--- Creating merge request ---'" |
155 | 157 | - "API_TOKEN=${GIT_PUSH_TOKEN:-${CI_JOB_TOKEN}}" |
156 | | - - "GITLAB_API_URL=$(git remote get-url origin | sed 's|/[^/]*/[^/]*\\.git$||')/api/v4" |
157 | | - - "EXISTING_MR=$(curl -sf --header \"PRIVATE-TOKEN: ${API_TOKEN}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests?source_branch=${CI_COMMIT_REF_NAME}&target_branch=${MR_TARGET_BRANCH}&state=opened\" | jq '.[0].iid // empty')" |
158 | | - - "if [ -n \"${EXISTING_MR}\" ]; then echo \"Merge request already exists (MR !${EXISTING_MR})\"; MR_IID=${EXISTING_MR}; else MR_RESPONSE=$(curl -sf --header \"PRIVATE-TOKEN: ${API_TOKEN}\" --header \"Content-Type: application/json\" --data \"{\\\"source_branch\\\": \\\"${CI_COMMIT_REF_NAME}\\\", \\\"target_branch\\\": \\\"${MR_TARGET_BRANCH}\\\", \\\"title\\\": \\\"${MR_TITLE}\\\", \\\"remove_source_branch\\\": false}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests\"); MR_IID=$(echo \"${MR_RESPONSE}\" | jq -r .iid); fi" |
| 158 | + - "GITLAB_API_URL=$(git remote get-url origin | sed 's|://[^@]*@|://|; s|\\.git$||; s|/[^/]*/[^/]*$||')/api/v4" |
| 159 | + - "echo \"API URL: ${GITLAB_API_URL}\"" |
| 160 | + - "MR_RESPONSE=$(curl -s --header \"PRIVATE-TOKEN: ${API_TOKEN}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests?source_branch=${CI_COMMIT_REF_NAME}&target_branch=${MR_TARGET_BRANCH}&state=opened\")" |
| 161 | + - "echo \"MR lookup response: ${MR_RESPONSE}\"" |
| 162 | + - "EXISTING_MR=$(echo \"${MR_RESPONSE}\" | jq -r 'if type == \"array\" then (.[0].iid // empty) else empty end')" |
| 163 | + - "if [ -n \"${EXISTING_MR}\" ]; then echo \"Merge request already exists (MR !${EXISTING_MR})\"; MR_IID=${EXISTING_MR}; else MR_RESPONSE=$(curl -s --header \"PRIVATE-TOKEN: ${API_TOKEN}\" --header \"Content-Type: application/json\" --data \"{\\\"source_branch\\\": \\\"${CI_COMMIT_REF_NAME}\\\", \\\"target_branch\\\": \\\"${MR_TARGET_BRANCH}\\\", \\\"title\\\": \\\"${MR_TITLE}\\\", \\\"remove_source_branch\\\": false}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests\"); echo \"MR create response: ${MR_RESPONSE}\"; MR_IID=$(echo \"${MR_RESPONSE}\" | jq -r .iid); fi" |
159 | 164 | - "BROWSE_URL=${GITLAB_EXTERNAL_URL:-${CI_SERVER_URL}}/${CI_PROJECT_PATH}/-/merge_requests/${MR_IID}" |
160 | 165 | - "echo '========================================'" |
161 | 166 | - "echo \"Review and merge: ${BROWSE_URL}\"" |
|
0 commit comments