Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: 创建流水线组失败,导致代码库开启PAC一直显示同步中 #11253 #11277

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TransferCreatorImpl @Autowired constructor(
inputMap[CheckoutAtomParam::repositoryType.name] = CheckoutAtomParam.CheckoutRepositoryType.ID
}

step.checkout?.url?.startsWith("http") == true -> {
step.checkout?.url != null -> {
inputMap[CheckoutAtomParam::repositoryUrl.name] = step.checkout?.url!!
inputMap[CheckoutAtomParam::repositoryType.name] = CheckoutAtomParam.CheckoutRepositoryType.URL
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ class PipelineViewService @Autowired constructor(
logger.warn("duplicate name , project:$projectId , user:$userId , view:$pipelineView")
throw ErrorCodeException(
errorCode = ProcessMessageCode.ERROR_VIEW_DUPLICATE_NAME,
defaultMessage = "view name is duplicate , name:${pipelineView.name}"
defaultMessage = "view name is duplicate , name:${pipelineView.name}",
params = arrayOf(pipelineView.name)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,49 @@ class PipelineYamlFacadeService @Autowired constructor(
logger.warn("enable pac,not found ci yaml from git|$projectId|$repoHashId")
return
}
// 创建yaml流水线组
pipelineYamlViewService.createYamlViewIfAbsent(
userId = action.data.getUserId(),
projectId = projectId,
repoHashId = repoHashId,
gitProjectName = action.data.setting.projectName,
directoryList = yamlPathList.map { GitActionCommon.getCiDirectory(it.yamlPath) }.toSet()
)
val path2PipelineExists = pipelineYamlInfoDao.getAllByRepo(
dslContext = dslContext, projectId = projectId, repoHashId = repoHashId
).associate {
it.filePath to YamlTriggerPipeline(
projectId = it.projectId,
repoHashId = it.repoHashId,
filePath = it.filePath,
pipelineId = it.pipelineId,
userId = userId
try {
// 创建yaml流水线组
pipelineYamlViewService.createYamlViewIfAbsent(
userId = action.data.getUserId(),
projectId = projectId,
repoHashId = repoHashId,
gitProjectName = action.data.setting.projectName,
directoryList = yamlPathList.map { GitActionCommon.getCiDirectory(it.yamlPath) }.toSet()
)
}
yamlPathList.forEach {
action.data.context.pipeline = path2PipelineExists[it.yamlPath]
action.data.context.yamlFile = it
pipelineEventDispatcher.dispatch(
PipelineYamlEnableEvent(
projectId = projectId,
yamlPath = it.yamlPath,
userId = userId,
eventStr = objectMapper.writeValueAsString(event),
metaData = action.metaData,
actionCommonData = action.data.eventCommon,
actionContext = action.data.context,
actionSetting = action.data.setting
val path2PipelineExists = pipelineYamlInfoDao.getAllByRepo(
dslContext = dslContext, projectId = projectId, repoHashId = repoHashId
).associate {
it.filePath to YamlTriggerPipeline(
projectId = it.projectId,
repoHashId = it.repoHashId,
filePath = it.filePath,
pipelineId = it.pipelineId,
userId = userId
)
}
yamlPathList.forEach {
action.data.context.pipeline = path2PipelineExists[it.yamlPath]
action.data.context.yamlFile = it
pipelineEventDispatcher.dispatch(
PipelineYamlEnableEvent(
projectId = projectId,
yamlPath = it.yamlPath,
userId = userId,
eventStr = objectMapper.writeValueAsString(event),
metaData = action.metaData,
actionCommonData = action.data.eventCommon,
actionContext = action.data.context,
actionSetting = action.data.setting
)
)
}
} catch (exception: Exception) {
logger.error("Failed to enable pac|projectId:$projectId|repoHashId:$repoHashId", exception)
pipelineYamlSyncService.enablePacFailed(
projectId = projectId,
repoHashId = repoHashId
)
throw exception
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ class PipelineYamlRepositoryService @Autowired constructor(
directory = directory
)
if (yamlPipelineCnt == 0L) {
logger.info("delete pipeline yaml view|$projectId|$repoHashId|$directory")
pipelineYamlViewService.getPipelineYamlView(
projectId = projectId,
repoHashId = repoHashId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ class PipelineYamlSyncService @Autowired constructor(
)
}

fun enablePacFailed(
projectId: String,
repoHashId: String
) {
client.get(ServiceRepositoryPacResource::class).updateYamlSyncStatus(
projectId = projectId,
repoHashId = repoHashId,
syncStatus = RepoYamlSyncStatusEnum.FAILED.name
)
}

/**
* 同步成功
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,29 @@ class CodeGitRepositoryService @Autowired constructor(
}

override fun pacCheckEnabled(projectId: String, userId: String, record: TRepositoryRecord, retry: Boolean) {
val codeGitRepository = compose(record)
if (codeGitRepository.authType != RepoAuthType.OAUTH) {
val repository = compose(record)
if (repository.authType != RepoAuthType.OAUTH) {
throw ErrorCodeException(errorCode = ERROR_AUTH_TYPE_ENABLED_PAC)
}
pacCheckEnabled(projectId = projectId, userId = userId, repository = codeGitRepository, retry = retry)
val gitProjectId =
pacCheckEnabled(projectId = projectId, userId = userId, repository = repository, retry = retry)
// 修复历史数据
if (repository.gitProjectId == null || repository.gitProjectId == 0L) {
val repositoryId = HashUtil.decodeOtherIdToLong(repository.repoHashId!!)
repositoryCodeGitDao.updateGitProjectId(
dslContext = dslContext,
id = repositoryId,
gitProjectId = gitProjectId
)
}
}

private fun pacCheckEnabled(
projectId: String,
userId: String,
repository: CodeGitRepository,
retry: Boolean
) {
): Long {
if (repository.authType != RepoAuthType.OAUTH) {
throw ErrorCodeException(errorCode = ERROR_AUTH_TYPE_ENABLED_PAC)
}
Expand Down Expand Up @@ -418,15 +428,7 @@ class CodeGitRepositoryService @Autowired constructor(
userName = userId,
event = CodeGitWebhookEvent.MERGE_REQUESTS_EVENTS.value
)
// 修复历史数据
if (repository.gitProjectId == null || repository.gitProjectId == 0L) {
val repositoryId = HashUtil.decodeOtherIdToLong(repository.repoHashId!!)
repositoryCodeGitDao.updateGitProjectId(
dslContext = dslContext,
id = repositoryId,
gitProjectId = gitProjectInfo.id
)
}
return gitProjectInfo.id
}

override fun getGitFileTree(projectId: String, userId: String, record: TRepositoryRecord): List<GitFileInfo> {
Expand Down
2 changes: 1 addition & 1 deletion support-files/i18n/process/message_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
2101124=Support target environment type: {0}
2101125=The view range of the pipeline group is inconsistent
2101126=Pipeline group creation reaches the upper limit
2101127=Duplicate pipeline group name
2101127=Duplicate pipeline group name: {0}
2101128=Invalid pipeline group name
2101129=Pipeline: The current build is running, do not submit retry requests repeatedly
2101130=Quality red line (admission) test failed
Expand Down
2 changes: 1 addition & 1 deletion support-files/i18n/process/message_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
2101124=支持 目标环境类型: {0}
2101125=流水线组的视图范围不一致
2101126=流水线组创建达到上限
2101127=流水线组名称重复
2101127=流水线组名称重复: {0}
2101128=流水线组名称不合法
2101129=流水线: 当前构建正在运行中,请勿重复提交重试请求
2101130=质量红线(准入)检测失败
Expand Down