-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1311 Auto-enabling of branch on new build
- Loading branch information
1 parent
e94518a
commit 13bb89e
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...-service/src/main/java/net/nemerosa/ontrack/service/BranchAutoEnableBuildEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
ontrack-service/src/test/java/net/nemerosa/ontrack/service/BuildServiceIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
|
||
} |