Add Reporsitory to GitHub Connection in ADS - github

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.
Is there any API using which we can add GitHub repos to the GitHub connections in ADS?

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

Related

How to use Azure DevOps REST API to Update File?

I'm trying to Update a test.json file hosted on a Azure DevOps Repo. I'm using a Logic App. Having trouble identifying the order of operations from the documentation.
I think I need to...
Issue a GET HTTP request to the Items endpoint:
https://dev.azure.com/myOrg/myProject/_apis/git/repositories/myRepoID/items?scopePath=/data/test.json&$format=json&api-version=6.0
Response:
{
"count": 1,
"value": [
{
"objectId": "<longGUID>",
"gitObjectType": "blob",
"commitId": "<longGUID>",
"path": "/data/test.json",
"url": "https://dev.azure.com/myOrg/longGUID/_apis/git/repositories/myRepoID/items?path=%2Fdata%2Ftest.json&versionType=Branch&versionOptions=None"
}
]
}
Use the objectId in the response to issue a POST HTTP request to the Pushes endpoint
Body:
{
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<longGuid from previous response>"
}
],
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "/data/test.json"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "My commit message"
}
]
}
Error:
Status 409 Conflict
{
"$id": "1",
"innerException": null,
"message": "TF401028: The reference 'refs/heads/main' has already been updated by another client, so you cannot update it. Please try again.",
"typeName": "Microsoft.TeamFoundation.Git.Server.GitReferenceStaleException, Microsoft.TeamFoundation.Git.Server",
"typeKey": "GitReferenceStaleException",
"errorCode": 0,
"eventId": 3000
}
Questions:
Am I correct on the order of operations?
How do I overcome this issue?
FIX: (Thank you #Leo_Liu-MSFT)
GET request to https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/commits?searchCriteria.$top=1&searchCriteria.itemVersion.version=main&api-version=6.0
POST request to https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/pushes
Body:
{
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "<Your File To Update>"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "<YOUR COMMIT MSG>"
}
],
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<commitId from previous response>"
}
]
}
How to use Azure DevOps REST API to Update File?
The oldObjectId in the request body is not the value of the objectId.
It should be the the latest commit SHA for the branch main.
Go to the code page > Files
Choose a repository and branch
Select the root level (repository name) > History
Click … of the first commit > Copy full SHA
And the value should be create a new branch 0000000000000000000000000000000000000000 when used to create a new branch.

How to find disabled azure services in azure devops project

We can disable azure devops services form UI
Is there any API available to GET the info about enabled / disabled services ?
Like in above image boards is disabled , Can I find this info using API ?
This is an feature in Project Settings.
I checked the related REST API and Azure CLI for Team Projects, however I did not find any available interface can list the info about enabled / disabled services, also no available interface to enabled / disabled services.
So, I think your question is more like a feature request. I recommend that you can report the feature request to Developer Community.
[UPDATE]
I found below API from the Network logs of the web browser (press F12). I have tested this API on my side, it should be the one you are looking for.
Request URI:
POST https://dev.azure.com/{Organization_name}/_apis/FeatureManagement/FeatureStatesQuery/host/project/{Project_id}?api-version=4.1-preview.1
Request Body:
{
"featureIds": [
"ms.vss-work.agile", // Boards
"ms.vss-code.version-control", // Repos
"ms.vss-build.pipelines", // Pipelines
"ms.vss-test-web.test", // Test Plans
"ms.feed.feed" // Artifacts
],
"featureStates": {},
"scopeValues": {
"project": "{Project_id}"
}
}
Response Body:
{
"featureIds": [
"ms.vss-work.agile",
"ms.vss-code.version-control",
"ms.vss-build.pipelines",
"ms.vss-test-web.test",
"ms.feed.feed"
],
"featureStates": {
"ms.vss-work.agile": {
"featureId": "ms.vss-work.agile",
"scope": {
"userScoped": false,
"settingScope": "project"
},
"state": "disabled"
},
"ms.vss-code.version-control": {
"featureId": "ms.vss-code.version-control",
"scope": null,
"state": "enabled"
},
"ms.vss-build.pipelines": {
"featureId": "ms.vss-build.pipelines",
"scope": null,
"state": "enabled"
},
"ms.vss-test-web.test": {
"featureId": "ms.vss-test-web.test",
"scope": null,
"state": "disabled",
"reason": "\"Test Plans\" is off because the \"Boards\" feature is off. In order to manage \"Test Plans\", you must turn on \"Boards\".",
"overridden": true
},
"ms.feed.feed": {
"featureId": "ms.feed.feed",
"scope": null,
"state": "enabled"
}
},
"scopeValues": {
"project": "{Project_id}"
}
}
The right name of the features are:
ms.vss-build.pipelines [Azure Pipelines]
ms.vss-test-web.test [Test Plans]
ms.vss-work.agile [Azure Boards]
ms.vss-code.version-control [Azure Repos]
ms.azure-artifacts.feature [Azure Artifacts]

How to get the list of published artifacts from an Azure DevOps build

Azure DevOps provides a view of published artifacts after a build has completed, my question is, is there an API endpoint that lists these artifacts?
This API is not officially documented, but you can get it from the developers tools in the Artifacts page.
So, the API url is:
https://dev.azure.com/{org-id}/_apis/Contribution/HierarchyQuery/project/{project-id}
And the body should be:
{
"contributionIds": [
"ms.vss-build-web.run-artifacts-data-provider"
],
"dataProviderContext": {
"properties": {
"artifactId": {artifact-id},
"buildId": {build-id},
"sourcePage": {
"url": "https://dev.azure.com/{org-id}/{project-id}/_build/results?buildId=1210\u0026view=artifacts\u0026pathAsName=false\u0026type=publishedArtifacts",
"routeId": "ms.vss-build-web.ci-results-hub-route",
"routeValues": {
"project": "{project-id}",
"viewname": "build-results",
"controller": "ContributedPage",
"action": "Execute",
"serviceHost": "{host-id} ({username})"
}
}
}
}
}
In the response you will get items section with the file names.
You can in the first to go the build artifacts page, press on F12 and see the values for the {} in the body I provided.

Mirror a GitHub repository using the source-repositories API directly

The cloud console provides an interface for mirroring a repository from GitHub.
When you use this feature it creates a mirrorConfig on the repository which can be read from the API. The API itself however does not seem to provide a way to write to this config.
Example when trying to make a repository with a mirrorConfig
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "repo.mirror_config",
"description": "mirror_config is a read-only field and must not be set"
}
]
},
{
"#type": "type.googleapis.com/google.rpc.RequestInfo",
"requestId": "*****"
}
]
}
}
Is there a way to programmatically create mirrored source repositories in Google Cloud Platform?
No.
Is the answer :(
Source: George's comment above (Google Cloud Platform Support team)

Add ARM Service Endpoint programatically in VSTS

I have an existing SPN in Azure AD and want to add to VSTS programatically.
Is this possible?
VSTS Rest-API? Examples?
Through powershell?
You can use the REST API to manage your endpoints.
For example the following POST will create an Azure endpoint:
https://fabrikam.visualstudio.com/DefaultAgileGitProject/_apis/serviceendpoint/endpoints?api-version=4.1-preview.1
{
"data": {
"SubscriptionId": "12345678-1234-1234-1234-123456129012",
"SubscriptionName": "TestSubscriptionName"
},
"id": "64be39c2-102b-416d-a3ac-2de40ebc8513",
"name": "TestEndpoint",
"type": "Azure",
"authorization": {
"parameters": {
"Certificate": "dummyCertificate"
},
"scheme": "Certificate"
},
"isReady": false
}
You can find the full documentation here: https://learn.microsoft.com/en-us/rest/api/vsts/serviceendpoint/endpoints/create?view=vsts-rest-4.1