Commit e0a8b597 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Clean up repo

parent e83e453a
Loading
Loading
Loading
Loading
+0 −610

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −139
Original line number Diff line number Diff line
#
#	checking_conflicts.sh
#
#	Script to check potential conflicts with existing merge requests 
#
#	(c) 2024 by Miguel Angel Reina Ortega
#	License: BSD 3-Clause License. See the LICENSE file for further details.
#
#!/bin/bash

#Parameters

#${CI_API_V4_URL} -> 1
echo "CI_API_V4_URL:" $1
#${CI_MERGE_REQUEST_PROJECT_ID} -> 2
echo "CI_MERGE_REQUEST_PROJECT_ID:" $2
#${CI_MERGE_REQUEST_MILESTONE} -> 3
echo "CI_MERGE_REQUEST_MILESTONE:" $3
#${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} -> 4
echo "CI_MERGE_REQUEST_TARGET_BRANCH_NAME:" $4
#${CI_MERGE_REQUEST_IID} -> 5
echo "CI_MERGE_REQUEST_IID:" $5
#${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> 6
echo "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:" $6
#${CI_PROJECT_NAME} -> 7
echo "CI_PROJECT_NAME:" $7
#"$GITLAB_USER_NAME" -> 8
echo "GITLAB_USER_NAME:" $8
#$GITLAB_USER_EMAIL -> 9
echo "GITLAB_USER_EMAIL:" $9

#echo "------ Removing previous outputs --------"
rm **/*.txt

#echo "------ Parsing repo URL --------"

#HOST_URL=$(echo $1 | cut -d'/' -f 1-3)
#PROJECT_NAME=$(echo $1 | cut -d'/' -f 6- | cut -d'.' -f 1)
#echo "HOST URL:" $HOST_URL
#echo "PROJECT NAME:" $PROJECT_NAME
#echo "PROJECT ID:" $2
#echo "MERGE IID:" $3

#echo "\n------ Install necessary packages --------"
#pip install -q mkdocs-material mike rich mkdocs-rss-plugin

echo "------ Config git and checkout project actual merge request source branch --------"
#git clone "https://oauth2:${10}@git.onem2m.org/specifications/ts/${7}.git" ${7}
cd ${7}
git config --global --replace-all user.name "$8"
git config --global --replace-all user.email $9
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}")

# Initialize an empty array to store conflicting merge requests
conflicting_merge_request_ids=()
if [ ${3} == "all" ] ; then
  merge_requests=$(curl "${1}/projects/${2}/merge_requests?state=opened&target_branch=${4}")
else
  merge_requests=$(curl "${1}/projects/${2}/merge_requests?state=opened&milestone=${3}&target_branch=${4}")
fi

printf '%s' "${merge_requests}" | jq -c '.[]' | while read -r mr; do
  mr_id=$(printf '%s' "$mr" | jq -r '.iid')
  result_id=$?
  if [ ! $result_id == 0 ] ; then
    echo "ERROR: When retrieving merge request id"
    continue
  fi
  mr_title=$(printf '%s' "$mr" | jq -r '.title')
  result_title=$?
  if [ ! $result_title == 0 ] ; then
    echo "ERROR: When retrieving merge request title"
    continue
  fi
  mr_source_branch=$(printf '%s' "$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
      spec=$(git diff --name-only --diff-filter=U | grep -E "(TS|TR)")
      sed -n '
        /^<<<<<<< /,/^>>>>>>> / {
          /^<<<<<<<\|^>>>>>>>/!{=;p}
          /^>>>>>>> /a\

        }
      ' ${spec} >> conflicting_merge_requests.txt
      conflicting_merge_request_ids+=("${mr_id}")
      # Setting label to the merge request which is conflicting with
      echo "Setting label to the merge request which is conflicting with: ${mr_id}"

      #Creating label colored orange
      curl --request POST \
        --header "PRIVATE-TOKEN: ${10}" \
        --data "name=Conflict with merge request ${5}&color=#ed9121" \
        "${1}/projects/${2}/labels"

      #Assign label to the conflicting merge request
      curl --request PUT \
        --silent \
        --header "PRIVATE-TOKEN: ${10}" \
        --data "add_labels=Conflict with merge request ${5}" \
        "${1}/projects/${2}/merge_requests/${mr_id}"
    else
      echo "No conflict with Merge request title: ${mr_title}, Merge Request ID: ${mr_id}"
    fi
    git merge --abort
  fi

done

if [ -f "conflicting_merge_requests.txt" ]; then
  echo "List of conflicting merge requests:"
  cat conflicting_merge_requests.txt
  mv conflicting_merge_requests.txt ../conflicting_merge_requests.txt
  exit 1
else
  exit 0
fi

exit 0
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ echo "\n------ Checking for docker image --------"
echo "$GENERATE_BASELINE_DOCKER_IMAGE" | cut -d "/" -f 1 | docker logout 
docker pull "$GENERATE_CHANGEMARKS_DOCKER_IMAGE"
echo "$FORGELIB_DOCKER_IMAGE" | cut -d "/" -f 1 | docker logout 
#docker pull "$FORGELIB_DOCKER_IMAGE"
docker pull "$FORGELIB_DOCKER_IMAGE"


echo "------ Removing previous outputs --------"
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ docker pull "$GENERATE_BASELINE_DOCKER_IMAGE"
docker logout $(echo "$MARKDOWN_TOOLS_DOCKER_IMAGE" | cut -d "/" -f 1)
docker pull "$MARKDOWN_TOOLS_DOCKER_IMAGE"
docker logout $(echo "$FORGELIB_DOCKER_IMAGE" | cut -d "/" -f 1)
#docker pull "$FORGELIB_DOCKER_IMAGE"
docker pull "$FORGELIB_DOCKER_IMAGE"

echo "------ Removing previous outputs --------"
rm **/*.docx