Is it possible to get a list of commit comments via the Azure devops API?

Viewed 1068

When viewing a commit in the web interface for an Azure Devops repo, it's possible to leave a comment on a commit by clicking to the left of a specific line and typing something in the box that appears. I'm building a tool that takes various analytics of remote repositories, including the frequency and volume of feedback on commits. Being able to get this information (or at least a summary of it, like a comment count per commit) would be excellent. Is it possible to get a list of such comments?

Such information definitely exists for pull requests, via this API method. PR comments and commit comments have a very similar interface, and I can confirm the PR method to be working, but have had no such luck finding an equivalent method for commits themselves. I've tried scanning the documentation, to no avail, as well as interrogating the output of various things like file diffs and commit info, which also don't contain the commit comments.

Does such functionality exist within the Azure Devops API in any form?

1 Answers

Does such functionality exist within the Azure Devops API in any form?

1.We can use Get Commits to retrieve all available git commits for one specific repo:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.1

Also we can use Get to retrieve a particular commit:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.1

Both them can give you the comments for corresponding commits.

enter image description here

Note:

The comment here indicates the initial comment for one commit, see:

enter image description here

2.If you're trying to get the comments created with this button:

enter image description here

The comments here are different things from the initial comments. We call them content in discussion... And here's one undocumented api you can use:

Replace the {OrganizationName},{ProjectID},{RepostoryID} and {CommitID} with your own values, it should work to get the comments in the discussion.

Get https://dev.azure.com/{OrganizationName}/_apis/discussion/Threads?artifactUri=vstfs%3A%2F%2F%2FGit%2FCommit%2F{ProjectID}%252F{RepositoryID}%252F{CommitId}&api-version=5.0-preview.1

1). My comments(not initial comment):

enter image description here

2). My url:

enter image description here

3). Result:

enter image description here

enter image description here

enter image description here

In addition:

1.Get ProjectID by name:

https://dev.azure.com/{organization}/_apis/projects/{projectName}?api-version=5.1)

2.Get RepoID by name:

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}?api-version=5.1

3.We can easily get the commitID in web portal UI with the Copy Full SHA button. Or use commits-related api.

Related