Answers: <p>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:</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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).</p>
  <p>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.</p>
  <p>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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-03-07T16:15:37.820Z
Answers: 2024-03-07T16:15:37.820Z
Answers: geeky_girl
Body: <p>I have just got the responsibility for around 100 different repositories (applications), distributed on about 20 project in Azure DevOps.</p>
  <p>I want to get some (very) basic metrics on each project:</p>
  <ul>
  <li>Numbers and names of repositories in each project</li>
  <li>Number of branches in a repository</li>
  <li>Number of files in a branch</li>
  <li>Number of code lines in a branch</li>
  <li>Names of developers which has worked on a project</li>
  <li>Number of developers which has worked on a project</li>
  <li>First and last commit/pull request from a developer on a project</li>
  <li>etc.</li>
  </ul>
  <p>Just simple counting and listing. Nothing fancy as test coverage etc. So far all my searching has only given results about code analysis and other advanced stuff. It's not where I am in my tasks right now.</p>
  
Comments: CC BY-SA 4.0
Comments: 2024-03-06T17:00:48.973Z
Comments: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments: Community
Tags: <azure><metrics><repository>
Title: Simple metrics of code in Azure Devops
UserDisplayName: Anders Finn Jørgensen
ThreadText: # Simple metrics of code in Azure Devops
  
  (Asked by: username_0 on 2024-03-06)
  
  I have just got the responsibility for around 100 different repositories (applications), distributed on about 20 project in Azure DevOps.
  
  I want to get some (very) basic metrics on each project:
  
  * Numbers and names of repositories in each project
  * Number of branches in a repository
  * Number of files in a branch
  * Number of code lines in a branch
  * Names of developers which has worked on a project
  * Number of developers which has worked on a project
  * First and last commit/pull request from a developer on a project
  * etc.
  
  Just simple counting and listing. Nothing fancy as test coverage etc. So far all my searching has only given results about code analysis and other advanced stuff. It's not where I am in my tasks right now.
  
  **Tags:** azure, metrics, repository
  
  > **Comments:**
  > **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-03-07. Score: 0 | Accepted answer
  
  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.
  
  
  ---
  
  