diff --git a/README.md b/README.md index 664708c..faff7dc 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ git-open can automatically guess the corresponding repository page for remotes - Atlassian Bitbucket Server (formerly _Atlassian Stash_) - Visual Studio Team Services - Team Foundation Server (on-premises) +- AWS Code Commit ## Configuration diff --git a/git-open b/git-open index fc68240..2e10b2a 100755 --- a/git-open +++ b/git-open @@ -196,6 +196,28 @@ elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' # Keep project and repository name, append branch selector. providerBranchRef="?version=GB$branch" fi +elif [[ "$domain" =~ amazonaws\.com$ ]]; then + # AWS Code Commit + if (( is_issue )); then + echo "Issue feature does not supported on AWS Code Commit." 1>&2 + exit 1 + fi + + # Take region name from domain. + region=${domain#*.} + region=${region%%.*} + + # Replace domain. + # Ex. git-codecommit.us-east-1.amazonaws.com -> us-east-1.console.aws.amazon.com + domain="${region}.console.aws.amazon.com" + + # Replace URL path. + # Ex. v1/repos/example -> codecommit/home?region=us-east-1#/repository/example/browse/ + urlpath="codecommit/home?region=${region}#/repository/${urlpath##*/}/browse/" + + # Replace branch ref. + # Ex. /tree/foobar -> foobar/--/ + providerBranchRef="${providerBranchRef##*/}/--/" fi openurl="$protocol://$domain/$urlpath" diff --git a/test/git-open.bats b/test/git-open.bats index 50808ac..c070606 100755 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -503,6 +503,39 @@ setup() { assert_output "https://gitopen.visualstudio.com/Project/_workitems?id=36" } +## +## AWS Code Commit +## + +@test "aws: https url" { + git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo" + git checkout -B "master" + run ../git-open + assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/" +} + +@test "aws: ssh url" { + git remote set-url origin "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo" + git checkout -B "master" + run ../git-open + assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/" +} + +@test "aws: branch " { + git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo" + git checkout -B "mybranch" + run ../git-open + assert_output "https://us-east-1.console.aws.amazon.com/codecommit/home?region=us-east-1#/repository/repo/browse/mybranch/--/" +} + +@test "aws: issue" { + git remote set-url origin "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo" + git checkout -B "issues/#12" + run ../git-open "--issue" + [ "$status" -eq 1 ] + assert_output "Issue feature does not supported on AWS Code Commit." +} + teardown() { cd ..