@@ -24,6 +24,7 @@ import kotlinx.serialization.json.jsonArray
2424import kotlinx.serialization.json.jsonObject
2525import kotlinx.serialization.json.jsonPrimitive
2626import org.modelix.authorization.ModelixJWTUtil
27+ import org.modelix.model.lazy.BranchReference
2728import org.modelix.model.lazy.RepositoryId
2829import org.modelix.model.server.ModelServerPermissionSchema
2930import org.modelix.workspaces.InternalWorkspaceConfig
@@ -42,13 +43,17 @@ class KestraClient(val jwtUtil: ModelixJWTUtil) {
4243 }
4344
4445 suspend fun getRunningImportJobIds (workspaceId : String ): List <String > {
46+ return getRunningImportJobIds(mapOf (" workspace" to workspaceId))
47+ }
48+
49+ suspend fun getRunningImportJobIds (labels : Map <String , String >): List <String > {
4550 val responseObject: JsonObject = httpClient.get {
4651 url {
4752 takeFrom(kestraApiEndpoint)
4853 appendPathSegments(" executions" , " search" )
4954 parameters.append(" namespace" , " modelix" )
5055 parameters.append(" flowId" , " git_import" )
51- parameters.append (" labels" , " workspace: $workspaceId " )
56+ parameters.appendAll (" labels" , labels.map { " ${it.key} : ${it.value} " } )
5257 parameters.append(" state" , " CREATED" )
5358 parameters.append(" state" , " QUEUED" )
5459 parameters.append(" state" , " RUNNING" )
@@ -64,36 +69,53 @@ class KestraClient(val jwtUtil: ModelixJWTUtil) {
6469
6570 suspend fun enqueueGitImport (workspace : InternalWorkspaceConfig ): JsonObject {
6671 val gitRepo = workspace.gitRepositories.first()
72+ return enqueueGitImport(
73+ gitRepoUrl = gitRepo.url,
74+ gitUser = gitRepo.credentials?.user,
75+ gitPassword = gitRepo.credentials?.password,
76+ gitRevision = " origin/${gitRepo.branch} " ,
77+ modelixBranch = RepositoryId (" workspace_${workspace.id} " ).getBranchReference(" git-import" ),
78+ labels = mapOf (" workspace" to workspace.id),
79+ )
80+ }
6781
82+ suspend fun enqueueGitImport (
83+ gitRepoUrl : String ,
84+ gitUser : String? ,
85+ gitPassword : String? ,
86+ gitRevision : String ,
87+ modelixBranch : BranchReference ,
88+ labels : Map <String , String >,
89+ ): JsonObject {
6890 updateGitImportFlow()
6991
70- val targetBranch = RepositoryId (" workspace_${workspace.id} " ).getBranchReference(" git-import" )
7192 val token = jwtUtil.createAccessToken(
7293 " git-import@modelix.org" ,
7394 listOf (
74- ModelServerPermissionSchema .repository(targetBranch .repositoryId).create.fullId,
75- ModelServerPermissionSchema .branch(targetBranch ).rewrite.fullId,
95+ ModelServerPermissionSchema .repository(modelixBranch .repositoryId).create.fullId,
96+ ModelServerPermissionSchema .branch(modelixBranch ).rewrite.fullId,
7697 ),
7798 )
7899
79100 val response = httpClient.post {
80101 url {
81102 takeFrom(kestraApiEndpoint)
82103 appendPathSegments(" executions" , " modelix" , " git_import" )
83- parameters[" labels" ] = " workspace:${workspace.id} "
104+ if (labels.isNotEmpty()) {
105+ parameters.appendAll(" labels" , labels.map { " ${it.key} :${it.value} " })
106+ }
84107 }
85108 setBody(
86109 MultiPartFormDataContent (
87110 formData {
88- append(" git_url" , gitRepo.url)
89- append(" git_revision" , " origin/${gitRepo.branch} " )
90- append(" modelix_repo_name" , " workspace_${workspace.id} " )
91- append(" modelix_target_branch" , " git-import" )
111+ append(" git_url" , gitRepoUrl)
112+ append(" git_revision" , gitRevision)
113+ append(" git_limit" , " 50" )
114+ append(" modelix_repo_name" , modelixBranch.repositoryId.id)
115+ append(" modelix_target_branch" , modelixBranch.branchName)
92116 append(" token" , token)
93- gitRepo.credentials?.also { credentials ->
94- append(" git_user" , credentials.user)
95- append(" git_pw" , credentials.password)
96- }
117+ gitUser?.let { append(" git_user" , it) }
118+ gitPassword?.let { append(" git_pw" , it) }
97119 },
98120 ),
99121 )
0 commit comments