From 88fa4690df06b946fe1fc6b1e33907bb76b0475c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 3 Apr 2023 18:32:32 +0800 Subject: [PATCH 01/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/tgit/TGitPushTriggerHandler.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index b77e9370206..820040fe0d5 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -174,13 +174,12 @@ class TGitPushTriggerHandler( to = event.before ) } else { - val changeFiles = mutableSetOf() - commits?.forEach { commit -> - changeFiles.addAll(commit.added ?: listOf()) - changeFiles.addAll(commit.removed ?: listOf()) - changeFiles.addAll(commit.modified ?: listOf()) - } - changeFiles + gitScmService.getChangeFileList( + projectId = projectId, + repo = repository, + from = event.after, + to = event.before + ) } pushChangeFiles = eventPaths return PathFilterFactory.newPathFilter( From aa3b588f9aaccf93c265a27d33d9fe342e3c58b0 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 10 Apr 2023 12:28:08 +0800 Subject: [PATCH 02/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/tgit/TGitPushTriggerHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 820040fe0d5..5741a75ab95 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -177,8 +177,8 @@ class TGitPushTriggerHandler( gitScmService.getChangeFileList( projectId = projectId, repo = repository, - from = event.after, - to = event.before + from = event.before, + to = event.after ) } pushChangeFiles = eventPaths From ac62d993914f8ea4f1cd27c3bb49730b47b8c2d6 Mon Sep 17 00:00:00 2001 From: v_hejieehe Date: Mon, 10 Apr 2023 14:14:57 +0800 Subject: [PATCH 03/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/tgit/TGitPushTriggerHandler.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index b77e9370206..5741a75ab95 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -174,13 +174,12 @@ class TGitPushTriggerHandler( to = event.before ) } else { - val changeFiles = mutableSetOf() - commits?.forEach { commit -> - changeFiles.addAll(commit.added ?: listOf()) - changeFiles.addAll(commit.removed ?: listOf()) - changeFiles.addAll(commit.modified ?: listOf()) - } - changeFiles + gitScmService.getChangeFileList( + projectId = projectId, + repo = repository, + from = event.before, + to = event.after + ) } pushChangeFiles = eventPaths return PathFilterFactory.newPathFilter( From 3a9bf809a05f8880f3baaa9ab8a2fb4027395c9f Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 14 Apr 2023 16:06:20 +0800 Subject: [PATCH 04/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/tgit/TGitPushTriggerHandler.kt | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 5741a75ab95..1a95db026dc 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -174,12 +174,32 @@ class TGitPushTriggerHandler( to = event.before ) } else { - gitScmService.getChangeFileList( - projectId = projectId, - repo = repository, - from = event.before, - to = event.after - ) + try { + gitScmService.getChangeFileList( + projectId = projectId, + repo = repository, + from = event.before, + to = event.after + ) + } catch (e: Exception) { + // 兜底方案,若关联代码的权限 + logger.warn( + "Failed to get the change file list," + + "use webhook information to trigger," + + "please check the repository permissions," + + "projectId[$projectId]," + + "repo[repo]," + + "form[${event.before}]," + + "to[${event.after}]" + ) + val changeFiles = mutableSetOf() + commits?.forEach { commit -> + changeFiles.addAll(commit.added ?: listOf()) + changeFiles.addAll(commit.removed ?: listOf()) + changeFiles.addAll(commit.modified ?: listOf()) + } + changeFiles + } } pushChangeFiles = eventPaths return PathFilterFactory.newPathFilter( From ffbd2d11cf6f607e9d3e636d322abc13ea306a06 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 17 Apr 2023 09:42:42 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/webhook/service/code/GitScmService.kt | 2 ++ .../webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt index 9afafaed334..87900104cf2 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt @@ -29,6 +29,7 @@ package com.tencent.devops.common.webhook.service.code import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.api.exception.RemoteServiceException import com.tencent.devops.common.api.util.DHUtil import com.tencent.devops.common.client.Client import com.tencent.devops.repository.api.ServiceOauthResource @@ -221,6 +222,7 @@ class GitScmService @Autowired constructor( } } catch (ignore: Exception) { logger.warn("fail to get change file list", ignore) + throw RemoteServiceException("fail to get change file list") } return changeSet } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 1a95db026dc..1a0ab829fbb 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -182,7 +182,7 @@ class TGitPushTriggerHandler( to = event.after ) } catch (e: Exception) { - // 兜底方案,若关联代码的权限 + // 兜底方案,若关联代码的权限失效,则使用webhook信息进行触发 logger.warn( "Failed to get the change file list," + "use webhook information to trigger," + From 84e0fda714ff2ef9c1bba5ca58c07df1890479bf Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 17 Apr 2023 09:54:51 +0800 Subject: [PATCH 06/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/service/code/EventCacheService.kt | 22 +++++-- .../webhook/service/code/GitScmService.kt | 62 +++++++++---------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt index e3bbff4c95a..702ab7b4311 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt @@ -8,6 +8,7 @@ import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.GitCommit import com.tencent.devops.scm.pojo.GitMrInfo import com.tencent.devops.scm.pojo.GitMrReviewInfo +import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -20,6 +21,10 @@ class EventCacheService @Autowired constructor( private val client: Client ) { + companion object { + private val logger = LoggerFactory.getLogger(EventCacheService::class.java) + } + fun getMergeRequestReviewersInfo(projectId: String, mrId: Long?, repo: Repository): GitMrReviewInfo? { val eventCache = EventCacheUtil.getOrInitRepoCache(projectId = projectId, repo = repo) return eventCache?.gitMrReviewInfo ?: run { @@ -69,12 +74,17 @@ class EventCacheService @Autowired constructor( fun getChangeFileList(projectId: String, repo: Repository, from: String, to: String): Set { val eventCache = EventCacheUtil.getOrInitRepoCache(projectId = projectId, repo = repo) return eventCache?.gitCompareChangeFiles ?: run { - val compareChangFile = gitScmService.getChangeFileList( - projectId = projectId, - repo = repo, - from = from, - to = to - ) + val compareChangFile = try { + gitScmService.getChangeFileList( + projectId = projectId, + repo = repo, + from = from, + to = to + ) + } catch (e: Exception) { + logger.warn("fail to get change file list", e) + setOf() + } eventCache?.gitCompareChangeFiles = compareChangFile compareChangFile } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt index 87900104cf2..c28db1eeef5 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.webhook.service.code import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.api.exception.RemoteServiceException import com.tencent.devops.common.api.util.DHUtil import com.tencent.devops.common.client.Client import com.tencent.devops.repository.api.ServiceOauthResource @@ -187,42 +186,37 @@ class GitScmService @Autowired constructor( ): Set { val type = getType(repo) ?: return emptySet() val changeSet = mutableSetOf() - try { - val tokenType = if (type.first == RepoAuthType.OAUTH) TokenTypeEnum.OAUTH else TokenTypeEnum.PRIVATE_KEY - val token = getToken( - projectId = projectId, - credentialId = repo.credentialId, - userName = repo.userName, - authType = tokenType - ) - for (i in 1..10) { - // 反向进行三点比较可以比较出rebase的真实提交 - val result = client.get(ServiceGitResource::class).getChangeFileList( - token = token, - tokenType = tokenType, - gitProjectId = repo.projectName, - from = from, - to = to, - straight = false, - page = i, - pageSize = 100 - ).data ?: emptyList() - changeSet.addAll( - result.map { - if (it.deletedFile) { - it.oldPath - } else { - it.newPath - } + val tokenType = if (type.first == RepoAuthType.OAUTH) TokenTypeEnum.OAUTH else TokenTypeEnum.PRIVATE_KEY + val token = getToken( + projectId = projectId, + credentialId = repo.credentialId, + userName = repo.userName, + authType = tokenType + ) + for (i in 1..10) { + // 反向进行三点比较可以比较出rebase的真实提交 + val result = client.get(ServiceGitResource::class).getChangeFileList( + token = token, + tokenType = tokenType, + gitProjectId = repo.projectName, + from = from, + to = to, + straight = false, + page = i, + pageSize = 100 + ).data ?: emptyList() + changeSet.addAll( + result.map { + if (it.deletedFile) { + it.oldPath + } else { + it.newPath } - ) - if (result.size < 100) { - break } + ) + if (result.size < 100) { + break } - } catch (ignore: Exception) { - logger.warn("fail to get change file list", ignore) - throw RemoteServiceException("fail to get change file list") } return changeSet } From b6bde8b883c66e9218bcdfd8aa3bd79bd1b285c8 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 21 Apr 2023 10:49:27 +0800 Subject: [PATCH 07/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/service/code/EventCacheService.kt | 17 ++---- .../webhook/service/code/GitScmService.kt | 60 ++++++++++--------- .../handler/tgit/TGitPushTriggerHandler.kt | 18 +++--- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt index 702ab7b4311..4cee159b1b8 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt @@ -74,17 +74,12 @@ class EventCacheService @Autowired constructor( fun getChangeFileList(projectId: String, repo: Repository, from: String, to: String): Set { val eventCache = EventCacheUtil.getOrInitRepoCache(projectId = projectId, repo = repo) return eventCache?.gitCompareChangeFiles ?: run { - val compareChangFile = try { - gitScmService.getChangeFileList( - projectId = projectId, - repo = repo, - from = from, - to = to - ) - } catch (e: Exception) { - logger.warn("fail to get change file list", e) - setOf() - } + val compareChangFile = gitScmService.getChangeFileList( + projectId = projectId, + repo = repo, + from = from, + to = to + ) eventCache?.gitCompareChangeFiles = compareChangFile compareChangFile } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt index c28db1eeef5..9afafaed334 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/GitScmService.kt @@ -186,37 +186,41 @@ class GitScmService @Autowired constructor( ): Set { val type = getType(repo) ?: return emptySet() val changeSet = mutableSetOf() - val tokenType = if (type.first == RepoAuthType.OAUTH) TokenTypeEnum.OAUTH else TokenTypeEnum.PRIVATE_KEY - val token = getToken( - projectId = projectId, - credentialId = repo.credentialId, - userName = repo.userName, - authType = tokenType - ) - for (i in 1..10) { - // 反向进行三点比较可以比较出rebase的真实提交 - val result = client.get(ServiceGitResource::class).getChangeFileList( - token = token, - tokenType = tokenType, - gitProjectId = repo.projectName, - from = from, - to = to, - straight = false, - page = i, - pageSize = 100 - ).data ?: emptyList() - changeSet.addAll( - result.map { - if (it.deletedFile) { - it.oldPath - } else { - it.newPath + try { + val tokenType = if (type.first == RepoAuthType.OAUTH) TokenTypeEnum.OAUTH else TokenTypeEnum.PRIVATE_KEY + val token = getToken( + projectId = projectId, + credentialId = repo.credentialId, + userName = repo.userName, + authType = tokenType + ) + for (i in 1..10) { + // 反向进行三点比较可以比较出rebase的真实提交 + val result = client.get(ServiceGitResource::class).getChangeFileList( + token = token, + tokenType = tokenType, + gitProjectId = repo.projectName, + from = from, + to = to, + straight = false, + page = i, + pageSize = 100 + ).data ?: emptyList() + changeSet.addAll( + result.map { + if (it.deletedFile) { + it.oldPath + } else { + it.newPath + } } + ) + if (result.size < 100) { + break } - ) - if (result.size < 100) { - break } + } catch (ignore: Exception) { + logger.warn("fail to get change file list", ignore) } return changeSet } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 1a0ab829fbb..098599a0fd4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -174,15 +174,17 @@ class TGitPushTriggerHandler( to = event.before ) } else { - try { + val changeFileList = mutableSetOf() + changeFileList.addAll( gitScmService.getChangeFileList( projectId = projectId, repo = repository, from = event.before, to = event.after ) - } catch (e: Exception) { - // 兜底方案,若关联代码的权限失效,则使用webhook信息进行触发 + ) + if(changeFileList.isEmpty()){ + // 兜底方案,若关联代码的权限失效,则集合为空,使用webhook信息进行触发 logger.warn( "Failed to get the change file list," + "use webhook information to trigger," + @@ -192,14 +194,14 @@ class TGitPushTriggerHandler( "form[${event.before}]," + "to[${event.after}]" ) - val changeFiles = mutableSetOf() commits?.forEach { commit -> - changeFiles.addAll(commit.added ?: listOf()) - changeFiles.addAll(commit.removed ?: listOf()) - changeFiles.addAll(commit.modified ?: listOf()) + changeFileList.addAll(commit.added ?: listOf()) + changeFileList.addAll(commit.removed ?: listOf()) + changeFileList.addAll(commit.modified ?: listOf()) } - changeFiles + } + changeFileList } pushChangeFiles = eventPaths return PathFilterFactory.newPathFilter( From b2099cd33184b259558483da3f01414840d3c41a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 21 Apr 2023 10:50:32 +0800 Subject: [PATCH 08/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/webhook/service/code/EventCacheService.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt index 4cee159b1b8..e3bbff4c95a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/EventCacheService.kt @@ -8,7 +8,6 @@ import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.GitCommit import com.tencent.devops.scm.pojo.GitMrInfo import com.tencent.devops.scm.pojo.GitMrReviewInfo -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -21,10 +20,6 @@ class EventCacheService @Autowired constructor( private val client: Client ) { - companion object { - private val logger = LoggerFactory.getLogger(EventCacheService::class.java) - } - fun getMergeRequestReviewersInfo(projectId: String, mrId: Long?, repo: Repository): GitMrReviewInfo? { val eventCache = EventCacheUtil.getOrInitRepoCache(projectId = projectId, repo = repo) return eventCache?.gitMrReviewInfo ?: run { From 380c1de1d6eb60ffa5744f63e4d7ae05d0008436 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 21 Apr 2023 10:55:25 +0800 Subject: [PATCH 09/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/tgit/TGitPushTriggerHandler.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 098599a0fd4..1a5cd63ba87 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -183,7 +183,7 @@ class TGitPushTriggerHandler( to = event.after ) ) - if(changeFileList.isEmpty()){ + if (changeFileList.isEmpty()) { // 兜底方案,若关联代码的权限失效,则集合为空,使用webhook信息进行触发 logger.warn( "Failed to get the change file list," + @@ -199,7 +199,6 @@ class TGitPushTriggerHandler( changeFileList.addAll(commit.removed ?: listOf()) changeFileList.addAll(commit.modified ?: listOf()) } - } changeFileList } From f1a830eb722c4aad12db5235fa9e2698d115a6d6 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 21 Apr 2023 11:10:50 +0800 Subject: [PATCH 10/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/tgit/TGitPushTriggerHandler.kt | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 1a5cd63ba87..7f885a80ed5 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -174,33 +174,11 @@ class TGitPushTriggerHandler( to = event.before ) } else { - val changeFileList = mutableSetOf() - changeFileList.addAll( - gitScmService.getChangeFileList( - projectId = projectId, - repo = repository, - from = event.before, - to = event.after - ) + getPushChangeFiles( + event = event, + projectId = projectId, + repository = repository ) - if (changeFileList.isEmpty()) { - // 兜底方案,若关联代码的权限失效,则集合为空,使用webhook信息进行触发 - logger.warn( - "Failed to get the change file list," + - "use webhook information to trigger," + - "please check the repository permissions," + - "projectId[$projectId]," + - "repo[repo]," + - "form[${event.before}]," + - "to[${event.after}]" - ) - commits?.forEach { commit -> - changeFileList.addAll(commit.added ?: listOf()) - changeFileList.addAll(commit.removed ?: listOf()) - changeFileList.addAll(commit.modified ?: listOf()) - } - } - changeFileList } pushChangeFiles = eventPaths return PathFilterFactory.newPathFilter( @@ -297,4 +275,38 @@ class TGitPushTriggerHandler( ) } } + + private fun getPushChangeFiles( + event: GitPushEvent, + projectId: String, + repository: Repository + ): Set { + val changeFileList = mutableSetOf() + changeFileList.addAll( + gitScmService.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," + + "please check the repository permissions," + + "projectId[$projectId]," + + "repo[$repository]," + + "form[${event.before}]," + + "to[${event.after}]" + ) + event.commits?.forEach { commit -> + changeFileList.addAll(commit.added ?: listOf()) + changeFileList.addAll(commit.removed ?: listOf()) + changeFileList.addAll(commit.modified ?: listOf()) + } + } + return changeFileList + } } From 58e2f65620fb83d19360354244d0d4400c21ecb5 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 21 Apr 2023 13:03:51 +0800 Subject: [PATCH 11/11] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9Git=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=20Tencen?= =?UTF-8?q?t#8570?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/tgit/TGitPushTriggerHandler.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 7f885a80ed5..8598535582b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -283,7 +283,7 @@ class TGitPushTriggerHandler( ): Set { val changeFileList = mutableSetOf() changeFileList.addAll( - gitScmService.getChangeFileList( + eventCacheService.getChangeFileList( projectId = projectId, repo = repository, from = event.before, @@ -295,11 +295,8 @@ class TGitPushTriggerHandler( logger.warn( "Failed to get the change file list," + "use webhook information to trigger," + - "please check the repository permissions," + - "projectId[$projectId]," + - "repo[$repository]," + - "form[${event.before}]," + - "to[${event.after}]" + "repo[${repository.projectName}]|" + + "commitId[${event.checkout_sha}]" ) event.commits?.forEach { commit -> changeFileList.addAll(commit.added ?: listOf())