fun findRelevantVcsRootInstances()

in src/main/kotlin/org/jetbrains/teamcity/github/util/WebHooksHelper.kt [17:44]


    fun findRelevantVcsRootInstances(repository: Repository): Collection<VcsRootInstance> {
        if (repository.cloneUrl.isNullOrEmpty())
            return emptyList()

        val repoUrls = setOf(repository.gitUrl, repository.cloneUrl, repository.sshUrl).filterNotNull().map { normalizeGitUrl(it) }

        val prefilteredVcsRoots = projectManager.allVcsRoots
            .filter {vcsRoot ->
                isParamRefOrMatches(vcsRoot.vcsName) {
                    it == "jetbrains.git"
                }
                && isParamRefOrMatches(normalizeGitUrl(vcsRoot.getProperty("url"))) {
                    repoUrls.contains(it)
                }
            }
        val authorityHolder = securityContext.authorityHolder
        return prefilteredVcsRoots
            .flatMap {
                vcsRoot ->
                    vcsRoot.usagesInConfigurations
                        .filter { buildType -> authorityHolder.isPermissionGrantedForProject(buildType.projectId, Permission.VIEW_BUILD_CONFIGURATION_SETTINGS) }
                        .map { buildType -> buildType.getVcsRootInstanceForParent(vcsRoot) } +
                    versionedSettingsManager.getProjectsByOwnSettingsRoot(vcsRoot)
                        .filter { project -> authorityHolder.isPermissionGrantedForProject(project.projectId, Permission.VIEW_BUILD_CONFIGURATION_SETTINGS) }
                        .map { project -> versionedSettingsManager.getVersionedSettingsVcsRootInstance(project) }
            }.toSet().filterNotNull()
            .filter { repoUrls.contains(normalizeGitUrl(it.getProperty("url"))) }
    }