1 | initial version |
To extract the code changes associated with each commit ID using the AzureDevOps API, you can use the following steps:
CoreHttpClient
to get the code changes associated with a particular commit ID.GitHttpClient
to get the repository details.GitHttpClient
again to get the changes associated with each commit ID.changeType
property.Here is an example code snippet to extract the code changes associated with each commit ID using the AzureDevOps API:
// Authenticate with AzureDevOps using a Personal Access Token (PAT).
string personalAccessToken = "YOUR_PAT";
VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/YOUR_ORGANIZATION"), new VssBasicCredential(string.Empty, personalAccessToken));
// Get the code changes associated with a particular commit ID.
string commitId = "COMMIT_ID";
var gitClient = connection.GetClient<GitHttpClient>();
var changes = gitClient.GetChangesAsync("YOUR_PROJECT_NAME", "YOUR_REPO_NAME", new GitQueryCommitsCriteria() {Ids = new List<string>() { commitId } }).Result;
// Get the repository details.
var repo = gitClient.GetRepositoryAsync("YOUR_PROJECT_NAME", "YOUR_REPO_NAME").Result;
// Get the changes associated with each commit ID.
var coreClient = connection.GetClient<CoreHttpClient>();
var changeDetails = new List<string>();
foreach (var change in changes.First().Changes)
{
if (change.Item.Path.StartsWith($"{repo.Name}/"))
{
var changeDetail = $"Path: {change.Item.Path}\nChange Type: {change.ChangeType}\n";
changeDetails.Add(changeDetail);
}
}
// Parse the `changeType` property to extract the code changes.
foreach (var changeDetail in changeDetails)
{
Console.WriteLine(changeDetail);
// Here, you can extract the code changes by parsing the `changeType` property.
}