Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#10070 from hejieehe/feat_9302
Browse files Browse the repository at this point in the history
feat: svn webhook接口切换 TencentBlueKing#9302
  • Loading branch information
bkci-bot authored Mar 6, 2024
2 parents dce85b2 + fce165a commit 1bda39b
Showing 1 changed file with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,35 +159,13 @@ class CodeSvnScmImpl constructor(
try {
addWebhookByToken(hookUrl, projectName)
} catch (ignored: ScmException) {
// 工蜂迁移svn项目后,svn项目名与原有git项目名相同,导致项目名冲突,为此在工蜂在svn项目名后添加[_svn]后缀,但在复制svn路径时可能
// 缺少[_svn],如实际路径为[bk_ci/ci_svn],但复制路径为[bk_ci/ci],所以当报项目不存在时,增加[_svn]后缀后重试
if (ignored.message == I18nUtil.getCodeLanMessage(CommonMessageCode.ENGINEERING_REPO_NOT_EXIST) &&
!projectName.endsWith(SVN_PROJECT_NAME_SUFFIX)
) {
try {
logger.info("retry addWebHookSVN|newProjectName=$projectName$SVN_PROJECT_NAME_SUFFIX")
addWebhookByToken(
hookUrl = hookUrl,
projectName = "$projectName$SVN_PROJECT_NAME_SUFFIX"
)
} catch (ignored: ScmException) {
logger.error("Fail to retry add the webhook", ignored)
throw ScmException(
message = ignored.message ?: I18nUtil.getCodeLanMessage(
CommonMessageCode.SVN_CREATE_HOOK_FAIL
),
scmType = ScmType.CODE_SVN.name
)
}
} else {
logger.error("Fail to add the webhook", ignored)
throw ScmException(
message = ignored.message ?: I18nUtil.getCodeLanMessage(
CommonMessageCode.SVN_CREATE_HOOK_FAIL
),
scmType = ScmType.CODE_SVN.name
)
}
// 工蜂迁移svn项目后,svn项目名与原有git项目名相同,导致项目名冲突,为此在工蜂在svn组名后添加[_svn]后缀,但在复制svn路径时可能
// 缺少[_svn],如实际路径为[bk_ci_svn/ci],但复制路径为[bk_ci/ci],所以当报项目不存在时,组名处增加[_svn]后缀后重试
tryAddSuffixToGroupName(
projectName = projectName,
hookUrl = hookUrl,
ignored = ignored
)
}
}

Expand Down Expand Up @@ -355,6 +333,41 @@ class CodeSvnScmImpl constructor(
}
}

/**
* 尝试添加后缀到组名
*/
private fun tryAddSuffixToGroupName(
projectName: String,
hookUrl: String,
ignored: Exception
) {
try {
if (ignored.message != I18nUtil.getCodeLanMessage(CommonMessageCode.ENGINEERING_REPO_NOT_EXIST)) {
throw ignored
} else {
val projectNameArr = projectName.split("/").toMutableList()
if (projectNameArr.size <= 1 || projectNameArr[0].endsWith(SVN_PROJECT_NAME_SUFFIX)) {
throw ignored
}
projectNameArr[0] = projectNameArr[0].plus(SVN_PROJECT_NAME_SUFFIX)
val newProjectName = projectNameArr.joinToString("/")
logger.info("retry addWebHookSVN|new projectName=$newProjectName")
addWebhookByToken(
hookUrl = hookUrl,
projectName = newProjectName
)
}
} catch (ignored: Exception) {
logger.error("Fail to add the webhook", ignored)
throw ScmException(
message = ignored.message ?: I18nUtil.getCodeLanMessage(
CommonMessageCode.SVN_CREATE_HOOK_FAIL
),
scmType = ScmType.CODE_SVN.name
)
}
}

companion object {
private val logger = LoggerFactory.getLogger(CodeSvnScmImpl::class.java)

Expand Down

0 comments on commit 1bda39b

Please sign in to comment.