Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pac_github' into pac_github
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Apr 25, 2024
2 parents 3614624 + f5b924f commit 1a84512
Showing 1 changed file with 2 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
package com.tencent.devops.process.yaml.creator

import com.tencent.devops.common.client.Client
import com.tencent.devops.common.pipeline.NameAndValue
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.process.yaml.v2.utils.ScriptYmlUtils
import com.tencent.devops.store.api.atom.ServiceMarketAtomResource
Expand All @@ -38,15 +37,15 @@ import org.slf4j.LoggerFactory
object ModelCommon {

private val logger = LoggerFactory.getLogger(ModelCommon::class.java)
private val regexMatch = Regex("""([^ ]+)\s*==\s*'(.*)'""")
private val regexNotMatch = Regex("""([^ ]+)\s*!=\s*'(.*)'""")

fun getBranchName(ref: String): String {
return when {
ref.startsWith("refs/heads/") ->
ref.removePrefix("refs/heads/")

ref.startsWith("refs/tags/") ->
ref.removePrefix("refs/tags/")

else -> ref
}
}
Expand Down Expand Up @@ -101,32 +100,4 @@ object ModelCommon {

return parseReceivers
}

fun revertCustomVariableMatch(input: String): List<NameAndValue>? {
if (input.indexOf("==") == -1) return null
val res = mutableListOf<NameAndValue>()
kotlin.runCatching {
input.split("&&").forEach {
regexMatch.matchEntire(it.trim())?.run {
val (key, value) = this.destructured
res.add(NameAndValue(key, value))
}
}
}.onFailure { return null }
return res
}

fun revertCustomVariableNotMatch(input: String): List<NameAndValue>? {
if (input.indexOf("!=") == -1) return null
val res = mutableListOf<NameAndValue>()
kotlin.runCatching {
input.split("||").forEach {
regexNotMatch.matchEntire(it.trim())?.run {
val (key, value) = this.destructured
res.add(NameAndValue(key, value))
}
}
}.onFailure { return null }
return res
}
}

0 comments on commit 1a84512

Please sign in to comment.