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

Archive rather than delete projects

Robert Obuch May 19, 2016

Does anybody have any experience of overriding the Delete repository function to instead move the repository to an archived repositories project. Ideally, I'm looking to also tag the repository name with a time stamp and the name of the original parent project.

Any help or first steps would be much appreciated.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
JamieA
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.
May 20, 2016

This is not a straightforward task. I've listed out the steps more or less as Adam described, but I have not tested it to destruction as of yet, and it's lacking the bells and whistles that you would expect.

First...

Create ARCHIVE project

Create a project with key ARCHIVE. If you choose something else you need to change both files.

Create REST Endpoint

Admin -> Rest Endpoints... the code is here: https://gist.github.com/jechlin/58532e84618b3c7cbf3e474fd46591ad

This gives you a rest endpoint you can post the repo ID, and it will move it to the ARCHIVE project. It changes the name by adding on the repo ID, which is globally unique. If you want the date, you can alter that. But, afaik, only certain chars are allowed in the slug (name).

Add Web Resource

The next task is add javascript that will replace the Delete Repo button with one that posts to the endpoint above.

Admin -> Script Fragments, Install Web Resource:

image2016-5-20 13:25:53.png

The content of the JS is at: https://gist.github.com/jechlin/16da177ed43aff75d28588a0e6d3df68

The JS needs to be under a plugin.resource.directory (see docs (they are for JIRA but it's the same deal))

Hard refresh and the buttons should look like the following (except on the Archive project):

image2016-5-20 13:30:6.png

 

Clicking the button should now move the repo to that project.

Like I say, there are probably corner cases outstanding.

I guess users could still delete repos via the rest api, so you would want to block that probably via an event handler, as there is no permission specific to deleting repos.

I was actually looking at fragments but was unsure how to hide existing entries and your documentation doesn't appear to detail this?

We haven't yet had time to update the SR4BBS docs with the new web frag stuff, but the JIRA and confluence docn examples are a good source until then.

1 vote
adammarkham
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.
May 19, 2016

When I first investigated this I thought you would be able to do this with an event listener to intercept the repository deleted event. However this doesn't work as expected when we move the repository, the archived one is always deleted along with the original.

For a proper solution you could hide the current delete repository button in the UI using script fragments and add a new delete repository button which does the archiving: https://scriptrunner.adaptavist.com/latest/bitbucket/CustomisingUI.html

From this button do a REST PUT call to the endpoint here in JavaScript to just move the repository and update the name, then it will be gone from the original project: https://developer.atlassian.com/static/rest/bitbucket-server/4.6.1/bitbucket-rest.html#idp457424

Sorry there is not a simple script to do this with. Hopefully that gives you a starting point at least.

Robert Obuch May 19, 2016

I was actually looking at fragments but was unsure how to hide existing entries and your documentation doesn't appear to detail this?

JamieA
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.
May 19, 2016

we'll come back to you with a solution tomorrow, inshallah.

TAGS
AUG Leaders

Atlassian Community Events