[Python] Error 400: "Bad Request" When Importing GitLab Repository into Azure DevOps via REST...

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to import a GitLab repository into Azure DevOps using the REST API. However, I am encountering a 400 Bad Request error during the process. Below is the core part of the code:

    python code:

    repo_details = get_azure_repo(
    context=context,
    repo_name=ADO_REPO_NAME,
    project_name=PROJECT_NAME
    )

    # Prepare import request
    import_url = f"https://dev.azure.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/_apis/git/repositories/{ADO_REPO_NAME}/importRequests?api-version=7.1-preview.1"

    import_payload = {
    "parameters": {
    "gitSource": {
    "url": GITLAB_REPO_URL,
    "overwrite": False,
    "username": "oauth2",
    "password": "GITLAB_PERSONAL_ACCESS_TOKEN" # Placeholder for GitLab PAT
    },
    "serviceEndpointId": None,
    "deleteServiceEndpointAfterImportIsDone": True
    }
    }

    headers = {
    "Content-Type": "application/json"
    }

    # Perform repository import
    import_response = requests.post(
    import_url,
    auth=HTTPBasicAuth("", AZURE_DEVOPS_PAT), # Placeholder for Azure DevOps PAT
    headers=headers,
    data=json.dumps(import_payload),
    verify=False
    )


    Error:

    400 Client Error: Bad Request for url: https://dev.azure.com//<project_name>/_apis/git/repositories/<repo_name>/importRequests?api-version=7.1-preview.1

    Things I've Tried:

    The GitLab repository URL (GITLAB_REPO_URL) is correct and publicly accessible. The Azure DevOps Personal Access Token (AZURE_DEVOPS_PAT) has full permissions for repository imports and related operations. The repository name (ADO_REPO_NAME) and project name (PROJECT_NAME) exist and are accessible in Azure DevOps. The GITLAB_REPO_URL is in the format: https://gitlab.example.com//.git. I am using the appropriate API version (7.1-preview.1) as per Microsoft's documentation.

    Continue reading...

Compartilhe esta Página