It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
I'm attempting to write a script to audit existing repositories for specific requirements and violations. Easy enough to doe with a bash script, except that the repositories have directory names that represent the stash repository ID, which is mapped to a project/repository by Stash, but not obvious to my script.
Given a repository ID (id = 1124) how do I obtain the associated clone url?
I tried http:server/rest/api/latest/repos?id=1124 but the id parameter is ignored and I get the first page of all repos.
I could cycle through all repos to find it, but that is pretty expensive. Is there a specific rest api to retrieve the clone url?
Michael,
Rather than write your script from scratch, you might want to try our latest Add-on in the Atlassian Marketplace called ScriptRunner for Stash.
It has a built-in repository size report that lists all of your repositories or you could write your own script with some help from the examples in the documentation. The nearest example would be the one that lists all the repository sizes. As well as the project name and size, you could return the clone URL fairly quickly.
Hi,
The repository ID's are not public, so there is no way to do a lookup by repository ID through the REST interface. You can retrieve the clone URL if you have the repository slug by parsing the output of
for
"links": {
"clone": [
{
"href": "https://<baseURL>/scm/PRJ/my-repo.git",
"name": "http"
},
but that's probably not what you wanted to hear.
Cheers,
Michael
I was hoping to drive the script with unix find:
cd repositories
find . -maxdepth 1 -type d -exec audit_repo {} \;
But I suppose I could add some additional logic to the audit_repo to use rest api to retrieve the projects and repos:
for project in (get all stash projects
do
for repo in (get all project repos)
do
something
done
done
You can receive all repositories at once with /rest/api/1.0/repos, so you don't need to iterate over all projects first. Note that you will get the repository ID in the JSON output: "values": [ { "slug": "my-repo", "id": 1, but that will probably not help you much...
The hard limit you mention is indeed 1000, but configurable (Stash config property page.max.repositories=1000, see here https://confluence.atlassian.com/display/STASH/Stash+config+properties). But you can always page over the results to get all repositories. Just use "?start=XXX" in your REST requests.
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreBitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda ...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.