Skip to content

Commit

Permalink
Merge pull request #7814 from yongyiduan/issue_7812_1.9
Browse files Browse the repository at this point in the history
[stream]github 审核权限优化 #7812
  • Loading branch information
irwinsun authored Oct 18, 2022
2 parents 2e792ee + 304f57d commit fdc5cb8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,7 +119,8 @@ class GithubPRActionGit(
userId = this.data.eventCommon.userId
).accessLevel

accessLevel >= 30
// >= TRIAGE
accessLevel >= GithubAccessLevelEnum.TRIAGE.level
} catch (error: ErrorCodeException) {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fdc5cb8

Please sign in to comment.