how to pull code review reports from TFSGIT - tfs

I am trying to pull code review reports from the TFSGIT/VSTS, but I don't see anything out of the box.
The 3rd part code review tools like "ReviewAssistant" works great but they are not integrated with the Pull Request. It decouples code review to pull request.
I would like to get reports from the PullRequest code comments.

You can pull data from TFS with Rest API.
To get the PR code comments you can use the Pull Request Threads - List.
The request is:
https://{instance}/{collection}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads?api-version=4.1
In the JSON response, you will get the comments and the comment location in the code (line number):
"comments": [
{
"id": 1,
"parentCommentId": 0,
"author": {
"displayName": "Shayki Abramczyk",
"url": "https://spsprodweu3.vssps.visualstudio.com/Ac256a93d-7cea-4070-xxxxxxxxx/_apis/Identities/7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"_links": {
"avatar": {
"href": "https://dev.azure.com/xxxxxx/_apis/GraphProfile/MemberAvatars/msa.N2E5YTlxxxxxxxxxxxxxxx"
}
},
"id": "7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"uniqueName": "xxxxxxxx",
"imageUrl": "https://dev.azure.com/xxxxxxxx/_api/_common/identityImage?id=7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
"descriptor": "msa.N2E5YTliNDQtYTJmMS03ZGZkLWE3Zjxxxxxxxxxxx"
},
"content": "test comment",
"publishedDate": "2019-02-25T11:11:03.45Z",
"lastUpdatedDate": "2019-02-25T11:11:03.45Z",
"lastContentUpdatedDate": "2019-02-25T11:11:03.45Z",
"commentType": "text",
"usersLiked": [
]
}
],
"status": "active",
"threadContext": {
"filePath": "/SampleForVSTS/Program.cs",
"leftFileStart": {
"line": 14,
"offset": 1
},
"leftFileEnd": {
"line": 14,
"offset": 10
}
},
As you can see there is a comment test comment at line 14 in the file SampleForVSTS/Program.cs.
You can write simple code in any language to get the data with Rest API.

Related

Pull Request Statuses - Added custom properties to a status aren't getting persisted by TFS

We are operating a TFS 2018 Update 2 in our enviroment.
We are sending the example json found here to our server and it is getting accepted successfully:
{
"properties": {
"sampleId": 7,
"customInfo": "Custom status information",
"startedDateTime": {
"$type": "System.DateTime",
"$value": "2017-09-19T14:50:26.7410146Z"
},
"weight": {
"$type": "System.Double",
"$value": 1.75
},
"bytes": {
"$type": "System.Byte[]",
"$value": "dGhpcyBpcyBzYW1wbGUgYmFzZTY0IGVuY29kZWQgc3RyaW5n"
},
"globalId": {
"$type": "System.Guid",
"$value": "1e788cb9-9d3d-4dc6-ac05-822092d17f90"
}
},
"state": "succeeded",
"description": "Sample status succeeded",
"context": {
"name": "sample-status-1",
"genre": "vsts-samples"
},
"targetUrl": "http://fabrikam-fiber-inc.com/CI/builds/1"
}
But the response doesn't look like in the documentation. Instead it looks like this:
{
"id": 6,
"state": "succeeded",
"description": "Sample status succeeded",
"context": {
"name": "sample-status-1",
"genre": "vsts-samples"
},
"creationDate": "2019-12-11T16:14:05.0574648Z",
"updatedDate": "2019-12-11T16:14:05.0574648Z",
"createdBy": {
"displayName": "...",
"url": "https://.../_apis/Identities/0b85e078-130d-4cb8-a450-17c5c7efccec",
"_links": {
"avatar": {
"href": "https://.../_api/_common/identityImage?id=0b85e078-130d-4cb8-a450-17c5c7efccec"
}
},
"id": "0b85e078-130d-4cb8-a450-17c5c7efccec",
"uniqueName": "...",
"imageUrl": "https://.../_api/_common/identityImage?id=0b85e078-130d-4cb8-a450-17c5c7efccec"
},
"targetUrl": "http://fabrikam-fiber-inc.com/CI/builds/1",
"_links": {
"self": {
"href": "https://.../_apis/git/repositories/35fe73eb-7af1-4bba-bf04-545611fcac1d/pullRequests/58/statuses/6"
},
"repository": {
"href": "https://.../_apis/git/repositories/35fe73eb-7af1-4bba-bf04-545611fcac1d"
}
}
}
The properties are gone. What could be wrong?
Could it be a somehow completely missleading documentation?
To troubleshoot your issue, please check the following items:
Check whether the Status updated on the pull request after running the POST request.
Press F12 in your browser, and send the POST request to check the statuses to see whether you can get properties in the response body.
Check your TFS edition by going to Administration Console -- Application Tier, or checking the About on the web portal. The issue can not be reproduced in TFS 2018.2 on our side.

How fetch "webParts" from site pages

I am trying to fetch Pages from Sharepoint sites using graph API.
But when we make GET request with
https://graph.microsoft.com/beta/sites/{site-id}/pages/{page-id}
the response consists of webParts which only have type and data.
Inside data we have an id(which same as type) and an instanceId that is unique for every webPart.
Sample webPart:
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"id": "d1d91016-032f-456d-98a4-721247c305e8",
"instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
}
My goal is to fetch webPages with complete details and then backup them to a local drive in any format.
The documentation of graph API shows that the responce would consist of complete details for the webPart, but it is not so.
Documentation link: https://learn.microsoft.com/en-us/graph/api/sitepage-get?view=graph-rest-beta&tabs=http
Sample request URL:
https://graph.microsoft.com/beta/sites/m365x214355.sharepoint.com,c1e5444e-12d8-43d3-96b1-f2f66559ef58,b181bdf0-9680-4988-81f7-a24aee4afd6a/pages
Webpart repsonse:
"webParts": [
{
"type": "rte",
"data": {
"innerHTML": "<p>Take a look at the team behind delivering amazing fashion events for Contoso.</p><p>Find out how the team uses the latest technology to plan amazing fashion shows and gather customer feedback for future events.</p><p>Meet the people behind Contoso's events, learn how to plan your own event, and find the necessary resources to run highly successful fashion shows, premiers, and extravaganzas!</p>"
}
},
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"id": "d1d91016-032f-456d-98a4-721247c305e8",
"instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
}
},
{
"type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"data": {
"id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"instanceId": "75ccfeba-ad6c-416d-a859-4a6b114e156e"
}
},
{
"type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"data": {
"id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
"instanceId": "f04e02fb-45e6-4e74-9f46-0c8d90e7fb8d"
}
},
{
"type": "275c0095-a77e-4f6d-a2a0-6a7626911518",
"data": {
"id": "275c0095-a77e-4f6d-a2a0-6a7626911518",
"instanceId": "c1a222b0-624e-4e30-b544-d2a67e8e1112"
}
}
Expected Response format:
"webParts": [
{
"type": "rte",
"data": {
"innerHTML": "<p>Here are the team's upcoming events:</p>"
}
},
{
"type": "d1d91016-032f-456d-98a4-721247c305e8",
"data": {
"title": "Events",
"description": "Display upcoming events",
"serverProcessedContent": {
"htmlStrings": {},
"searchablePlainTexts": {
"title": ""
},
"imageSources": {},
"links": {
"baseUrl": "https://www.contoso.com/sites/Engineering"
},
"componentDependencies": {
"layoutComponentId": "8ac0c53c-e8d0-4e3e-87d0-7449eb0d4027"
}
},
"dataVersion": "1.0",
"properties": {
"selectedListId": "032e08ab-89b0-4d8f-bc10-73094233615c",
"selectedCategory": "",
"dateRangeOption": 0,
"startDate": "",
"endDate": "",
"isOnSeeAllPage": false,
"layoutId": "FilmStrip",
"dataProviderId": "Event",
"webId": "0764c419-1ecc-4126-ba32-0c25ae0fffe8",
"siteId": "6b4ffc7a-cfc2-4a76-903a-1cc3686dee23"
}
}
}
]
I want webParts in the format as per documentation.
If the instanceId is unique then there might be some reference table to match these instanceIds and fetch the detailed webParts structure.

how to create a confluence page using rest api with a label

I checked the documentation and I saw how to update an existing page to add the labels.
What I need is to create a new confluence page with a specific label that is added during this creation.
With get I saw that for a existing page, labels are stored into the metadatas:
"metadata": {
"labels": {
"results": [
{
"prefix": "global",
"name": "labelName1",
"id": "2195459"
},
{
"prefix": "global",
"name": "labelName2",
"id": "2195460"
}
],
"start": 0,
"limit": 200,
"size": 2,
"_links": {
"self": "http://localhost:8090/rest/api/content/2129921/label"
}
},...
Can anyone tell me if it is possible to create a page with a label and if yes, how?
Thanks
According to the documentation (https://docs.atlassian.com/confluence/REST/latest/#content/{id}/label-addLabels), you can add the following to your json for creating the page:
"metadata": {
"labels": [
{
"prefix": "global",
"name": "label1"
},
{
"prefix": "global",
"name": "label2"
}
]
},
I have not, however, been successful at getting this implementation to work yet. It seems to be ignored when I invoke the post to the endpoint (/rest/api/content).
I did some tests and found out that if you add below json node just after body node a curl will create the page with label2 successfully.
,"metadata": {"labels": [{"prefix": "global","name": "label2"}]}

Jenkins Bitbucket Plugin - Cannot parse POST data

Sending a POST request to /jenkins/bitbucket-hook causes a 500 error:
javax.servlet.ServletException: net.sf.json.JSONException: A JSONObject text must begin with '{' at character 0 of
Regardless of the content type, or body data.
The body data being sent is that outlined by Bitbucket:
{
"canon_url": "https://bitbucket.org",
"commits": [
{
"author": "marcus",
"branch": "master",
"files": [
{
"file": "somefile.py",
"type": "modified"
}
],
"message": "Added some more things to somefile.py\n",
"node": "620ade18607a",
"parents": [
"702c70160afc"
],
"raw_author": "Marcus Bertrand <marcus#somedomain.com>",
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
"revision": null,
"size": -1,
"timestamp": "2012-05-30 05:58:56",
"utctimestamp": "2012-05-30 03:58:56+00:00"
}
],
"repository": {
"absolute_url": "/marcus/project-x/",
"fork": false,
"is_private": true,
"name": "Project X",
"owner": "marcus",
"scm": "git",
"slug": "project-x",
"website": "https://atlassian.com/"
},
"user": "marcus"
}
Jenkins is the most up to date version, along with the Bitbucket plugin.
Update: I have used the data directly taken from BitBucket.
http://www.posttestserver.com/data/2015/05/20/sb/02.50.32555038623
I think I have answered my own question.
For me to get rid of that error I just had to add a trailing slash to the url... Something so simple worked for me. Might be worth others trying it too.

How do I retrieve issues of specific status with JQL

Entering a url, or running with curl, like:
https://<myurl>/rest/api/2/search?jql=project=<myproject>&status=closed&fields=id,key,status,project&maxResults=5
returns me 5 items in my project but with all statuses. For some reason I can't query for a specific status.
The output (part of it) is:
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 5,
"total": 727,
"issues": [
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "79577",
"self": "https://<myurl>/rest/api/2/issue/79577",
"key": "<myproject>-774",
"fields": {
"project": {
"self": "https://<myurl>/rest/api/2/project/<myproject>",
"id": "14421",
"key": "<myproject>",
"name": "<myproject>",
"avatarUrls": {
(...)
}
},
"status": {
"self": "<myurl>/rest/api/2/status/1",
"description": "The issue is open and ready for the assignee to start work on it.",
"iconUrl": "https://<myurl>/images/icons/statuses/open.png",
"name": "Open",
"id": "1"
}
}
},(...)
]
}
How to query for a given status? Many thanks.
Use URL encoding on the attributes.
Perhaps use an online tool like this to URL encode your JQL from this:
project = PROJECTKEY AND status = Closed
to get this:
/rest/api/2/search?jql=project%20%3D%20PROJECTKEY%20AND%20status%20%3D%20Closed&fields=id,key,status,project&maxResults=5
The resulting JSON will be all closed issues.
Run the query you want in the Issue Navigator. Use the link to the left of the Share button that resembles a chain link to find the URL for the query, e.g.
http://jira.example.com/issues/?jql=project%20%3D%20MDOAR%20and%20status%20%3D%20Closed
Use that URL with curl

Resources