Snippets

Adaptavist Stash - Allow Only N Personal Repositories

Created by Jamie Echlin
package com.onresolve.stash.groovy.test.listeners.STASH_3850_block_personal

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.stash.event.RepositoryCreationRequestedEvent
import com.atlassian.stash.project.ProjectType
import com.atlassian.stash.repository.RepositoryService

// only allow N personal
def repositoryService = ComponentLocator.getComponent(RepositoryService)
final Integer MAX_PERSONAL = 5
def event = event as RepositoryCreationRequestedEvent
def project = event.repository.project

if (project.type == ProjectType.PERSONAL) {
    if (repositoryService.countByProject(project) >= MAX_PERSONAL) {
        event.cancel("You can only create $MAX_PERSONAL personal repositories.")
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.