Commit, push and create a pull request in VSTS with just seven characters!

I'm a huge fan of automation and reducing the need for repetitive tasks, even if we're just talking about a couple of mouse clicks. When you're working with Visual Studio and Visual Studio Team Services you may or may not be doing a fair share of clicks each day. Commit, push, create pull request, confirm... rinse and repeat.

Coming from a Microsoft world I'm not that much of a command line user, even though I have some Linux experience. If there's a GUI I'll probably pick that over the command line any day. However, having had tendonitis in both arms before I wouldn't mind sparing myself a few clicks here and there.

I had this idea while working through a couple of bugs on a project today, why not investigate and implement a reduction of tedious operations? I first thought of git hooks, but apparently there is no such as a post push hook in existence! Who would have thought!? Enter git alias, my saviour. After an hour or two of messing around this is what I came up with:

git config alias.branch-name '!git rev-parse --abbrev-ref HEAD'
git config alias.pull-request '!curl -u your@email.tld:yourAccessToken https://{collection}/DefaultCollection/{project}/_apis/git/repositories/{repository}/pullRequests?api-version=3.0 -d "{\"sourceRefName\": \"refs/heads/$(git branch-name)\",\"targetRefName\": \"refs/heads/develop\",\"title\": \"Merge $(git branch-name) to develop\",\"description\": \"Merging $(git branch-name) into develop\",\"reviewers\": [{\"id\": \"{teamGuid}\"}]}" -H "Content-Type: application/json"'
git config '!git push -u origin $(git branch-name) && git pull-request'

Now you can just create your new branch, write your code and simply write "git pub" in the command line. Enjoy!

#visualstudio #vsts #visualstudioteamservices #git #bash #programming #curl

Ingen kommentarer

Skriv en ny kommentar