Search code examples
githubazure-devopsversion-controlgit-merge

How to split changes on my PR into two separate PR's without losing comments?


I made sweeping changes to 2 projects (call it Project A and B) in my team's repository in this PR *. After getting through testing, review, and getting comments resolved, I found out that a different team is working on conflicting changes to project A on a different PR and those changes need to go to staging first. Now I can't merge my PR because it has changes to A, but my changes to Project B need to be merged ASAP. Now the obvious answer is probably to abandon the PR, do a soft reset and start again with two branches, but my team wants to keep the comment threads on both A and B because they showcase a month of work and important design decisions made by multiple teams during the reviewing process. Is there a way to split my changes to Projects A and B into two separate PR's without losing all the comments?

My current solution is branch a new branch off the current one, manually undo my changes to Project A from the branch, push, and leave the comments to A dangling (I think there will be some comment view that the file reference is deleted), merge. Then create a new PR of the newest branch, copy and paste each of the 50+ dangling comments over to their respective files, resolve all, and merge. This is obviously not great because I lose some context and it will take hours. Other solutions I've seen on here will delete all existing comments altogether and I can't have that.

*Yes, I definitely shouldn't have done that.


Solution

  • There is no out of the box solution for this.

    I would suggest to use Azure DevOps APIs, and even that isn’t a walk in the park.

    Modus operandi

    Choose your language, PowerShell, js, c#, etc and start exploring. Below a suggestion where to start:

    1. Start with getting the original PR using the getbyid api
    2. Since you mention the comments are the most import part, the next thing is to retrieving list with thread comments API.
    3. Optional: Per comment iterate through the thread with the next get api, because the docs state: Represents a comment which is one of potentially many in a comment thread.
    4. From this point, retrieve more info you need or start building the copy of the PR with, create PR and adding comments and other part you need to reuse.

    Again, this is not easy and maybe retrieving and saving this in another format already helps you.

    I did tried to find a solution for you online, but did find it (yet). Found other handy stuff like this quick and dirty js script to search through comments.