how to get repository list for a stash project?

Stash project has 65+ repositories (modules) and growing. To not adjust the build process everytime a new repository is added, is there a way to query the stash project to get a listing of repositories to then input to a script to clone each at build time?

4 answers

1 accepted

I'd suggest writting a script to do the query and then filter the results down and print the output list in the format you require for your build system.

For example: You could write a get_repo_list script that takes a project name (or ~<user>) and prints all the repository slugs or the clone urls or some other simple list.

There some example code on writing oath capable REST clients for Atlassian products at:

https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples

The PERL example was written with Stash in mind (Disclaimer: I wrote it) and should be easy to use it to make such a query, parse the JSON structure into perl and then iterate over it pulling out the field you want (just make sure to handle the whole paged API thing or you only get some of the results).

Hi there Jennifer,

You can use the REST API to achieve that.

Are all repositories created by the same user?

There are some examples with the REST API that can he useful for you.

Please check them here:

https://answers.atlassian.com/questions/193504/stash-pr-rest-api-for-user-repositories

The rest api for Stash core can be found here: https://developer.atlassian.com/static/rest/stash/2.7.2/stash-rest.html.

Regards,

Celso Yoshioka

Hi Celso,

I've been playing around with the REST API using the browser plugin...is there a way to limit these results to only being the "slug"?? I'm trying to use curl to get this information in a way to pass to my git clone statements.

The repos will not be created by the same user.

I also found this https://developer.atlassian.com/static/javadoc/stash/2.0.1/api/reference/com/atlassian/stash/repository/RepositoryService.html

but I'm not familiar on how I would construct this, public Page<? extends Repository> findByProjectKey (String projectKey, PageRequest pageRequest). Any advice?

BR,

Jennifer

Hi Jennifer,

Currently our REST resources don't have any notion of 'filtering' or viewing specific fields. It's all or nothing. You will have to grep or parse the results into JSON somehow.

Regarding your second question - how do you mean construct? If you're writing a Java plugin, if you have a component mentioned in atlassian-plugin.xml that can add RepositoryService to your constructor and it will be 'injected' for free. We have a few example plugins here:

http://atlassian.bitbucket.org/#stash

Cheers,

Charles

Here is the way to list all public repositories in STASH project with Linux/Mac boxes,  make sure you have jq installed. 

STASH=&lt;your-stash-server:port&gt;
curl -k -s https://${STASH}/rest/api/1.0/projects/|jq -r ".values[].link.url"|while read line
do
   #echo "curl -k -s https://${STASH}/rest/api/1.0${line}/repos"
   curl -k -s https://${STASH}/rest/api/1.0${line}/repos|jq -r ".values[].cloneUrl"
done

It looks like the /projects request returns the first 25 projects.  If you have more than than, you'll need to paginate through the results or change the size and limit parameters.

.../projects?size=100&amp;limit=100

Stashy (Python API client for the Atlassian Stash REST API) works very well !

https://github.com/RisingOak/stashy

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

23,557 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you