0

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?

Mike Cole
  • 14,474
  • 28
  • 114
  • 194
Jay K
  • 41
  • 8

1 Answers1

0

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",
                }
            }
        }
    }
}
Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • Hi @Jane Ma-MSFT, Thank you for the API. Some confusion orgName do we need to provide GitHub org name without url? and also where can I find ConnectionId? – Jay K Jan 24 '23 at 11:48