From 60932c79eec3b936e57117708dbe9ddf0043f575 Mon Sep 17 00:00:00 2001 From: yongyiduan Date: Tue, 18 Oct 2022 15:37:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[stream]github=20=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BC=98=E5=8C=96=20#7812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/tencent/devops/stream/pojo/GitRequestEvent.kt | 3 ++- .../devops/stream/trigger/actions/github/GithubPRActionGit.kt | 3 ++- .../devops/stream/trigger/git/service/GithubApiService.kt | 2 +- .../parsers/triggerParameter/GithubRequestEventHandle.kt | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/stream/api-stream/src/main/kotlin/com/tencent/devops/stream/pojo/GitRequestEvent.kt b/src/backend/ci/core/stream/api-stream/src/main/kotlin/com/tencent/devops/stream/pojo/GitRequestEvent.kt index a3424d60b0f..c009d015443 100644 --- a/src/backend/ci/core/stream/api-stream/src/main/kotlin/com/tencent/devops/stream/pojo/GitRequestEvent.kt +++ b/src/backend/ci/core/stream/api-stream/src/main/kotlin/com/tencent/devops/stream/pojo/GitRequestEvent.kt @@ -107,7 +107,8 @@ data class GitRequestEvent( fun GitRequestEvent.isMr() = objectKind == StreamGitObjectKind.MERGE_REQUEST.value fun GitRequestEvent.isFork(): Boolean { - return objectKind == StreamGitObjectKind.MERGE_REQUEST.value && + return (objectKind == StreamGitObjectKind.MERGE_REQUEST.value || + objectKind == StreamGitObjectKind.PULL_REQUEST.value) && sourceGitProjectId != null && sourceGitProjectId != gitProjectId } diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt index 3967ca3258a..1034540c341 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt @@ -118,7 +118,8 @@ class GithubPRActionGit( userId = this.data.eventCommon.userId ).accessLevel - accessLevel >= 30 + // >= TRIAGE + accessLevel >= 20 } catch (error: ErrorCodeException) { false } diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/git/service/GithubApiService.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/git/service/GithubApiService.kt index d02999b2bcd..a8ae4e50eb9 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/git/service/GithubApiService.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/git/service/GithubApiService.kt @@ -188,7 +188,7 @@ class GithubApiService @Autowired constructor( ), token = cred.toToken() ).data?.let { - GithubProjectUserInfo(GithubAccessLevelEnum.getGithubAccessLevel(it.permission).level, it.user.login) + GithubProjectUserInfo(GithubAccessLevelEnum.getGithubAccessLevel(it.roleName).level, it.user.login) } ?: GithubProjectUserInfo(GithubAccessLevelEnum.GUEST.level, "no_user") } diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerParameter/GithubRequestEventHandle.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerParameter/GithubRequestEventHandle.kt index 5a5ea85d5e6..0cbcfe397b7 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerParameter/GithubRequestEventHandle.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerParameter/GithubRequestEventHandle.kt @@ -80,9 +80,9 @@ object GithubRequestEventHandle { sourceGitProjectId = gitMrEvent.pullRequest.head.repo.id.toLong(), // Merged动作使用目标分支,因为源分支可能已被删除 branch = if (gitMrEvent.pullRequest.merged == true) { - gitMrEvent.pullRequest.head.ref - } else { gitMrEvent.pullRequest.base.ref + } else { + gitMrEvent.pullRequest.head.ref }, targetBranch = gitMrEvent.pullRequest.base.ref, commitId = gitMrEvent.pullRequest.head.sha, From 304f57d7cac00a4451eefdd79d7189ba7d626e56 Mon Sep 17 00:00:00 2001 From: yongyiduan Date: Tue, 18 Oct 2022 16:31:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[stream]github=20=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BC=98=E5=8C=96=20#7812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/stream/trigger/actions/github/GithubPRActionGit.kt | 3 ++- .../devops/stream/trigger/actions/tgit/TGitMrActionGit.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt index 1034540c341..e83f3d9b528 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/github/GithubPRActionGit.kt @@ -36,6 +36,7 @@ import com.tencent.devops.common.webhook.pojo.code.github.isPrForkNotMergeEvent import com.tencent.devops.process.yaml.v2.enums.StreamMrEventAction import com.tencent.devops.process.yaml.v2.enums.StreamObjectKind import com.tencent.devops.process.yaml.v2.models.on.TriggerOn +import com.tencent.devops.repository.pojo.enums.GithubAccessLevelEnum import com.tencent.devops.stream.dao.StreamBasicSettingDao import com.tencent.devops.stream.pojo.GitRequestEvent import com.tencent.devops.stream.pojo.enums.TriggerReason @@ -119,7 +120,7 @@ class GithubPRActionGit( ).accessLevel // >= TRIAGE - accessLevel >= 20 + accessLevel >= GithubAccessLevelEnum.TRIAGE.level } catch (error: ErrorCodeException) { false } diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/tgit/TGitMrActionGit.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/tgit/TGitMrActionGit.kt index 1ebbea9aa2d..41a0d725172 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/tgit/TGitMrActionGit.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/tgit/TGitMrActionGit.kt @@ -41,6 +41,7 @@ import com.tencent.devops.common.webhook.pojo.code.git.isMrMergeEvent import com.tencent.devops.process.yaml.v2.enums.StreamMrEventAction import com.tencent.devops.process.yaml.v2.enums.StreamObjectKind import com.tencent.devops.process.yaml.v2.models.on.TriggerOn +import com.tencent.devops.repository.pojo.enums.GitAccessLevelEnum import com.tencent.devops.scm.pojo.WebhookCommit import com.tencent.devops.scm.utils.code.git.GitUtils import com.tencent.devops.stream.dao.StreamBasicSettingDao @@ -126,7 +127,7 @@ class TGitMrActionGit( search = this.data.eventCommon.userId ).find { it.userId == this.data.eventCommon.userId }?.accessLevel - accessLevel != null && accessLevel >= 30 + accessLevel != null && accessLevel >= GitAccessLevelEnum.DEVELOPER.level } catch (error: ErrorCodeException) { false }