Skip to content

Instantly share code, notes, and snippets.

@l8nite
Last active February 18, 2016 05:12
Show Gist options
  • Save l8nite/654567309434e576cdd3 to your computer and use it in GitHub Desktop.
Save l8nite/654567309434e576cdd3 to your computer and use it in GitHub Desktop.
Make an etsy/hound config file for stash repositories a user/pass have access too
!/bin/bash
if [[ "$STASH_USER" == "" || "$STASH_PASS" == "" ]]; then
echo "FATAL: You need to set STASH_USER and/or STASH_PASS"
exit 1
fi
STASH_HOST=${STASH_HOST:-your.host.here.com}
STASH_URL=https://${STASH_USER}:${STASH_PASS}@${STASH_HOST}
echo '{ "max-concurrent-indexers": 2, "dbpath": "data", "repos": {'
projectCount=0
curl -k -s ${STASH_URL}/rest/api/1.0/projects?limit=500 | jq -r '.values[].link.url' | while read projectPath
do
if [[ $projectCount -ne 0 ]]; then
echo ','
fi
repoCount=0
curl -k -s ${STASH_URL}/rest/api/1.0${projectPath}/repos?limit=500 | jq -r '.values[].links.clone[] | select(.name=="ssh") | .href' | while read cloneUrl
do
repo=$(basename $cloneUrl)
if [[ $repoCount -ne 0 ]]; then
echo ','
fi
echo '"'$projectPath/$repo'": { "url": "'$cloneUrl'", "url-pattern": { "base-url": "{url}/files/{path}{anchor}", "anchor": "#line={line}" } }'
((repoCount=repoCount+1))
done
((projectCount=projectCount+1))
done
echo '} }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment