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?
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unless I'm overlooking something, repos returns 25 entries by default, and appears to have a hard limit of 1000 entries per request. But I can work with that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.