Skip to content

Instantly share code, notes, and snippets.

@VitorBlog
Last active April 16, 2024 18:29
Show Gist options
  • Save VitorBlog/947e4dba16d55eb33752338b18d02ea5 to your computer and use it in GitHub Desktop.
Save VitorBlog/947e4dba16d55eb33752338b18d02ea5 to your computer and use it in GitHub Desktop.
Create pull request on git push with Azure DevOps CLI

Create pull request on git push with Azure DevOps CLI

First Steps

  1. Define your organization and project at the $organization variable, example:
organization="google/gemini"
  1. Install and configure the Azure DevOps CLI, Learn.Microsoft.com.
  2. Execute the file in your repository folder.
$ git-push
What's the target branch? [develop, homolog, main] -> develop
enumerating objects: 25, done.
Counting objects: 100% (25/25), done.
Delta compression using up to 12 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (13/13), 956 bytes | 956.00 KiB/s, done.
Total 13 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (13/13) (10 ms)
remote: Validating commits... (1/1) done (0 ms)
remote: Storing packfile... done (63 ms)
remote: Storing index... done (49 ms)
To ssh.dev.azure.com:v3/ORGANIZATION/PROJECT/REPOSITORY
 * [new branch]      bug/98993 -> bug/98993
Branch 'bug/98993' set up to track remote branch 'bug/98993' from 'origin'.
"https://dev.azure.com/ORGANIZATION/PROJECT/_git/REPOSITORY/pullrequest/15572"

How to link Work Items

To auto-link work items you can follow the pattern "*/work-item-id", examples:

feature/43229
bug/98993
help-me/23433
#!/bin/bash
organization="AZURE-ORG/PROJECT"
repo_name=$(basename -s .git "$(git config --get remote.origin.url)")
branch="$(git symbolic-ref --short HEAD)"
branch_suffix="${branch#*/}"
target="develop"
read -p "What's the target branch? [develop, homolog, main] -> " target
git push --set-upstream origin $branch
az repos pr create -s "$branch" -t "$target" -r "$repo_name" --work-items $branch_suffix --query "join(\`/\`, ['https://dev.azure.com/$organization/_git',repository.name,'pullrequest',to_string(codeReviewId)])"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment