diff --git a/checking_conflicts.sh b/checking_conflicts.sh index 22b6bf7db97bce9445cdcc87820402edb99b797e..6d1e895c80665d03cca9fc6f0d2fdbeedeec6fd4 100644 --- a/checking_conflicts.sh +++ b/checking_conflicts.sh @@ -20,6 +20,8 @@ echo "CI_PROJECT_NAME:" $7 echo "GITLAB_USER_NAME:" $8 #$GITLAB_USER_EMAIL -> 9 echo "GITLAB_USER_EMAIL:" $9 +#CONFLICTING_MERGE_REQUEST -> 11 +echo "CONFLICTING_MERGE_REQUEST:" $CONFLICTING_MERGE_REQUEST #echo "------ Removing previous outputs --------" rm **/*.txt @@ -45,47 +47,76 @@ echo "Checkout merge request source branch ${6} ..." git checkout -b "${6}" "origin/${6}" #Git checkout actual merge requests SOURCE BRANCHE git status -echo "\n------ Getting all potential conflicting merge requests --------" -# Get a list of open merge requests: Filter by the same Milestone and Target Branch as the actual merge request - -#curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}" |jq -c '.[] | {iid: .iid, source_branch: .source_branch, title: .title}' -#curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}" | jq -c '.[]' | while read mr; do -#merge_requests=$(curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}") -merge_requests=$(curl "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}") -echo "${merge_requests}" | jq -c '.[]' | while read mr; do - mr_id=$(echo "$mr" | jq '.iid') - result_id=$? - if [ ! $result_id == 0 ] ; then - echo "ERROR: When retrieving merge request id" - continue - fi - mr_title=$(echo "$mr" | jq '.title') - result_title=$? - if [ ! $result_title == 0 ] ; then - echo "ERROR: When retrieving merge request title" - continue - fi - mr_source_branch=$(echo "$mr" | jq -r '.source_branch') - result_source_branch=$? - if [ ! $result_source_branch == 0 ] ; then - echo "ERROR: When retrieving merge request source branch" - continue - fi - if [ ${mr_id} != ${5} ]; then - echo "Checkout potential merge request source branch ${mr_source_branch} ..." +if [ ! -z $CONFLICTING_MERGE_REQUEST ] ; then + echo "\n------ Getting a conflicting merge request --------" + mr_source_branch=${$CONFLICTING_MERGE_REQUEST} + echo "Checkout conflicting merge request source branch ${mr_source_branch} ..." git checkout -b "${mr_source_branch}" "origin/${mr_source_branch}" #Git checkout other merge requests SOURCE BRANCHES - echo "Run dry merge from potential merge request source branch ${mr_source_branch} into actual merge request source branch ${6} ..." + echo "Run dry merge from conflicting merge request source branch ${mr_source_branch} into actual merge request source branch ${6} ..." git merge --no-commit --no-ff "${6}" #SOURCE BRANCH of the merge request - result=$? - if [ ! $result == 0 ] ; then - echo "Merge request title: ${mr_title}, Merge Request ID: ${mr_id}" >> conflicting_merge_requests.txt + result=$? + if [ ! $result == 0 ] ; then + echo "Merge request title: ${mr_source_branch}" >> conflicting_merge_requests.txt else - echo "No conflict with Merge request title: ${mr_title}, Merge Request ID: ${mr_id}" + echo "No conflict with Merge request title: ${mr_source_branch}" fi git merge --abort - fi -done +else + echo "\n------ Getting all potential conflicting merge requests --------" + # Get a list of open merge requests: Filter by the same Milestone and Target Branch as the actual merge request + + #curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}" |jq -c '.[] | {iid: .iid, source_branch: .source_branch, title: .title}' + #curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}" | jq -c '.[]' | while read mr; do + #merge_requests=$(curl --header "PRIVATE-TOKEN: ${10}" "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}") + + # Initialize an empty array to store conflicting merge requests + conflicting_merge_request_ids=() + merge_requests=$(curl "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}") + echo "${merge_requests}" | jq -c '.[]' | while read mr; do + mr_id=$(echo "$mr" | jq '.iid') + result_id=$? + if [ ! $result_id == 0 ] ; then + echo "ERROR: When retrieving merge request id" + continue + fi + mr_title=$(echo "$mr" | jq '.title') + result_title=$? + if [ ! $result_title == 0 ] ; then + echo "ERROR: When retrieving merge request title" + continue + fi + mr_source_branch=$(echo "$mr" | jq -r '.source_branch') + result_source_branch=$? + if [ ! $result_source_branch == 0 ] ; then + echo "ERROR: When retrieving merge request source branch" + continue + fi + if [ ${mr_id} != ${5} ] && [ ${mr_id} -lt ${5} ]; then + echo "Checkout potential merge request source branch ${mr_source_branch} ..." + git checkout -b "${mr_source_branch}" "origin/${mr_source_branch}" #Git checkout other merge requests SOURCE BRANCHES + echo "Run dry merge from potential merge request source branch ${mr_source_branch} into actual merge request source branch ${6} ..." + git merge --no-commit --no-ff "${6}" #SOURCE BRANCH of the merge request + result=$? + if [ ! $result == 0 ] ; then + echo "Merge request title: ${mr_title}, Merge Request ID: ${mr_id}" >> conflicting_merge_requests.txt + conflicting_merge_request_ids+=("${mr_id}") + # Trigger pipeline for conflicting merge requests + echo "Triggering pipeline for merge request ${mr_id}" + curl -X POST \ + --fail \ + -F token=${10} \ + -F ref=${mr_source_branch} \ + -F "variables[CONFLICTING_MERGE_REQUEST]=${mr_source_branch}" \ + ${1}/projects/${2}/trigger/pipeline + else + echo "No conflict with Merge request title: ${mr_title}, Merge Request ID: ${mr_id}" + fi + git merge --abort + fi + + done +fi if [ -f "conflicting_merge_requests.txt" ]; then echo "List of conflicting merge requests:" diff --git a/generateChangemarks/.gitlab-ci.yml b/generateChangemarks/.gitlab-ci.yml index f0bb3528f7bf3dca22714f6f70cb7f3e72187e1c..18b42e362916a4370bddb2528123059c149c25b3 100644 --- a/generateChangemarks/.gitlab-ci.yml +++ b/generateChangemarks/.gitlab-ci.yml @@ -7,11 +7,11 @@ workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Creation of Merge Request (generation of CR) + - if: $CI_PIPELINE_SOURCE == "trigger" # Upgrade of the index.html page - if: $CI_COMMIT_TAG # Creation of tag (publish spec) - if: $CI_PIPELINE_SOURCE == "web" # Removal of a specific entry - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never # Pipeline to be run manually as defined in the contribution procedure as it is not known when the CR is ready - - if: $CI_PIPELINE_SOURCE == "trigger" # Upgrade of the index.html page variables: @@ -26,6 +26,9 @@ Checking conflicts: rules: - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event" when: always + - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "trigger" + when: always + allow_failure: true image: python:3.9.18-slim-bullseye tags: - docker @@ -38,7 +41,7 @@ Checking conflicts: - git clone "https://$CI_SERVER_HOST/$CI_PROJECT_PATH.git" ${CI_PROJECT_NAME} script: - echo 'Checking conflicts' - - ./checking_conflicts.sh ${CI_API_V4_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_MILESTONE} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} ${CI_MERGE_REQUEST_IID} ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} ${CI_PROJECT_NAME} "$GITLAB_USER_NAME" $GITLAB_USER_EMAIL + - ./checking_conflicts.sh ${CI_API_V4_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_MILESTONE} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} ${CI_MERGE_REQUEST_IID} ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} ${CI_PROJECT_NAME} "$GITLAB_USER_NAME" $GITLAB_USER_EMAIL $CHECKING_CONFLICTS_TOKEN $CONFLICTING_MERGE_REQUEST artifacts: when: on_failure paths: @@ -50,6 +53,8 @@ Word CR: rules: - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "merge_request_event" when: on_success + - if: $CI_MERGE_REQUEST_TITLE !~ /v.*_baseline$/ && $CI_PIPELINE_SOURCE == "trigger" + when: on_success dependencies: [] when: on_success before_script: