简体   繁体   中英

Cherry-pick to multiple branches

I've been working on a project that has multiple environments (imagine two branches for tests, two for pre-production, and the other two for production, etc) using different database software. Sometimes the code is almost the same, but each one of these environments has its differences. Once it's necessary to make a change in a common file between all these branches, the cherry-picking process is just exhausting.

After a few hours of research, I've found an extension called PR Multi-Cherry-Pick , but the problem is that the extension not only creates the Pull Requests but publishes them. However, one of the team's policies is to only publish a pull request after it's approved in its lower layer (only publish in pre-production after it is approved in both test repositories and so on for production). Besides that, I read the merging solution in a similar question but there's no known common ancestor between all the branches simultaneously.

Is there a way to cherry-pick and create all those PRs as drafts ? The use of the extension is not mandatory.

You could use Cherry Picks - Create api and Pull Requests - Create api to achieve what you want.

First, use Cherry Picks - Create api to create Cherry Picks:

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/cherryPicks?api-version=6.0-preview.1

Body:

{
    "generatedRefName":"refs/heads/TopicBranchName",
    "ontoRefName":"refs/heads/TargetBranchName",
    "source":{
        "pullRequestId":xx
        }
}

Then use Pull Requests - Create api to create PRs as draft:

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=6.0

Body:

{
   "isDraft": true,
   "sourceRefName": "refs/heads/TopicBranchName",
   "targetRefName": "refs/heads/TargetBranchName",
   "title": "cherrypicks"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM