From c8fcef94e93a0f768d1498911851a1b99f2c4c7a Mon Sep 17 00:00:00 2001 From: Louis-Filipe Date: Mon, 15 Jun 2026 10:03:08 +0200 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20workflow=20sync=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync-to-gitlab.yml | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/sync-to-gitlab.yml diff --git a/.github/workflows/sync-to-gitlab.yml b/.github/workflows/sync-to-gitlab.yml new file mode 100644 index 0000000..cf26914 --- /dev/null +++ b/.github/workflows/sync-to-gitlab.yml @@ -0,0 +1,55 @@ +name: Sync PR to GitLab + +on: + pull_request: + branches: + - main + types: + - opened + - synchronize + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + + - name: GitLab remote + run: | + git remote add gitlab https://oauth2:${{ secrets.PUSH_TO_MAIN_TOKEN }}@gitlab.insee.fr/dsi/compas/compas-api.git + + - name: Creation de la sync branch + run: | + git checkout -B sync-from-github origin/${{ github.head_ref }} + + - name: Push to GitLab + run: | + git push --force gitlab HEAD:sync-from-github + + - name: Creation de la MR + run: | + EXISTING_MR=$(curl --silent \ + --header "PRIVATE-TOKEN: ${{ secrets.PUSH_TO_MAIN_TOKEN }}" \ + "https://gitlab.insee.fr/api/v4/projects/${{ secrets.ID_PROJECT }}/merge_requests?state=opened&source_branch=sync-from-github" \ + | jq '.[0].iid') + + if [ "$EXISTING_MR" == "null" ] || [ -z "$EXISTING_MR" ]; then + echo "Création de la MR..." + curl --request POST \ + --header "PRIVATE-TOKEN: ${{ secrets.PUSH_TO_MAIN_TOKEN }}" \ + --header "Content-Type: application/json" \ + --data '{ + "source_branch": "sync-from-github", + "target_branch": "main", + "title": "Sync de GitHub PR: ${{ github.event.pull_request.title }}", + "remove_source_branch": false + }' \ + "https://gitlab.insee.fr/api/v4/projects/${{ secrets.ID_PROJECT }}/merge_requests" + echo "MR créée ✅" + else + echo "MR déjà existante #$EXISTING_MR, push suffisant ✅" + fi \ No newline at end of file