name: Sync GitHub to GitLab

on:
  push:
    branches:
      - develop  # Se activa cuando hay cambios en la rama develop

jobs:
  create-merge-request:
    runs-on: ubuntu-latest

    steps:
      # 1. Checkout del código desde GitHub
      - name: Checkout GitHub repository
        uses: actions/checkout@v4

      # 2. Crear un Merge Request en GitLab
      - name: Create Merge Request in GitLab
        env:
          GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
        run: |
          # Información del MR
          PROJECT_ID="335" # Reemplaza con el ID del proyecto de GitLab
          SOURCE_BRANCH="develop"
          TARGET_BRANCH="main"

          # Crear el Merge Request usando la API de GitLab
          curl -X POST \
            -H "Content-Type: application/json" \
            -H "Authorization: Bearer $GITLAB_TOKEN" \
            -d '{
              "id": "'"${PROJECT_ID}"'",
              "source_branch": "'"${SOURCE_BRANCH}"'",
              "target_branch": "'"${TARGET_BRANCH}"'",
              "title": "Sync develop to main",
              "remove_source_branch": false,
              "squash": false
            }' \
            https://labs.etsi.org/api/v4/projects/${PROJECT_ID}/merge_requests
