Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to get repository list for a stash project?

Jennifer Schuch September 24, 2013

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

0 votes
Answer accepted
Andrew Milne September 25, 2013

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).

0 votes
Jonathan Demeyer February 23, 2015

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

https://github.com/RisingOak/stashy

 

0 votes
Bill Wang February 10, 2015

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
bruce szalwinski April 27, 2016

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
Prashanth Amarachinta April 26, 2019

i am unable to list more than 25 projects , i have more than 25 . how to list them ?

Adam Burden May 16, 2019

should be 

.../projects?size=100&limit=100
0 votes
CelsoA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2013

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

Jennifer Schuch September 25, 2013

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

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2013

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events