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?
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).
Stashy (Python API client for the Atlassian Stash REST API) works very well !
https://github.com/RisingOak/stashy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the way to list all public repositories in STASH project with Linux/Mac boxes, make sure you have jq installed.
STASH=<your-stash-server:port> 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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&limit=100
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i am unable to list more than 25 projects , i have more than 25 . how to list them ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
should be
.../projects?size=100&limit=100
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.