Skip to content

Commit

Permalink
Merge pull request #8598 from hejieehe/feat_8570
Browse files Browse the repository at this point in the history
feat: 修改Git触发的判断条件 Tencent#8570
  • Loading branch information
bkci-bot authored Apr 24, 2023
2 parents 195a634 + 58e2f65 commit eda1a49
Showing 1 changed file with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ class TGitPushTriggerHandler(
to = event.before
)
} else {
val changeFiles = mutableSetOf<String>()
commits?.forEach { commit ->
changeFiles.addAll(commit.added ?: listOf())
changeFiles.addAll(commit.removed ?: listOf())
changeFiles.addAll(commit.modified ?: listOf())
}
changeFiles
getPushChangeFiles(
event = event,
projectId = projectId,
repository = repository
)
}
pushChangeFiles = eventPaths
return PathFilterFactory.newPathFilter(
Expand Down Expand Up @@ -277,4 +275,35 @@ class TGitPushTriggerHandler(
)
}
}

private fun getPushChangeFiles(
event: GitPushEvent,
projectId: String,
repository: Repository
): Set<String> {
val changeFileList = mutableSetOf<String>()
changeFileList.addAll(
eventCacheService.getChangeFileList(
projectId = projectId,
repo = repository,
from = event.before,
to = event.after
)
)
if (changeFileList.isEmpty()) {
// 兜底方案,若关联代码的权限失效,则集合为空,使用webhook信息进行触发
logger.warn(
"Failed to get the change file list," +
"use webhook information to trigger," +
"repo[${repository.projectName}]|" +
"commitId[${event.checkout_sha}]"
)
event.commits?.forEach { commit ->
changeFileList.addAll(commit.added ?: listOf())
changeFileList.addAll(commit.removed ?: listOf())
changeFileList.addAll(commit.modified ?: listOf())
}
}
return changeFileList
}
}

0 comments on commit eda1a49

Please sign in to comment.