Setting repository connections using REST API

A. Truelsen June 15, 2015

I'm try to add read permissions to forked repositories so that team members can access each others commits.

I have a powershell script that looks roughly like this:

 

param(
[Parameter(Mandatory=${true})][string]$gitUser = "jdoe",
[Parameter(Mandatory=${false})][string]$gitPrj = "DEMO"
)

$headers = @{}
$headers.Add('Accept','application/json')
$headers.Add('Authorization','Basic 123abc456def')

$repos = @("repo1","repo2","repo3","repo4","repo5")

foreach ($repo in $repos) {
   $uri = "http://$gitHost/rest/api/1.0/projects/~$gitUser/repos/$repo/permissions/groups?permission=REPO_READ&name=R_STAS_$gitPrj_dev"
   $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method "POST"

}

This works nicely for the first two repos, but the third (and subsequent) API call fail with a timeout:

System.Net.WebException: The operation has timed out.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

The order of the repositories doesn't matter so breaking the script up in chunks that does 2 repos and then calling all the two-repo scripts does in fact work.

 

Stash support is unable to help sad

Has anybody tried something similar?

 

TIA

/anders

 

2 answers

2 votes
Mark McCormack (Adaptavist)
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.
June 22, 2015

Anders,

Adaptavist just released a new Add-on to the Marketplace called ScriptRunner for Stash. I'm replying here since I can't answer your question directly but this Add-on may be an easier workaround for updating Stash repository permissions in bulk.

There is a section in the documentation that outlines how to get started with a permission script provided:

https://scriptrunner.adaptavist.com/stash/latest/docs/script_console/#bulk-project-permissions-update

Also, there is functionality that can set default permissions for each new repository that gets created in the future and is covered in the documentation here:

https://scriptrunner.adaptavist.com/stash/latest/docs/event_handlers/#default-project-repository-permissions

Finally, there is a video available that goes through this on our Youtube channel:

https://www.youtube.com/watch?v=iRnD00EPmQE

I hope that helps, if so - could you please mark this as an answer?

 

regards,

Mark McCormack

Adaptavist ScriptRunner for Stash - Product Owner.

0 votes
Tomasz Urbański August 1, 2018

Hi Anders,

I observe exactly the same issue with my REST API calls.

Namely, the first two PUT invocations work nicely, but the third (and subsequent) API call fails with a timeout:

System.Net.WebException: The operation has timed out.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

My implementation is also composed in PowerShell.

The only difference is that I call Jira REST API, not Stash.

Q: Have you made any progress in the root cause analysis? Have you found any solution?

BR. Tomasz

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events