Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 支持只监听某个branch下的tag #3332 #3599

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ data class GitTagPushEvent(
val repository: GitCommitRepository,
val commits: List<GitCommit>,
val total_commits_count: Int,
val operation_kind: String?
val operation_kind: String?,
val create_from: String
) : GitEvent() {
companion object {
const val classType = "tag_push"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,30 @@ open class GitWebHookMatcher(val event: GitEvent) : ScmWebhookMatcher {

// 匹配
val eventTag = getTag(gitTagPushEvent.ref)
val createFrom = gitTagPushEvent.create_from
with(webHookParams) {
if (doExcludeBranchMatch(excludeTagName, eventTag, pipelineId)) {
logger.warn("Do tag event match fail for exclude branch match for pipeline: $pipelineId")
return ScmWebhookMatcher.MatchResult(false)
}

if (doExcludeBranchMatch(excludeBranchName, createFrom, pipelineId)) {
logger.warn("Do tag event match fail for exclude create from branch match for pipeline: $pipelineId")
return ScmWebhookMatcher.MatchResult(false)
}

val matchBranch = doIncludeBranchMatch(tagName, eventTag, pipelineId)
if (matchBranch == null) {
logger.warn("Do tag event match fail for include branch not match for pipeline: $pipelineId")
return ScmWebhookMatcher.MatchResult(false)
}

val matchFromBranch = doIncludeBranchMatch(branchName, createFrom, pipelineId)
if (matchFromBranch == null) {
logger.warn("Do tag event match fail for include create from branch not match for pipeline: $pipelineId")
return ScmWebhookMatcher.MatchResult(false)
}

logger.info("Do tag match success for pipeline: $pipelineId")
return ScmWebhookMatcher.MatchResult(true, mapOf(MATCH_BRANCH to matchBranch, MATCH_PATHS to ""))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_PUSH_MODIFY_FILE_PREFIX
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_PUSH_OPERATION_KIND
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_PUSH_TOTAL_COMMIT
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_PUSH_USERNAME
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_TAG_CREATE_FROM
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_TAG_NAME
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_TAG_OPERATION
import com.tencent.devops.scm.pojo.BK_REPO_GIT_WEBHOOK_TAG_USERNAME
Expand Down Expand Up @@ -164,6 +165,7 @@ class GitWebHookStartParam(
startParams[BK_REPO_GIT_WEBHOOK_TAG_OPERATION] = gitTagPushEvent.operation_kind ?: ""
startParams[BK_REPO_GIT_WEBHOOK_PUSH_TOTAL_COMMIT] = gitTagPushEvent.total_commits_count
startParams[BK_REPO_GIT_WEBHOOK_TAG_USERNAME] = matcher.getUsername()
startParams[BK_REPO_GIT_WEBHOOK_TAG_CREATE_FROM] = gitTagPushEvent.create_from ?: ""
genCommitsParam(startParams, gitTagPushEvent.commits)
}

Expand Down