Skip to content

Commit

Permalink
feat: 企业微信通知功能支持去掉域 TencentBlueKing#5318
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzcao committed Oct 20, 2021
1 parent 6735945 commit ebd93c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tencent.devops.process.permission.notify
import com.tencent.devops.process.notify.command.BuildNotifyContext
import com.tencent.devops.process.notify.command.impl.NotifyReceiversCmd
import org.springframework.beans.factory.annotation.Configurable
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean

@Configurable
Expand All @@ -12,12 +13,30 @@ class BluekingNotifyReceiversCmdImpl : NotifyReceiversCmd() {
return true
}

@Value("\${user.domain:#{null}")
private val userUseDomain: Boolean? = true

override fun execute(commandContext: BuildNotifyContext) {
val setting = commandContext.pipelineSetting
if (commandContext.buildStatus.isFailure() || commandContext.buildStatus.isCancel()) {
commandContext.receivers = setting.successSubscription.users.split(",").toMutableSet()
commandContext.receivers = findWeworkUser(setting.successSubscription.users.split(",").toMutableSet())
} else if (commandContext.buildStatus.isSuccess()) {
commandContext.receivers = setting.failSubscription.users.split(",").toMutableSet()
commandContext.receivers = findWeworkUser(setting.failSubscription.users.split(",").toMutableSet())
}
}

// #5318 为解决使用蓝鲸用户中心生成了带域名的用户名无法与企业微信账号对齐问题
private fun findWeworkUser(userSet: Set<String>): Set<String> {
if (userUseDomain!!) {
val weworkUserSet = mutableSetOf<String>()
userSet.forEach {
// 若用户名包含域,取域前的用户名.
if (it.contains("@")) {
weworkUserSet.add(it.substringBefore("@"))
}
}
return weworkUserSet
}
return userSet
}
}
4 changes: 4 additions & 0 deletions support-files/templates/#etc#ci#application-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ scm:
tGit:
hookSecret:
enableHookSecret: false

# 用户名是否包含域信息
user:
domain: true

0 comments on commit ebd93c8

Please sign in to comment.