Is it possible to fetch commit changes (diff only) via api? - azure-devops

I am trying to pull commit changes via api and all i get is the path to the file itself, as in the whole file.
What I want to achieve is to see the changes (diff only) for a single file per commit.
E.g:
If i query the same using Github i get the diff like so:
"## -1 +0,0 ##\n- console.log(\"Blasting!\")"
Is there a similar solution in Azure-devops?
Thanks!

What I want to achieve is to see the changes (diff only) for a single file per commit.
There is no existing Rest API to meet your needs. But you could refer to the following steps to get the content of the git diff.
Step1: You could use the Rest API to get the commit id.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.0
Step2: You could use the Rest API to get the commit by commit id.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.0
In the Rest API Result, you need to record the value of parentsid.
Step3: You could use the Rest API to Get the file path.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=6.0
Step4: You could use the following API to get the diff content.
Post https://dev.azure.com/Organization/Project /_api/_versioncontrol/fileDiff?__v=5&diffParameters={value}&repositoryId={repositoryid}
The {value} is Json type.
Here is an example:
{"originalPath":"filepath","originalVersion":"Parentsid","modifiedPath":"filepath","modifiedVersion":"commitid","partialDiff":true,"includeCharDiffs":true}
You could add the value to the API URL.
Then run the API and the result will contains the git diff content. (2 means remove, 1 means add)
Here is a result sample:
Here is the ticket, you could refer to it.

Related

Github multi-dimensional query

I am trying to query the Github RestAPI v. X-GitHub-Api-Version to find line changes (addition, deletions), user, date, repository_name for any repositories in an organization that have files of a particular file extension. Not seeing a clear path forward with this, do I need to file all files using {{baseUrl}}/search/code?q=org:{{org}}+extension:tf, then take those outputs iterating over and querying commits for a file and then extract the details from the commit details?

Merge pull request by Github API: SHA parameter

I was reading the documentation of GitHub API and I'm not sure what do do with the Merge Pull Request method.
https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
Specifically with the parameter SHA. I don't understand what exactly I should provide to API.
The INPUT section says I must provide
commit_title Title for the automatic commit message.
commit_message Extra detail to append to automatic commit message.
sha SHA that pull request head must match to allow merge.
merge_method Merge method to
use.
Where do I exactly get the sha value that I need to pass to API?
Thanks!
Consider the following diagram, which shows a feature branch derived from some base branch:
base: ... A -- B -- C
\
feature: D -- E
Let's suppose that we created a pull request from feature going back to base. GitHub would execute this pull request by merging feature into base. The pull request HEAD, at the time we created the pull request, would be commit E in feature. But, the HEAD of the feature branch could change before the pull request is completed.
The API call you mention includes the SHA-1 hash of the pull request HEAD, as a requirement for the pull request to complete. This would avoid the possibility of feature being merged back to base while containing additional commits beyond commit E.
Regarding how you would find the SHA-1 hash for E, the pull request HEAD, you may simply try using git log, e.g.
# from feature
git log
Then, check the output for what should be the latest entry from commit E, and find the hash.

Github api 'List pull requests files' only returns 30 files

I am trying to retrieve a list of all the files included in a pull request.
The Github API documentation in the following URL - https://developer.github.com/v3/pulls/#list-pull-requests-files mentions that it can retrieve a maximum of 300 files. However, when i run the request from Advanced Rest Client, i get a list of only 30 files.
Is there any way i could retrieve a list of all the files included in the pull request?
Github API paginates data in sets of 30 or 100 (depending on what you are requesting). You could consider increasing the per_page count to a higher value or just traverse through the pages. Ref: Github Pagination

Is there a way to download all release data of a github repository?

This picture shows few releases from a project. To see more, one has to press "Next" button.
Is it possible to get data (commit hash tag, date) about all releases preferably in a excel, csv, json file format or at least in a single web page.
The list releases API endpoint will provide data about each release in a repository in JSON format:
GET /repos/:owner/:repo/releases
The target_commitish field returned in the response is the nearest thing to a commit hash that is returned by this API, but you can then use the the Git Data API to return the commit SHA:
GET /repos/:owner/:repo/git/tags/:sha
Where :sha can be the string returned in target_commitish. The result of this request will give you the matching commit SHA in the sha field.

Github API: Check if a branch or repository contains a commit

Can I use the Github API to check if a certain repository contains a certain commit?
At first glance, it seems that the get a single commit API call should work, returning 404 if there is no such commit in the repository. But that is not true: It seems that this call will run successful on commits that are present in forked repositories (possibly due to a pull request). (This effect can also be observed in the regular web interface; this particular commit has not been pulled into that repository yet.)
Api GitHub search
For searching other repositories one can use the api, which finds commits via various criteria. (This method returns up to 100 results per page.):
https://developer.github.com/v3/search/#search-commits
Only the default branch is considered, mostly master
Api usage
GET /search/commits
q can be any kind of search term combination: https://help.github.com/articles/searching-commits/
Example parameters for q
hash:124a9a0ee1d8f1e15e833aff432fbb3b02632105
Matches commits with the hash 124a9a0ee1d8f1e15e833aff432fbb3b02632105.
parent:124a9a0ee1d8f1e15e833aff432fbb3b02632105
Matches children of 124a9a0ee1d8f1e15e833aff432fbb3b02632105.
further parameters, like sorting, ordering can be found in the documentation above.
Usage example per hash:
example call https://api.github.com/search/commits?q=<searchterm>+<searchterm2>
specific call: https://api.github.com/search/commits?q=repo:adejoux/kitchen-wpar+hash:0a3a228e5b250daf06f933b35b3f0eafc715be4f
You need to add an special header, because the api is available for developers to preview
header to add: application/vnd.github.cloak-preview