0

Atlassian Stash uses repo URLs for cloning/pushing/pulling in the form of

https://mystashserver/scm/myproject/myrepo.git

How can I transform this URL into the one used by Stash's web UI in the form of

https://mystashserver/projects/myproject/repos/myrepo

Opening the first URL in the browser automatically forwards to the latter, but you can't add additional parameters, e.g. for selecting a specific branch.

I'm looking for a way to transform URLs of the first kind to the latter, ideally for use in a Bash script.

nwinkler
  • 52,665
  • 21
  • 154
  • 168

1 Answers1

1

The following works in a Bash script, using Bash's built-in regular expression support:

giturl=https://mystashserver/scm/myproject/myrepo.git

re='(.*)/scm/(.*)/(.*)\.git'
if [[ $giturl =~ $re ]]; then
  newgiturl=${BASH_REMATCH[1]}/projects/${BASH_REMATCH[2]}/repos/${BASH_REMATCH[3]}
  echo $newgiturl
fi

The regular expression splits up the original URL into several parts:

  • (Capture Group 1): Protocol, hostname, optional web root context
  • "scm": This seems to be a fixed value for Atlassian Stash
  • (Capture Group 2): The project name
  • (Capture Group 3): The actual repository name, minus the .git suffix

In the above example, the newgiturl variable then reassembles the URL, injecting the projects and repos part in the desired locations.

nwinkler
  • 52,665
  • 21
  • 154
  • 168