diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/ElementProp.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/ElementProp.kt new file mode 100644 index 00000000000..613a8dd8718 --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/ElementProp.kt @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.pipeline.pojo.element + +/** + * 插件属性 + */ +data class ElementProp( + val name: String, + val value: Any, + val type: ElementPropType +) + +/** + * 属性类型 + */ +enum class ElementPropType(val value: String) { + VUEX_INPUT("vuex-input"), + STAFF_INPUT("staff-input"), + SELECTOR("selector"); +} diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt index 4b238b6d206..f1a412ec320 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt @@ -29,8 +29,12 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.selector +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.staffInput +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.vuexInput import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -116,68 +120,69 @@ data class CodeGitWebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return when (eventType) { + override fun triggerCondition(): List { + val props = when (eventType) { CodeEventType.PUSH -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput(name = "includeSourceBranchName", value = includeSourceBranchName), + vuexInput(name = "includeSourceBranchName", value = includeSourceBranchName), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST_ACCEPT -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput(name = "includeSourceBranchName", value = includeSourceBranchName), + vuexInput(name = "includeSourceBranchName", value = includeSourceBranchName), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.TAG_PUSH -> { - mapOf( - "tagName" to tagName, - "excludeTagName" to excludeTagName, - "fromBranches" to fromBranches + listOf( + vuexInput(name = "tagName", value = tagName), + vuexInput(name = "excludeTagName", value = excludeTagName), + vuexInput(name = "fromBranches", value = fromBranches), ) } CodeEventType.REVIEW -> { - mapOf( - "includeCrState" to includeCrState, - "includeCrTypes" to includeCrTypes + listOf( + selector(name = "includeCrState", value = includeCrState), + selector(name = "includeCrTypes", value = includeCrTypes) ) } CodeEventType.ISSUES -> { - mapOf( - "includeIssueAction" to includeIssueAction + listOf( + selector(name = "includeIssueAction", value = includeIssueAction) ) } CodeEventType.NOTE -> { - mapOf( - "includeNoteTypes" to includeNoteTypes, - "includeNoteComment" to includeNoteComment + listOf( + selector(name = "includeNoteTypes", value = includeNoteTypes), + vuexInput(name = "includeNoteComment", value = includeNoteComment) ) } else -> - emptyMap() + emptyList() } + return props.filterNotNull() } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt index 2730b7b2e02..0f7419f8d7a 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt @@ -29,7 +29,9 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -71,31 +73,18 @@ data class CodeGithubWebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return when (eventType) { - CodeEventType.PUSH -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "excludeUsers" to excludeUsers + override fun triggerCondition(): List { + val props = when (eventType) { + CodeEventType.PUSH, CodeEventType.CREATE, CodeEventType.PULL_REQUEST -> { + listOf( + TriggerElementPropUtils.vuexInput(name = "branchName", value = branchName), + TriggerElementPropUtils.vuexInput(name = "excludeBranchName", value = excludeBranchName), + TriggerElementPropUtils.vuexInput(name = "excludeUsers", value = excludeUsers) ) } - CodeEventType.CREATE -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "excludeUsers" to excludeUsers - ) - } - CodeEventType.PULL_REQUEST -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "excludeUsers" to excludeUsers - ) - } - else -> - emptyMap() + + else -> emptyList() } + return props.filterNotNull() } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt index 0a06ba1066a..fdeb3cd8066 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt @@ -29,8 +29,11 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.staffInput +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.vuexInput import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -94,50 +97,63 @@ data class CodeGitlabWebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return when (eventType) { + override fun triggerCondition(): List { + val props = when (eventType) { CodeEventType.PUSH -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST_ACCEPT -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.TAG_PUSH -> { - mapOf( - "tagName" to tagName, - "excludeTagName" to excludeTagName + listOf( + vuexInput(name = "tagName", value = tagName), + vuexInput(name = "excludeTagName", value = excludeTagName), ) } else -> - emptyMap() + emptyList() } + return props.filterNotNull() } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt index b9ef2be0380..99cf3d17101 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt @@ -29,7 +29,9 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.vuexInput import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -59,26 +61,27 @@ data class CodeP4WebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return with(data.input) { - when (eventType) { + override fun triggerCondition(): List { + with(data.input) { + val props = when (eventType) { CodeEventType.CHANGE_COMMIT, CodeEventType.CHANGE_SUBMIT, CodeEventType.CHANGE_CONTENT -> { - mapOf( - "includePaths" to includePaths, - "excludePaths" to excludePaths + listOf( + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths) ) } CodeEventType.SHELVE_COMMIT, CodeEventType.SHELVE_SUBMIT, CodeEventType.SHELVE_DELETE -> { - mapOf( - "includePaths" to includePaths, - "excludePaths" to excludePaths + listOf( + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths) ) } else -> - emptyMap() + emptyList() } + return props.filterNotNull() } } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt index 02e4b3a95fa..a1c0d2afc3e 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt @@ -29,7 +29,10 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.staffInput +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.vuexInput import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -73,12 +76,12 @@ data class CodeSVNWebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return mapOf( - "relativePath" to relativePath, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + override fun triggerCondition(): List { + return listOfNotNull( + vuexInput(name = "relativePath", value = relativePath), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt index 376a69643c3..19f72909f05 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt @@ -29,8 +29,12 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.element.ElementProp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.selector +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.staffInput +import com.tencent.devops.common.pipeline.utils.TriggerElementPropUtils.vuexInput import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -60,69 +64,82 @@ data class CodeTGitWebHookTriggerElement( } // 增加条件这里也要补充上,不然代码库触发器列表展示会不对 - override fun triggerCondition(): Map { - return with(data.input) { - when (eventType) { + override fun triggerCondition(): List { + with(data.input) { + val props = when (eventType) { CodeEventType.PUSH -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.MERGE_REQUEST_ACCEPT -> { - mapOf( - "branchName" to branchName, - "excludeBranchName" to excludeBranchName, - "includeSourceBranchName" to includeSourceBranchName, - "excludeSourceBranchName" to excludeSourceBranchName, - "includePaths" to includePaths, - "excludePaths" to excludePaths, - "includeUsers" to includeUsers, - "excludeUsers" to excludeUsers + listOf( + vuexInput(name = "branchName", value = branchName), + vuexInput(name = "excludeBranchName", value = excludeBranchName), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput( + name = "includeSourceBranchName", + value = includeSourceBranchName + ), + vuexInput(name = "includePaths", value = includePaths), + vuexInput(name = "excludePaths", value = excludePaths), + staffInput(name = "includeUsers", value = includeUsers), + staffInput(name = "excludeUsers", value = excludeUsers) ) } CodeEventType.TAG_PUSH -> { - mapOf( - "tagName" to tagName, - "excludeTagName" to excludeTagName, - "fromBranches" to fromBranches + listOf( + vuexInput(name = "tagName", value = tagName), + vuexInput(name = "excludeTagName", value = excludeTagName), + vuexInput(name = "fromBranches", value = fromBranches), ) } CodeEventType.REVIEW -> { - mapOf( - "includeCrState" to includeCrState + listOf( + selector(name = "includeCrState", value = includeCrState), ) } CodeEventType.ISSUES -> { - mapOf( - "includeIssueAction" to includeIssueAction + listOf( + selector(name = "includeIssueAction", value = includeIssueAction) ) } CodeEventType.NOTE -> { - mapOf( - "includeNoteTypes" to includeNoteTypes, - "includeNoteComment" to includeNoteComment + listOf( + selector(name = "includeNoteTypes", value = includeNoteTypes), + vuexInput(name = "includeNoteComment", value = includeNoteComment) ) } else -> - emptyMap() + listOf() } + return props.filterNotNull() } } } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/WebHookTriggerElement.kt index 78b15ff3103..8b69ccf5cb8 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/WebHookTriggerElement.kt @@ -28,6 +28,7 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.ElementProp abstract class WebHookTriggerElement( override val name: String = "webhook base class", @@ -35,5 +36,5 @@ abstract class WebHookTriggerElement( override var status: String? = null ) : Element(name, id, status) { - open fun triggerCondition(): Map = emptyMap() + open fun triggerCondition(): List = emptyList() } diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/TriggerElementPropUtils.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/TriggerElementPropUtils.kt new file mode 100644 index 00000000000..f04742a3f09 --- /dev/null +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/TriggerElementPropUtils.kt @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.pipeline.utils + +import com.tencent.devops.common.pipeline.pojo.element.ElementProp +import com.tencent.devops.common.pipeline.pojo.element.ElementPropType + +object TriggerElementPropUtils { + + fun vuexInput(name: String, value: String?): ElementProp? { + if (value.isNullOrBlank()) return null + return ElementProp(name = name, value = value.split(","), type = ElementPropType.VUEX_INPUT) + } + + fun staffInput(name: String, value: List?): ElementProp? { + if (value.isNullOrEmpty()) return null + return ElementProp(name = name, value = value, type = ElementPropType.STAFF_INPUT) + } + + fun selector(name: String, value: List?): ElementProp? { + if (value.isNullOrEmpty()) return null + return ElementProp(name = name, value = value, type = ElementPropType.SELECTOR) + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/RepoPipelineRefService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/RepoPipelineRefService.kt index 75b748e4634..45a824d6541 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/RepoPipelineRefService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/RepoPipelineRefService.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.api.enums.RepositoryConfig import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.util.EnvUtils +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.container.Stage @@ -306,7 +307,7 @@ class RepoPipelineRefService @Autowired constructor( atomCategory = RepoAtomCategoryEnum.TRIGGER.name, triggerType = triggerType, eventType = eventType, - triggerCondition = (element as WebHookTriggerElement).triggerCondition() + triggerCondition = JsonUtil.toJson((element as WebHookTriggerElement).triggerCondition()) ) ) } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRef.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRef.kt index 0115a94b7c7..b238067d08c 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRef.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRef.kt @@ -56,7 +56,7 @@ data class RepoPipelineRef( @ApiModelProperty("事件类型") val eventType: String?, @ApiModelProperty("触发条件") - val triggerCondition: Map?, + val triggerCondition: String?, @ApiModelProperty("触发条件md5") val triggerConditionMd5: String? ) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRefInfo.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRefInfo.kt index f457fbc9a35..647f23e77b6 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRefInfo.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepoPipelineRefInfo.kt @@ -59,5 +59,5 @@ data class RepoPipelineRefInfo( @ApiModelProperty("事件类型,只有触发插件才有值") val eventType: String? = null, @ApiModelProperty("触发条件") - val triggerCondition: Map? = null + val triggerCondition: String? = null ) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepoPipelineService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepoPipelineService.kt index d9e62d23c84..c247b98f2fb 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepoPipelineService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepoPipelineService.kt @@ -33,6 +33,9 @@ import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.util.HashUtil import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.pojo.element.ElementProp +import com.tencent.devops.common.pipeline.pojo.element.ElementPropType +import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.repository.dao.RepoPipelineRefDao import com.tencent.devops.repository.pojo.RepoPipelineRef import com.tencent.devops.repository.pojo.RepoPipelineRefInfo @@ -226,9 +229,7 @@ class RepoPipelineService @Autowired constructor( eventType = it.eventType, taskParams = JsonUtil.to(it.taskParams, object : TypeReference>() {}), triggerCondition = it.triggerCondition?.let { condition -> - JsonUtil.to( - condition, - object : TypeReference>() {}) + translateCondition(condition) }, triggerConditionMd5 = it.triggerConditionMd5, pipelineRefCount = pipelineRefCountMap[it.id] ?: 0, @@ -240,6 +241,20 @@ class RepoPipelineService @Autowired constructor( return SQLPage(count = count, records = triggerRecords) } + private fun translateCondition(triggerCondition: String): Map { + val elementProps = JsonUtil.to(triggerCondition, object : TypeReference>() {}) + return elementProps.associateBy( + { I18nUtil.getCodeLanMessage(it.name) }, + { + if (it.type == ElementPropType.SELECTOR) { + (it.value as List<*>).map { value -> I18nUtil.getCodeLanMessage(value.toString()) } + } else { + it.value + } + } + ) + } + private fun getAtomProp(atomCodes: Set) = try { client.get(ServiceAtomResource::class).getAtomProps(atomCodes).data } catch (ignored: Exception) {