Is there a way to get the raw diff of a commit via the Azure Devops API? - azure-devops

As part of our application, we're building an ability to integrate with Azure DevOps' REST API. One key component that we're interested in is being able to see actual diffs of specific commits, so that we can look at and analyze the line content. We've already created this integration for GitHub, GitLab, and Bitbucket, and each time it was easy: There's a fairly simple diff endpoint for each that takes in a specific commit ID and diffs it (sometimes with a specific parent commit).
I've not had much luck finding this same functionality in Azure DevOps, however: The diffs endpoint has some data related to this, but it is really just an overview of which files changed and the high-level nature of those changes, along with the IDs of specific blobs that represent the files in each state (before and after).
It's theoretically possible to use those blobs to manually construct what I'm after, and indeed I've been able to query for the before and after blobs to get a diff on each file. But that's two separate endpoint queries per file -- take a twenty-file commit, and suddenly we'd need 40 API calls just to construct a reasonable diff. That doesn't really fit our performance needs, unfortunately.
Is there a separate API endpoint or technique that lets us get to the raw diff? It doesn't need to be a raw diff a la git diff directly, just anything that lets us see the before and after state of each line (rather than each file) with minimal API calls (preferably just one). I've done much scouring through the docs and here on StackOverflow, and not found anything that accomplishes this.

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}?changeCount={changeCount}&api-version=5.0
In the Rest API Result, you need to record the value of “parentsid”, “path”.
Step3: 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:
This is the ticket I refer to, hope it helps you.

Related

Right way to commit to Github using Github API

I am using the Github API to create a plugin for a note-taking app, I am using a lot. Right now I fetch latest commit, get the tree, get all file contents for each file (a seperate call for each) and comparing all files etc. You get the idea, I end up making a ton of API calls which leads me to exceeding the limit per hour of the API. What is the recommended approach or how do I commit a lot of files in a good way?
As said I've tried with a lot of API-calls but it doesn't end up fast nor below the API limit.

Programmatically create a commit containing Git-LFS data to a Github Repository

Ether by using the GraphQL (Preferred but seems unlikely), REST API, or by any other means.
Ideally it would be possible to commit the LFS objects and regular objects in the same commit.
I have been using the GraphQL API to successfully query and download LFS objects. I was hoping that it would be possible to also create commits that contain LFS objects.
Unfortunately it seems like createCommitOnBranch doesn't provide a documented way of doing that. So I am left with looking for alternatives.
A version of this question is in the Github Community GraphQL category: https://github.community/t/create-a-commit-containing-lfs-data-via-graphql/252637

GitHub REST API: Commits per release

I'm trying to obtain the commits that were included on an specific release, on a repository that uses tags to identify releases. According to this answer, this doable through git log.
However, I need to gather this information for several repositories, so using an API is more convenient. Is it possible to get that information from GitHub's REST API?
You can use the compare two commits API:
GET /repos/:owner/:repo/compare/:base...:head
This is the same as locally running git log base..head.
Given that you want to automate this for several repos check List your Repositories API as well
Let me know if you need more info.

GitHub to share a set of SPARQL queries

I am using github to share a set of SPARQL queries:
http://www.boisvert.me.uk/opendata/sparql_aq+.html?file=specific%20sensor.txt
Currently the simple work allows end-users to access queries stored on the github repository, but ultimately I want to allow them to also modify the queries, as with a pastebin, and make use of the repository to better manage the shared system. Ideally I would want end-users who may not be very tech-savvy, to be able to make minor changes to queries to an open, linked data endpoint: so to keep the technology barrier low.
My problem is this: how best to structure the github project and exploit the API to make the most of the available information? I can think of different points:
Currently the project (https://github.com/boisvert/unshaql) holds client code and example queries. Does it make a difference to create an independent project (separate from the web client code) for SPARQL queries?
I would use directories within the project to classify/tag queries, and file names to title them. Are there better alternatives? It strikes me that a hierarchical structure is not a good fit to tags.
When end-users save, a simpler (and cruder) option is to allow them to push their file into just one branch, which holds the examples. A better engineered one would be to allow them to use their github credentials to fork the set of SPARQL queries and edit theirs, but with unaware users, how do I avoid creating a mess?
I think that a rigular Github repository is a rather bad fit for this kind of content. If your users have a GitHub account, you should probably use Gists instead: https://help.github.com/articles/about-gists/ I never used this myself, but it seems perfectly adapted to what you are planning. Your site could become a DB of tags over user-provided gists. That would however lock you into GitHub-specific solutions.
Even if you go for a regular repository, you should not allow the users to commit into the repository hosting your code: that would be a serious security hazard as you won't be able to control the parts of the repository to which they are allowed to commit.
If you setup two repositories, it's rather easy to have the code of a webpage in a repository, and the code automatically commited in another repository (under an anonymous identity so that your users don't have to create a github account).
Also, note that the oauth token should never be stored in a public repository (or the GitHub robots will invalidate it in a matter of hours).
See Hiding GitHub token in .gitconfig for a solution to this sub-problem.

Getting Jira Issue's Branches from REST API

I am working with the Atlassian product Jira's REST API, combined with Stash. I have the two applications linked so that I can create branches in Stash for the Jira tickets. That is all working great, but what I need is a REST API call or really any call to get the branches for the issue to help automate our development process.
/rest/api/2/{issueid} // Doesn't work
The standard issue pull, Atlassian documentation https://docs.atlassian.com/jira/REST/6.0.1/#id147461, doesn't give me any information about the branches created for the issue.
The only other way I can think of to get the information is to scan every project's repo for the specific name of the ticket, which sounds wildly inefficient.
I'm using:
Jira version 6.2.6
Stash version 3.0.1
Found the rest url I was looking for and so far I have found zero documentation on it. Anyway I am going to use it as this is the actual url that Jira uses in the user interface.
{Jira App Url}/rest/dev-status/latest/issue/detail?issueId={IssueKey}&applicationType=stash&dataType=pullrequest
The docs: https://quickstart.atlassian.com/download/stash/jira-integration mention there is information about "all branches related to the issue". The decision which branch is related to which issue comes from branch name. I assume what you would like to get is "all branches that have commits related to particular issue" (issue key must be in commit message). As far as I know this is not supported at the moment.
One solution that comes to my mind is using Stash git hooks (https://blogs.atlassian.com/2013/03/stash-22-customize-workflow-git-hooks-api-merge-checks/) with custom JIRA plugin that exposes custom REST API to collect information triggered by git hook.
I'd look at the source for the JIRA part of the integration to see what REST calls it makes to stash. They're probably ones documented here: https://developer.atlassian.com/static/rest/stash/3.0.4/stash-branch-utils-rest.html
but they may also use the core REST API for Stash
Try This :
{Jira App Url}/rest/dev-status/latest/issue/detail?issueId={IssueKey}&applicationType=stash&dataType=repository