net.nemerosa.ontrack.kdsl.spec.Project.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-kdsl Show documentation
Show all versions of ontrack-kdsl Show documentation
Ontrack module: ontrack-kdsl
package net.nemerosa.ontrack.kdsl.spec
import net.nemerosa.ontrack.kdsl.connector.Connector
import net.nemerosa.ontrack.kdsl.connector.graphql.GraphQLMissingDataException
import net.nemerosa.ontrack.kdsl.connector.graphql.checkData
import net.nemerosa.ontrack.kdsl.connector.graphql.convert
import net.nemerosa.ontrack.kdsl.connector.graphql.schema.CreateBranchMutation
import net.nemerosa.ontrack.kdsl.connector.graphql.schema.DeleteProjectByIdMutation
import net.nemerosa.ontrack.kdsl.connector.graphql.schema.type.ProjectEntityType
import net.nemerosa.ontrack.kdsl.connector.graphqlConnector
/**
* Representation of a project.
*
* @property id Project ID
* @property name Project name
* @property description Project description
*/
class Project(
connector: Connector,
id: UInt,
val name: String,
val description: String?,
) : ProjectEntity(connector, ProjectEntityType.PROJECT, id) {
/**
* Deletes this project
*/
fun delete() {
graphqlConnector.mutate(
DeleteProjectByIdMutation(id.toInt())
) {
it?.deleteProject()?.fragments()?.payloadUserErrors()?.convert()
}
}
/**
* Create a branch inside this project.
*
* @param name Name of the branch to create
* @param description Description of the branch
* @return Created branch
*/
fun createBranch(
name: String,
description: String,
): Branch =
graphqlConnector.mutate(
CreateBranchMutation(
id.toInt(),
name,
description
)
) {
it?.createBranch()?.fragments()?.payloadUserErrors()?.convert()
}
?.checkData { it.createBranch()?.branch() }
?.fragments()?.branchFragment()?.toBranch(this)
?: throw GraphQLMissingDataException("Did not get back the created branch")
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy