azure-devops-cli-extension icon indicating copy to clipboard operation
azure-devops-cli-extension copied to clipboard

Pull Request command should support creating PR from forked repo

Open tobieheyns opened this issue 4 years ago • 7 comments

[Edit] Converting the issue to a enhancement PR create command should support creating a new PR from a forked repo into the source repo.

Original reported issue:

I use the following command: az repos pr create -r <id_of_main_repo> -s master -t master

I get the return message The source branch, "refs/heads/master", can not be the same as the target branch.

To set the context: On devops on Azure I have a main repo of the project, and I have a forked repo of the main, which I work on.

I want to do a pull request from forked repo's master branch to the main repo's master branch. I am running the command in the folder of the GIT repo on my local machine, so I am assuming the az tool will pick up source repo's ID.

I need some guidance on my command please.

tobieheyns avatar Aug 03 '19 06:08 tobieheyns

@tcheyns Sorry for the trouble you went through but creating PRs to source repo from forked repo is not supported in the PR command. I am editing this issue to track the work that needs to be done. Please follow the issue for updates.

atbagga avatar Aug 05 '19 04:08 atbagga

Thanks so much for your reply.

tobieheyns avatar Aug 05 '19 09:08 tobieheyns

We are also waiting for this functionality. I tried to use az devops invoke but cannot seem to pick the right area/resource/version to POST the request to the desired URL. As a workaround we use the REST API.

lnist avatar Aug 15 '19 11:08 lnist

omg, are you kidding me? this is not supported .... apparently still?

bitsofinfo avatar Oct 13 '20 16:10 bitsofinfo

@LasseNisted can you please share your workaround?

bitsofinfo avatar Oct 13 '20 16:10 bitsofinfo

for anyone else fumbling around in the dark on this, you can do it manually w/ the API, this seems to work

Get a PAT token for your user:

curl --location --request POST 'https://dev.azure.com/TARGET_ORG/TARGET_PROJECT/_apis/git/repositories/GIT_REPO_NAME/pullrequests?supportsIterations=true&api-version=5.1' \
--header 'Authorization: Basic [BASE64 encoded <yourusername>:<yourPATtoken>]' \
--header 'Content-Type: application/json' \
--data-raw '{
  "sourceRefName": "refs/heads/BRANCH_NAME_IN_THE FORK",
  "targetRefName": "refs/heads/TARGET_BRANCH_NAME",
  "title": "WHATEVER",
  "description": "WHATEVER",
  "forkSource": {
      "name": "NAME_OF_FORK_REPO",
      "repository": {
          "id": "ID_OF_FORK_REPO"
      }
  }
}'

bitsofinfo avatar Oct 13 '20 17:10 bitsofinfo

Any updates on this? An equivalent solution to the hub or gb pr create command would be highly appreciated. Thanks!

fdammeke avatar Sep 15 '23 10:09 fdammeke