How to check if a changeType is "merge" or "branch" when retrieving git changes through Azure DevOps REST Api - azure-devops

I am fetching Git changes from Azure DevOps REST Api and want to distinguish if a specific commit was a merge/branch operation. The default changeTypes are: add, edit, delete and I couldn't find any reference for "merge" or "branch".
Is there a built in way to achieve this?
My query uses the following syntax from the official doc:
GET https://{instance}/{collection}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=4.1
And the response is like:
{
"parents": [],
"treeId": "7fa1a3523ffef51c525ea476bffff7d648b8cb3d",
"push": {
"pushedBy": {
"id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"displayName": "Chuck Reinhart",
"uniqueName": "fabrikamfiber3#hotmail.com",
"url": "https://fabrikam:8080/tfs/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"imageUrl": "https://fabrikam:8080/tfs/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
},
"pushId": 1,
"date": "2014-01-29T23:33:15.2434002Z"
},
"commitId": "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"author": {
"name": "Chuck Reinhart",
"email": "fabrikamfiber3#hotmail.com",
"date": "2014-01-29T23:32:09Z"
},
"committer": {
"name": "Chuck Reinhart",
"email": "fabrikamfiber3#hotmail.com",
"date": "2014-01-29T23:32:09Z"
},
"comment": "First cut\n",
"changeCounts": {
"Add": 2
},
"changes": [
{
"item": {
"gitObjectType": "blob",
"path": "/.gitattributes",
"url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitattributes?versionType=Commit"
},
"changeType": "add"
},
{
"item": {
"gitObjectType": "blob",
"path": "/.gitignore",
"url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/items/.gitignore?versionType=Commit"
},
"changeType": "add"
}
],
"url": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"remoteUrl": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"_links": {
"self": {
"href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"repository": {
"href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
},
"changes": {
"href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4/changes"
},
"web": {
"href": "https://fabrikam:8080/tfs/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"tree": {
"href": "https://fabrikam:8080/tfs/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/7fa1a3523ffef51c525ea476bffff7d648b8cb3d"
}
}
}
If there is no built in way to achieve this, should the parent be used as a guidance? Like if it is empty it is a 'branch' operation and if there is two entries in it it is a 'merge'?
Update 1
I can see in the documentation referenced above that there are merge and branch changeTypes, but when I query a change that was merged the result only contains edit or add.

You will have to use the parents collection to determine whether it was a merge. Since normal commits just have 1 parent, more than 1 indicates a merge.
From the git documentation here
A commit object may have any number of parents. With exactly one parent, it is an ordinary commit. Having more than one parent makes the commit a merge between several lines of history. Initial (root) commits have no parents.

Related

Unable to retrieve the changeCounts properties for a git Pull Request in AzureDevOps using the REST api

I am trying to find (roughly) the number of lines of code that has been changed in a Pull Request using the Azure DevOps REST Api. The documentation suggests that it is possible but I have been unable to get it to work.
The api's return a GitCommitRef[] as a response and inside the GitCommitRef there is a changeCounts property, but this mostly appears to be missing from most responses.
Things I have tried\observed:
1. List of commits for a pull request
I can get a list of the commits for a pull request, but this does not include the changeCounts
Request
https://{{coreServer}}/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/pullRequests/{{pullRequestId}}/commits?api-version=6.0
Response
{
"count": 3,
"value": [
{
"commitId": "0b415...669fda",
"author": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-02T03:34:23Z"
},
"committer": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-02T03:34:23Z"
},
"comment": "checkin commit",
"url": "https://dev.azure.com/{{organization}}/{{project}}/_apis/git/repositories/5f32ff...2a97ac1/commits/0b415...669fda"
},
2. Getting a list of commits for a repository does return the changeCounts
So I thought, okay I will just retrieve each commit and get the counts that way, but I cannot get it to honour the searchCriteria, so if I ask for a specific commit I still get all the commits on the repo
https://{{coreServer}}/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/commits?searchCriteria.compareVersion.version=67...4b4&searchCriteria.compareVersion.versionType=commit&api-version=6.0
Response
{
"count": 100,
"value": [
{
"commitId": "71...a93a",
"author": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-07T23:59:52Z"
},
"committer": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-07T23:59:52Z"
},
"comment": "Merged PR 11087: did some work",
"commentTruncated": true,
"changeCounts": {
"Add": 0,
"Edit": 1,
"Delete": 0
},
3. Specifying the commit id does not return the changeCounts either
If I specify the commit id when retrieving a commit that, only returns the commit but not the changeCounts
https://{{coreServer}}/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/commits?searchCriteria.ids=0b...fda&api-version=6.0
Response
{
"count": 1,
"value": [
{
"commitId": "0b...da",
"author": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-02T03:34:23Z"
},
"committer": {
"name": "name",
"email": "name#email.com",
"date": "2021-11-02T03:34:23Z"
},
"comment": "did some work",
"url": "https://dev.azure.com/{{organization}}/{{project}}/_apis/git/repositories/5f...ac1/commits/0b...da"
}
]
}
Anyone have an idea why the api's do not seem to be working for me?

AWS Stepfunction: Substring from input

As a general question is it possible do a substring function within step functions?
I receive the following event:
{
"input": {
"version": "0",
"id": "d9c5fec0-d08d-6abd-4ea5-0107fbbce47d",
"detail-type": "EBS Multi-Volume Snapshots Completion Status",
"source": "aws.ec2",
"account": "12345678",
"time": "2021-11-12T12:08:16Z",
"region": "us-east-1",
"resources": [
"arn:aws:ec2::us-east-1:snapshot/snap-0a98c2a42ee266123"
]
}
}
but need the snapshot id as input to DescribeInstances, therefore I need to extract snap-0a98c2a42ee266123 from arn:aws:ec2::us-east-1:snapshot/snap-0a98c2a42ee266123
Is there any simple way to do this within step functions?. That is to say without having to pass it to a lambda or something equally convoluted?
This has recently become possible with the addition of new intrinsic functions. ArrayGetItem gets an item by its index. StringSplit splits a string at a delimeter. Use a Pass state to extract the snapshot name from the resource ARN:
{
"StartAt": "ExtractSnapshotName",
"States": {
"ExtractSnapshotName": {
"Type": "Pass",
"Parameters": {
"input.$": "$.input",
"snapshotName.$": "States.ArrayGetItem(States.StringSplit(States.ArrayGetItem($.input.resources,0), '/'),1)"
},
"ResultPath": "$",
"End": true
}
}
}
output:
{
"input": {
"version": "0",
"id": "d9c5fec0-d08d-6abd-4ea5-0107fbbce47d",
"detail-type": "EBS Multi-Volume Snapshots Completion Status",
"source": "aws.ec2",
"account": "12345678",
"time": "2021-11-12T12:08:16Z",
"region": "us-east-1",
"resources": [
"arn:aws:ec2::us-east-1:snapshot/snap-0a98c2a42ee266123"
]
},
"snapshotName": "snap-0a98c2a42ee266123"
}

Write correct JSON about PlanDefinition and ActivityDefinition on FHIR

I want to write a JSON to create a PlanDefinition resource with some ActivityDefinition resources inside it to persiste on FHIR r4 server these resources.
My sandbox server is Hapi FHIR
Two questions:
The first: How can I write it
The second: When I'll wirte the correct JSON, the result will be the creation of one PlanDefinition resource and some ActivityDefinition resources, or will be created only one PlanDefinition resource with these informations inside it?
This is my JSON to create a simple PlanDefinition, but I donìt know how to add ActivityDefinition inside it
{
"resourceType": "PlanDefinition",
"id": "999999",
"meta": {
"versionId": "1",
"lastUpdated": "2020-04-16T11:10:45.868+00:00",
"source": "#YS2h8QIqvGKHDy4x"
},
"url": "www.myserver.it",
"identifier": [ {
"system": "www.myserver.it",
"value": "jtr-pd1"
} ],
"version": "versione 1",
"status": "active",
"action": [ {
"title": "A",
"definitionCanonical": "#Process_Alex1"
}, {
"title": "B",
"definitionCanonical": "#Process_Alex2"
}, {
"title": "C",
"definitionCanonical": "ActivityDefinition"
} ]
}
Typically in FHIR we don't contain resources inside each other. References instead point to other independently maintained resource instances. For example, multiple PlanDefinitions might point to the same ActivityDefinition because that one activity is a 'step' in multiple protocols/order sets.
If you have a situation where an activity definition is tied to a single PlanDefinition and can't exist independent of that PlanDefinition (e.g. if the PlanDefinition were deleted, the ActivityDefinition would go too; no other PlanDefinition can point to the Activity, any update to the activity would be considered an update to the plan, etc.), you can send the ActivityDefinition as a 'contained' resource. Your instance would look like this:
{
"resourceType": "PlanDefinition",
"id": "999999",
"meta": {
"versionId": "1",
"lastUpdated": "2020-04-16T11:10:45.868+00:00",
"source": "#YS2h8QIqvGKHDy4x"
},
"contained": [ {
"resourceType": "ActivityDefinition",
"id": "Process_Alex1",
...
},
{
"resourceType": "ActivityDefinition",
"id": "Process_Alex2",
...
} ],
{
"url": "www.myserver.it",
"identifier": [ {
"system": "www.myserver.it",
"value": "jtr-pd1"
} ],
"version": "versione 1",
"status": "active",
"action": [ {
"title": "A",
"definitionCanonical": "#Process_Alex1"
}, {
"title": "B",
"definitionCanonical": "#Process_Alex2"
}, {
"title": "C",
"definitionCanonical": "http://somewhere.org/ActivityDefinition/foo"
} ]
}

Swagger UI doesn't show embedded json properties model

I am using the swagger tool for documenting my Jersey based REST API (the swaggerui I am using was downloaded on June 2014 don't know if this issue has been fixed in later versions but as I made a lot of customization to its code so I don't have the option to download the latest without investing lot of time to customize it again).
So far and until now, all my transfer objects have one level deep properties (no embedded pojos). But now that I added some rest paths that are returning more complex objects (two levels of depth) I found that SwaggerUI is not expanding the JSON model schema when having embedded objects.
Here is the important part of the swagger doc:
...
{
"path": "/user/combo",
"operations": [{
"method": "POST",
"summary": "Inserts a combo (user, address)",
"notes": "Will insert a new user and a address definition in a single step",
"type": "UserAndAddressWithIdSwaggerDto",
"nickname": "insertCombo",
"consumes": ["application/json"],
"parameters": [{
"name": "body",
"description": "New user and address combo",
"required": true,
"type": "UserAndAddressWithIdSwaggerDto",
"paramType": "body",
"allowMultiple": false
}],
"responseMessages": [{
"code": 200,
"message": "OK",
"responseModel": "UserAndAddressWithIdSwaggerDto"
}]
}]
}
...
"models": {
"UserAndAddressWithIdSwaggerDto": {
"id": "UserAndAddressWithIdSwaggerDto",
"description": "",
"required": ["user",
"address"],
"properties": {
"user": {
"$ref": "UserDto",
"description": "User"
},
"address": {
"$ref": "AddressDto",
"description": "Address"
}
}
},
"UserDto": {
"id": "UserDto",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},...
},
"AddressDto": {
"id": "AddressDto",
"properties": {
"addressId": {
"type": "integer",
"format": "int64"
},
"street": {
"type": "string"
},...
}
}
...
The embedded objects are User and Address, their models are being created correctly as shown in the json response.
But when opening the SwaggerUI I can only see:
{
"user": "UserDto",
"address": "AddressDto"
}
But I should see something like:
{
"user": {
"userId": "integer",
"name": "string",...
},
"address": {
"addressId": "integer",
"street": "string",...
}
}
Something may be wrong in the code that expands the internal properties, the javascript console doesn't show any error so I assume this is a bug.
I found the solution, there is a a line of code that needs to be modified to make it work properly:
In the swagger.js file there is a getSampleValue function with a conditional checking for undefined:
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
var result;
if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === 'undefined'))
...
I updated the equality check to (removing quotes):
modelsToIgnore[this.refModel.name] === undefined
After that, SwaggerUI is able to show the embedded models.

OData REST Filter for deeply nested data

I have a working REST request that returns a large results collection. (trimmed here)
The original URL is:
http://intranet.domain.com//_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\kens'&$select=AccountName,DisplayName,Email,Title,UserProfileProperties
The response is:
{
"d": {
"__metadata": {
"id": "stuff",
"uri": "morestuff",
"type": "SP.UserProfiles.PersonProperties"
},
"AccountName": "domain\\KenS",
"DisplayName": "Ken Sanchez",
"Email": "KenS#domain.com",
"Title": "Research Assistant",
"UserProfileProperties": {
"results": [
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "UserProfile_GUID",
"Value": "1c419284-604e-41a8-906f-ac34fd4068ab",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "SID",
"Value": "S-1-5-21-2740942301-4273591597-3258045437-1132",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ADGuid",
"Value": "",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "AccountName",
"Value": "domain\\KenS",
"ValueType": "Edm.String"
}...
Is it possible to change the REST request with a $filter that only returns the Key Values from the results collection where Key=SID OR Key= other values?
I only need about 3 values from the results collection by name.
In OData, you can't filter an inner feed.
Instead you could try to query the entity set that UserProfileProperties comes from and expand the associated SP.UserProfiles.PersonProperties entity.
The syntax will need to be adjusted for your scenario, but I'm thinking something along these lines:
service.svc/UserProfileProperties?$filter=Key eq 'SID' and RelatedPersonProperties/AccountName eq 'domain\kens'&$expand=RelatedPersonProperties
That assumes you have a top-level entity set of UserProfileProperties and each is tied back to a single SP.UserProfiles.PersonProperties entity via a navigation property called (in my example) RelatedPersonProperties.