{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ac1706f2-273e-4191-94f7-0e4c84e6939b",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        140,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "93d54a8a-9a7c-4193-89b6-754014b804d5",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        800,
        -20
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ac8b47d9-ba45-42c0-be51-2a9ecf2cada6",
      "name": "Switch error codes",
      "type": "n8n-nodes-base.switch",
      "position": [
        1260,
        -20
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "404",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1d1c97aa-61cd-4272-a650-a70c04dea44b",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.error.status }}",
                    "rightValue": 404
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "cf3bee67-e127-4efb-a8b1-384603eb0151",
      "name": "Stop and Error",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1500,
        200
      ],
      "parameters": {
        "errorMessage": "Unexpected error code when checking if Gitea repo already exists"
      },
      "typeVersion": 1
    },
    {
      "id": "8e3e60c7-a555-45aa-8ff4-aa64fd3aec46",
      "name": "Setup (CHANGE ME)",
      "type": "n8n-nodes-base.set",
      "position": [
        360,
        -20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3a089155-3799-416c-bdc6-2d8db2c093d5",
              "name": "gitlabAccessToken",
              "type": "string",
              "value": "1234567890"
            },
            {
              "id": "1da58875-baa0-4a4a-86e8-6294236b21e1",
              "name": "gitlabGroupPathName",
              "type": "string",
              "value": "gitlab-group-name"
            },
            {
              "id": "ec12a90b-5b50-4a19-8e28-84c9d540497c",
              "name": "giteaOrganizationPathName",
              "type": "string",
              "value": "gitea-org-name"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e475bc22-719c-4d87-95ba-7567107b7ecd",
      "name": "Gitea: Migrate repo",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1500,
        -20
      ],
      "parameters": {
        "url": "=https://gitea.example.com/api/v1/repos/migrate",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"auth_token\": \"{{ $('Setup (CHANGE ME)').item.json.gitlabAccessToken }}\",\n  \"clone_addr\": \"{{ $('Loop Over Items').item.json.http_url_to_repo }}\",\n  \"description\": \"{{ $('Loop Over Items').item.json.description }}\",\n  \"issues\": true,\n  \"labels\": true,\n  \"lfs\": true,\n  \"milestones\": true,\n  \"mirror\": false,\n  \"private\": true,\n  \"pull_requests\": true,\n  \"releases\": true,\n  \"repo_name\": \"{{ $('Loop Over Items').item.json.path }}\",\n  \"repo_owner\": \"{{ $('Setup (CHANGE ME)').item.json.giteaOrganizationPathName }}\",\n  \"service\": \"gitlab\",\n  \"wiki\": true\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "159efdb3-b3a6-469f-8021-b608996ffcc5",
      "name": "Gitea: Search for repo",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1040,
        -20
      ],
      "parameters": {
        "url": "=https://gitea.example.com/api/v1/repos/{{ $('Setup (CHANGE ME)').item.json.giteaOrganizationPathName }}/{{ $json.path }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "06081af1-73c9-4f61-889c-289ea3de4c2c",
      "name": "Gitlab: Get projects",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        580,
        -20
      ],
      "parameters": {
        "url": "=https://gitlab.com/api/v4/groups/{{ $json.gitlabGroupPathName }}/projects",
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "page",
                    "value": "={{ $response.headers['x-next-page'] }}"
                  }
                ]
              },
              "completeExpression": "={{ $response.headers['x-page'] == $response.headers['x-total-pages'] }}",
              "paginationCompleteWhen": "other"
            }
          }
        },
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "per_page",
              "value": "20"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Gitea: Search for repo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup (CHANGE ME)": {
      "main": [
        [
          {
            "node": "Gitlab: Get projects",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch error codes": {
      "main": [
        [
          {
            "node": "Gitea: Migrate repo",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gitea: Migrate repo": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gitlab: Get projects": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gitea: Search for repo": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Switch error codes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Setup (CHANGE ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}