Code Sharing (PowerShell): Create Pull Request via VSTS REST API

Visual Studio Team Services Git Love

This past week I started concentrating on optimizing our release processes. I’ve talked about how our team uses VSTS and Git in a previous post. At the end of a sprint, pull requests are created in all of our repositories to merge to the release branches. As the number of our repositories continues to grow, the number of manual steps to merge for releases grows exponentially. Having worked with the VSTS REST API in the past I knew this wouldn’t be difficult to automate. A build would be run that runs the script below for each of our repositories to create pull requests. Service hooks to Slack would then send notifications so the necessary reviewers can approve the newly created pull requests. This same script can be used post release to merge back to Master branches. I commented on every line of code in the script below so I didn’t have to go into details here ๐Ÿ™‚

6 thoughts on “Code Sharing (PowerShell): Create Pull Request via VSTS REST API

  1. I have been looking for a solution for the exact same problem. Merging code automatically from Release branch to all user branches. The script is beautifully written explaining every detail in comments. Thank you very much for sharing the same.

  2. Greetings
    Thank you very much for the wonderful work you have done Its really help. Further i want anther help how to associate work items too with the pull request. How can we achieve it.

      1. Marcus
        Thanks a lot for your response. But in my case when i create a pull request through rest API for a specific branch workitems does not automatically pop up. But when i manually create a pull request in azure devops they do link automatically.

Leave a Reply

Your email address will not be published. Required fields are marked *