To gather basic metrics on your Azure DevOps projects and repositories, you can use the Azure DevOps REST API. Here’s a general approach to getting the metrics you need:
List of repositories in each project:
Use the GET request to {organization}/{project}/_apis/git/repositories?api-version=6.0. This will give you the names and IDs of all repositories in a project.
Number of branches in a repository:
For each repository, make a GET request to {organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=6.0. This will list all branches in the repository.
Number of files in a branch:
This is trickier because there's no direct API to count files per branch. You might need to clone the repository and use a Git command like git ls-tree -r branchName --name-only | wc -l to list and count files.
Number of code lines in a branch:
Similarly, after cloning the repository, you can use a command like git ls-files | xargs wc -l in the branch to get the total lines of code.
Names and number of developers who worked on a project:
Use the GET request to {organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=6.0 to fetch commits. From the commit data, you can extract the authors (developers).
First and last commit/pull request from a developer on a project:
With the commit data fetched above, you can filter by author and sort by date to find the first and last commit for each developer.
You will need to write scripts that automate these API calls and process the responses to generate your metrics. For authentication, you might use a personal access token (PAT) with your requests to access the Azure DevOps REST API.