Skip to content

Commit

Permalink
bug: 创建流水线组失败,导致代码库开启PAC一直显示同步中 TencentBlueKing#11253
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Nov 29, 2024
1 parent 850a2a5 commit 1a7b427
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,45 @@ 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 (ignored: Exception) {
logger.error("Failed to enable pac|projectId:$projectId|repoHashId:$repoHashId", ignored)
pipelineYamlSyncService.initPacFailed(projectId = projectId, repoHashId = repoHashId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ class PipelineYamlSyncService @Autowired constructor(
)
}

fun initPacFailed(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

0 comments on commit 1a7b427

Please sign in to comment.