From a3cf0d02fb6015f2c2e36ac9adc210e7f9e50474 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 26 Jul 2017 18:27:28 +0100 Subject: [PATCH] Issues for Visual Studio Team Services Provide issue support for VSTS and TFS, modifying the URL from the `_git` endpoint to the `_workitems` endpoint and appending the `id` query string. --- git-open | 12 +++++++++--- test/git-open.bats | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/git-open b/git-open index cdb5426..e6f8463 100755 --- a/git-open +++ b/git-open @@ -131,9 +131,15 @@ elif [[ ${pathargs[0]} == 'scm' ]]; then IFS='/' urlpath="${pathargs[*]}" providerBranchRef="/browse?at=$branch" elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' ]]; then - # Visual Studio Team Services and Team Foundation Server: keep the - # Team Project and repository name, append branch selector. - providerBranchRef="?version=GB$branch" + # Visual Studio Team Services and Team Foundation Server always have /_git/ as the second to last segment in the url path + if (( is_issue )); then + # Switch to workitems, provide work item id if specified + urlpath="${urlpath%%/_git/*}/_workitems" + providerBranchRef="?id=${branch//[^0-9]/}" + else + # Keep project and repository name, append branch selector. + providerBranchRef="?version=GB$branch" + fi fi openurl="$protocol://$domain/$urlpath" diff --git a/test/git-open.bats b/test/git-open.bats index c1a5575..c3abd6c 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -356,6 +356,13 @@ setup() { assert_output "http://tfs.example.com:8080/Project/Folder/_git/Repository?version=GBmybranch" } +@test "vsts: issue" { + git remote set-url origin "http://tfs.example.com:8080/Project/Folder/_git/Repository" + git checkout -B "bugfix-36" + run ../git-open "--issue" + assert_output "http://tfs.example.com:8080/Project/Folder/_workitems?id=36" +} + teardown() { cd ..