Jay K
Jay K

Reputation: 61

Add Repository to GitHub Connection in ADS

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?

Upvotes: 0

Views: 325

Answers (1)

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5182

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",
                }
            }
        }
    }
}

Upvotes: 0

Related Questions