Forum Discussion

chamidu_sumanasekara's avatar
chamidu_sumanasekara
Copper Contributor
Nov 13, 2024

Azure GIT - can we get PR list between two tags

Hi,

We are looking for an API or a workaround to get the list of PRs between two tags

ex: assume we have tag-1 from dev branch and after few PRs merged to the dev branch, we create tag-2.

now I would like to retrieve the list of PRs happened between tag-1 and tag-2 

 

2 Replies

  • chamidu_sumanasekara 

    To get the list of PRs between two tags in Azure DevOps.

    1. Get Commits Between Tags
    Run this Git command to get commit IDs between tag-1 and tag-2
    git log tag-1..tag-2 --oneline

    2. Fetch PRs for Each Commit:
    Use the Azure DevOps API to get PRs for each commit ID
    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/pullRequests?api-version=7.1-preview.1

    3. Consolidate PRs
    Combine the PRs retrieved from each commit, removing duplicates to get the unique list.

    This approach gives you the PRs between tag-1 and tag-2.

    • Get Commit History Between Two Tags: Use the Commits REST API to list the commits between two tags. This helps identify the commit range associated with the tags.
      • API Endpoint: GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?searchCriteria.fromCommitId={tag1CommitId}&searchCriteria.toCommitId={tag2CommitId}&api-version=6.0
      • Replace {organization}, {project}, {repositoryId}, {tag1CommitId}, and {tag2CommitId} with the appropriate values.
      • You can find the commit IDs associated with your tags using the Refs API (GET /_apis/git/repositories/{repositoryId}/refs?filter=tags/).
    • Map Commits to PRs:
      • After getting the list of commits between the two tags, use the Pull Requests REST API to find PRs that merged those commits.
      • You can filter PRs using the commit ID with the following API:
        • API Endpoint: GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests?searchCriteria.sourceRefName=refs/heads/{branch}&status=completed&api-version=6.0
      • Check for the mergeCommitId or use the commits relation in each PR to match with your commit list.
    • Script Automation:
      • Write a script (using PowerShell, Python, or any tool of your choice) to automate fetching the commit IDs between the two tags and mapping them to PRs.
      • Use the Azure DevOps Personal Access Token (PAT) for authentication when making API calls.

Resources