Add Repository to GitHub Connection in ADS

254 Views Asked by At

How to add GitHub repository to ADS (On-Prem) connection using API. Followed this link to establish connection between GitHub repos and ADS (GitHub connection). We can add repos manually, we are looking for APIs to add the repos. enter image description here

Is there any API using which we can add GitHub repos to the GitHub connections in ADS?

1

There are 1 best solutions below

1
On

There isn't a documented REST API that can do this. But when I checked the Developer Console, I found that there is indeed a REST API that can add repository with existing GitHub connection:

POST https://dev.azure.com/{organization}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview.1

Here is a sample request body:

{
    "contributionIds": [
        "ms.vss-work-web.github-unified-installation-experience-data-provider"
    ],
    "dataProviderContext": {
        "properties": {
            "orgName": "{organization}",
            "externalRepositoryExternalIds": [
                "{RepositoryExternalIds}",
                "{RepositoryExternalIds}"
            ],
            "existingConnectionId": "{ConnectionId}",
            "sourcePage": {
                "url": "https://dev.azure.com/{organization}/{project}/_settings/boards-external-integration",
                "routeId": "ms.vss-admin-web.project-admin-hub-route",
                "routeValues": {
                    "project": "{project}",
                    "adminPivot": "boards-external-integration",
                    "controller": "ContributedPage",
                    "action": "Execute"
                }
            }
        }
    }
}

In the externalRepositoryExternalIds section, note that you need to include all the repository ids you want, not just the new ones you want to add.

Other information that might help: If you change the request body, the REST API will return all repositories that are currently connected. Here are some examples:

{
    "contributionIds": [
        "ms.vss-work-web.azure-boards-external-connection-data-provider"
    ],
    "dataProviderContext": {
        "properties": {
            "includeInvalidConnections": true,
            "sourcePage": {
                "url": "https://dev.azure.com/{organization}/{project}/_settings/boards-external-integration",
                "routeId": "ms.vss-admin-web.project-admin-hub-route",
                "routeValues": {
                    "project": "{project}",
                    "adminPivot": "boards-external-integration",
                    "controller": "ContributedPage",
                    "action": "Execute",
                }
            }
        }
    }
}