Get Lines of Code edited for a Commit in Azure DevOps Rest API: large files edited (changeType==3) don't return full changes - azure-devops-rest-api

when attempting to get the line changes for a very large file (10K+ lines), not all changes are returned. is there a way to paginate the return result? or a different query parameter that can be sent so as to not truncate the response?
url = https://{account}.visualstudio.com/{project}/_api/_versioncontrol/fileDiff?__v=5&diffParameters={params}&repositoryId={repositoryId}
params (removing spaces) =
{
"originalPath": commit path,
"originalVersion": parent commit_id,
"modifiedPath": commit path,
"modifiedVersion": commit_id,
"partialDiff": True
}
(Expected) sample response (based on this answer):
{
"changeType": 2,
"mLine": 9,
"mLines": [],
"mLinesCount": 0,
"oLine": 9,
"oLines": [
" <!-- Polyfill(s) for older browsers -->"
],
"oLinesCount": 1
},
{
"changeType": 1,
"mLine": 22,
"mLines": [
" <div>2</div>"
],
"mLinesCount": 1,
"oLine": 23,
"oLines": [],
"oLinesCount": 0
}
I am able to get a response. But the response does not include line changes that are found far down the file; this is usually denoted when reviewing the commit via the UI with this warning: "The file is too large to be included in the change summary view. Navigate to the file to view the full diff."

I'm afraid there is no way to get all lines in your scenario. As the top and skip parameter don't work in this api. You may check whether there is continuationToken in the response hearder, if there is continuationToken, then try to add continuationToken={continuationToken} in the api to see whether it works. If there is no continuationToken, then there is no way to get all lines in your file as it too large.

Related

API POST Endpoint for Inline Pull Request Comments?

I’m hoping someone can help me be able to post inline comments on PR’s. In the UI version of Bitbucket, you can post a comment on a specific line, for example, line 6 (see screenshot):
However, when I try to send a POST request to the API, it won’t do an inline comment. All I can get it to do so far is post the comment at the end, rather than on a specific line, like line 6, as shown in this screenshot:
The POST endpoint I’m using is (https://api.bitbucket.org/2.0/repositories/{workspace}/{repo}/pullrequests/6/comments) and I’m sending the following information in body:
{
"content": {
"raw": "will this work on one line?"
},
"inline": {
"from": 6,
"to": 7,
"path": "style.css"
}
}
No matter what I put in the “from” and “to” it always puts the comment at the end, like in the 2nd screenshot, rather than inline, like it does in the UI (1st screenshot). Does anyone have any suggestions for getting the POST request to do inline comments like the UI version allows?
The API documentation tells you how to use them. You should use either-or. In your example you are trying to write on old file line 6, which will be the value taken, which is at the end of the snippet, where the comment is displayed like you show.

Google Docs API : How to update alignment of the table?

I have a Table in the google docs and want to change its alignment to -0.71 but i do not see any Python API to change table properties. This can be done easily using following UI on google UI (as shown below):
I also tries looking at following requests but could not find it:
updateTableColumnProperties
updateTableCellStyle
For debugging, i created a doc with mentioned alignment and tried dumping JSON of it. But i do not see alignment keyword in the JSON.
Thanks #jescanellas for reply.
I found a hack, this may not be the best solution but works.
1) Update paragraph style and set the indentation, alignment as required. Here the start_idx is the index where table needs to be created.
request = [{
'updateParagraphStyle': {
'paragraphStyle': {
'namedStyleType': 'HEADING_5',
'direction': 'LEFT_TO_RIGHT',
'alignment': 'START',
'indentFirstLine': {
'magnitude': -51.839999999999996,
'unit': 'PT'
},
'indentStart': {
'magnitude': -51.839999999999996,
'unit': 'PT'
},
},
'fields': '*',
'range': {
'startIndex': start_idx,
'endIndex': end_idx
}
}
}]
2) Create the table, it will get created at new indented place.
request = [{
'insertTable': {
'rows': 1,
'columns': 1,
'location': {
'segmentId':'',
'index': start_idx
}
},
}]
It's not currently possible to do so. You can create a Feature Request for the Docs API, and you can also subscribe to this one for Apps Script by clicking on the star next to the Issue number to give more priority to the request and to receive updates.
In case of the second request being implemented, you could call the script from the command line using Clasp.

BitBucket 1.0 REST API Retrieve all Pull-Requests for repository

When I curl the rest api, I get back an empty response but I know that there are pull-requests open.
What is the setting in bitbucket stash that allows anyone to view/read pull-requests without being authenticated?
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests
response:
{
"size": 0,
"limit": 25,
"isLastPage": true,
"values": [],
"start": 0
}
Try
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests?state=ALL
You can find more options for this specific API call at https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm140236731714560
This worked for me:
curl -D- -u user:password -X GET -H "Content-Type: application/json" -X GET https://bitbucket.com/rest/api/1.0/projects/ONEP/repos/oneplanner/pull-requests?state=OPEN
To check status to particular PR:
curl -X GET https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pr-id}
DOC https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8287391664
Paged APIs
Bitbucket uses paging to conserve server resources and limit response size for resources that return potentially large collections of items. A request to a paged API will result in a values array wrapped in a JSON object with some paging metadata, like this:
{
"size": 3,
"limit": 3,
"isLastPage": false,
"values": [
{ /* result 0 */ },
{ /* result 1 */ },
{ /* result 2 */ }
],
"start": 0,
"filter": null,
"nextPageStart": 3
}
Clients can use the limit and start query parameters to retrieve the desired number of results.
The limit parameter indicates how many results to return per page. Most APIs default to returning 25 if the limit is left unspecified. This number can be increased, but note that a resource-specific hard limit will apply. These hard limits can be configured by server administrators, so it's always best practice to check the limit attribute on the response to see what limit has been applied. The request to get a larger page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?limit={desired size of page}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?limit=1000
The start parameter indicates which item should be used as the first item in the page of results. All paged responses contain an isLastPage attribute indicating whether another page of items exists.
Important: If more than one page exists (i.e. the response contains "isLastPage": false), the response object will also contain a nextPageStart attribute which must be used by the client as the start parameter on the next request. Identifiers of adjacent objects in a page may not be contiguous, so the start of the next page is not necessarily the start of the last page plus the last page's size. A client should always use nextPageStart to avoid unexpected results from a paged API. The request to get a subsequent page should look like this:
http://host:port/context/rest/api-name/api-version/path/to/resource?start={nextPageStart from previous response}
For example:
https://stash.atlassian.com/rest/api/1.0/projects/JIRA/repos/jira/commits?start=25

Time from creation to closed

I am trying to calculate the average time for all the jira cases that are created and until they are resolved.
How can this be done, for a specific project?
You dont say how you want to calculate this.
The simplest way is to add the Resolution Time Gadget to your dashboard. Here you can add a filter to specify which issues you want to consider.
This will give you a nice bar chart of the average resolution times of issues over a given period
If you want more control, you can write a script for it with the Jira REST API
If you create a jql for the issues you are interested in, you can call the REST api with a url like this:
https://jira.intern.sparebank1.no/rest/api/2/search?jql=assignee=e6462u
This will return a whole bunch of info, but you are most interested in the issues array elements, and specifically the fields "created" and "resolutiondate"
A snipped version of the JSON returned is:
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 1,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields",
"id": "104799",
"self": "https://jira.domain.com/rest/api/2/issue/104799",
"key": "HELLO-1",
"fields": {
...
"resolutiondate": "2015-06-25T09:12:27.000+0200",
"created": "2015-03-18T16:18:38.000+0100"
...
}
}
]
}
Now you can calculate the difference between the two for each issue element and find an average.
More info on Jira REST API: https://docs.atlassian.com/jira/REST/latest/
A blog I wrote on how to script stuff like this (and present in a graph in confluence ;) ): http://javamemento.blogspot.no/2016/05/jira-confluence-3.html

Elasticsearch: aggregation of URLS

I want my elasticsearch / Kibana4 to give me an overview which pages of my website are viewed most. I have a field "request" but since the URLs listed there contain parameters, I get a false list of the top requests
Example:
/search?query=123
/search?query=234
Each request is shown as a single request
but
home/foobar
home/foobar
is listed with 2 requests and is the top request in this case.
How can I tell elasticsearch to aggregate the requests that contain parameters?
There are number of ways to solve this.
One would be setting the url field as not_analyzed and then using script to parse out the unwanted value.
A sample script can be found here -
{
"aggs": {
"urls": {
"terms": {
"field": "url",
"script" : "_value.split("?")[0]"
}
}
}
}
Another approach would be to add a multifield and then remove the part after '?' using custom analyzer . You can achieve this by removing anything after '?' using pattern replace tokenizer

Resources