Azure DevOps, probably one of the worst tools you can get for a your software team, I hated it with passion. The reason that company chooses it over any other software is probably because they can get a decent enough discount when bundled with the M$'s shitty Outlook, Teams, and office suite. If I could, I would give Azure DevOps's web interface and overall experience a 0 out of 10: it is slow, difficult to navigate, and way behind what you would get from GitHub or GitLab. Enough for the ranting, in short, I hate Azure DevOps' web interface, therefore, I prefer to use the CLI to interact with it.
Azure CLI: Generic at a cost
Azure DevOps, however bad it is, still provides a command line interface to interact with its API.
As an example, if you want to create a PR through azure DevOps, you can run: az pr create -s 'source branch' -t 'target branch' --title 'title' --workItem 'ID' --description "description"
I understand that this CLI is intended to be a general audience, so it is meant to be generic, but my issues with this command are:
It is just too difficult to remember all the options without looking at the docs.
Have to type the target, source branch and/or work item manually.
What I want to achieve:
Interactivity: can choose if open in browser and/or draft mode or not
Simple and intuitive: lists all the available branches, and allow selecting one as target and/or source.
Work item linking and transition: Automatically transition the linked work item so it transition from Todo to In progress
Road to the ideal script
To achieve the Interactivity I wanted, I had opted to use a tool called fzf which is a fuzzy finder.
The script below is what I ended up with. It is quite bloated, but does what I look for.
Note before using this script, you need to have:
FZF installed.
Azure CLI authenticated from your command line, meaning you can already create pr in the "dumb" way I mentioned above.
if [ "$workItemReq" == "Y" ] || [ "$workItemReq" == "y" ]; then workItem=$(az boards query --id$BOARD_ID --output jsonc|jq -r '.[]|(.id|tostring) + " " + (.fields["System.Title"])'|fzf --prompt "Choose a workItem"|awk '{print $1}') if [[ -n $workItem ]]; then ## transition selected workitem to in progress az boards work-item update --id$workItem --state "In Progress" WORKITEMARG="--work-items $workItem" fi fi
read -rp " Title for your PR: " title echo"PR title: ""$title" echo"${LINE}"
read -rp " Description for your PR: " description echo"PR description: ""$description" echo"${LINE}" if [[ "$description" ]] ; then DESCRIPTION="-d $description" fi
read -rp " Open in browser (Y/N, N): " openBrowser if [ "$openBrowser" == "Y" ] || [ "$openBrowser" == "y" ]; then OPEN_BROWSER_ARG="--open" fi
read -rp " Is Draft? (Y/N, N): " isDraft if [ "$isDraft" == "Y" ] || [ "$isDraft" == "y" ]; then IS_DRAFT_ARG="--draft" fi