Skip to content

Commit

Permalink
#1311 Auto-enabling of branch on new build
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 1, 2024
1 parent e94518a commit 13bb89e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.nemerosa.ontrack.service

import net.nemerosa.ontrack.model.events.Event
import net.nemerosa.ontrack.model.events.EventFactory
import net.nemerosa.ontrack.model.events.EventListener
import net.nemerosa.ontrack.model.security.SecurityService
import net.nemerosa.ontrack.model.structure.Branch
import net.nemerosa.ontrack.model.structure.ProjectEntityType
import net.nemerosa.ontrack.model.structure.StructureService
import org.springframework.stereotype.Component

@Component
class BranchAutoEnableBuildEventListener(
private val structureService: StructureService,
private val securityService: SecurityService,
) : EventListener {

override fun onEvent(event: Event) {
if (event.eventType == EventFactory.NEW_BUILD) {
val branch = event.getEntity<Branch>(ProjectEntityType.BRANCH)
if (branch.isDisabled) {
securityService.asAdmin {
structureService.enableBranch(branch)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.nemerosa.ontrack.service

import net.nemerosa.ontrack.it.AbstractDSLTestSupport
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class BuildServiceIT : AbstractDSLTestSupport() {

@Test
fun `Auto re-enabling a branch when a build is created`() {
project {
branch {
// Disabling the branch
val branch = structureService.disableBranch(this)
// Checking the branch is disabled
assertEquals(true, structureService.getBranch(id).isDisabled, "Branch is disabled")
// Creating a build
branch.build()
// Checking the branch is enabled
assertEquals(false, structureService.getBranch(id).isDisabled, "Branch is enabled")
}
}
}

}

0 comments on commit 13bb89e

Please sign in to comment.