diff --git a/plugins/git4idea/src/git4idea/push/GitPushRepoResult.java b/plugins/git4idea/src/git4idea/push/GitPushRepoResult.java index 1cc225e9d4be..0ab9c14bc8b8 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushRepoResult.java +++ b/plugins/git4idea/src/git4idea/push/GitPushRepoResult.java @@ -108,8 +108,7 @@ public final class GitPushRepoResult { /** * Returns the branch we were pushing to, in the full-name format, e.g. {@code refs/remotes/origin/master}. */ - @NotNull - String getTargetBranch() { + public @NotNull String getTargetBranch() { return myTargetBranch; } diff --git a/plugins/github/src/org/jetbrains/plugins/github/notification/GHNotificationService.kt b/plugins/github/src/org/jetbrains/plugins/github/notification/GHNotificationService.kt index 9bd68fade5cd..2854fab01bd7 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/notification/GHNotificationService.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/notification/GHNotificationService.kt @@ -25,6 +25,10 @@ internal class GHNotificationService(private val project: Project, parentCs: Cor serviceScope.launch { val toolWindowVm = project.serviceAsync() val projectVm = toolWindowVm.projectVm.filterNotNull().first() + + val defaultBranch = projectVm.defaultBranch + if (defaultBranch != null && pushResult.targetBranch.endsWith(defaultBranch)) return@launch + val existingPullRequest = projectVm.isExistingPullRequest(pushResult) ?: return@launch if (!existingPullRequest) { notifyReviewCreation(project) diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/toolwindow/model/GHPRToolWindowProjectViewModel.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/toolwindow/model/GHPRToolWindowProjectViewModel.kt index fc80d9158aab..f5a8ed599540 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/toolwindow/model/GHPRToolWindowProjectViewModel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/toolwindow/model/GHPRToolWindowProjectViewModel.kt @@ -40,6 +40,7 @@ class GHPRToolWindowProjectViewModel internal constructor( private val cs = parentCs.childScope() internal val dataContext: GHPRDataContext = connection.dataContext + val defaultBranch: String? = dataContext.repositoryDataService.defaultBranchName private val allRepos = project.service().knownRepositories.map(GHGitRepositoryMapping::repository) val repository: GHRepositoryCoordinates = dataContext.repositoryDataService.repositoryCoordinates diff --git a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/toolwindow/model/GitLabToolWindowProjectViewModel.kt b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/toolwindow/model/GitLabToolWindowProjectViewModel.kt index c609c94c90cf..1d2a71fc3944 100644 --- a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/toolwindow/model/GitLabToolWindowProjectViewModel.kt +++ b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/toolwindow/model/GitLabToolWindowProjectViewModel.kt @@ -17,6 +17,7 @@ import git4idea.remote.hosting.changesSignalFlow import git4idea.repo.GitRemote import git4idea.repo.GitRepository import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Deferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch @@ -30,6 +31,7 @@ import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabAccountManager import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabAccountViewModel import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabAccountViewModelImpl import org.jetbrains.plugins.gitlab.mergerequest.data.GitLabMergeRequestDetails +import org.jetbrains.plugins.gitlab.mergerequest.data.GitLabProject import org.jetbrains.plugins.gitlab.mergerequest.diff.GitLabMergeRequestDiffViewModel import org.jetbrains.plugins.gitlab.mergerequest.file.GitLabMergeRequestsFilesController import org.jetbrains.plugins.gitlab.mergerequest.file.GitLabMergeRequestsFilesControllerImpl @@ -61,12 +63,13 @@ private constructor(parentCs: CoroutineScope, val connectionId: String = connection.id override val projectName: @Nls String = connection.repo.repository.projectPath.name + val defaultBranch: Deferred = connection.projectData.defaultBranch + private val mergeRequestsVms = Caffeine.newBuilder().build>> { iid -> - val projectData = connection.projectData - projectData.mergeRequests.getShared(iid) + connection.projectData.mergeRequests.getShared(iid) .transformConsecutiveSuccesses { mapScoped { - GitLabMergeRequestViewModels(project, this, projectData, it, this@GitLabToolWindowProjectViewModel, connection.currentUser) + GitLabMergeRequestViewModels(project, this, connection.projectData, it, this@GitLabToolWindowProjectViewModel, connection.currentUser) } } .shareIn(cs, SharingStarted.WhileSubscribed(0, 0), 1) diff --git a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabNotificationService.kt b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabNotificationService.kt index 1a06bade3b79..2a0b1481fb9b 100644 --- a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabNotificationService.kt +++ b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabNotificationService.kt @@ -19,10 +19,14 @@ import org.jetbrains.plugins.gitlab.util.GitLabBundle internal class GitLabNotificationService(private val project: Project, parentCs: CoroutineScope) { private val serviceScope = parentCs.childScope(CoroutineName("GitLab notification service scope")) - fun showReviewCreationNotification() { + fun showReviewCreationNotification(targetBranch: String) { serviceScope.launch { val toolWindowVm = project.serviceAsync() val projectVm = toolWindowVm.projectVm.filterNotNull().first() + + val defaultBranch = projectVm.defaultBranch.await() + if (targetBranch.endsWith(defaultBranch)) return@launch + val mergeRequest = projectVm.mergeRequestOnCurrentBranch.first() if (mergeRequest == null) { notifyReviewCreation(project) diff --git a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabPushNotificationListener.kt b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabPushNotificationListener.kt index e5f8fbd7e74c..ac85cef5fed5 100644 --- a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabPushNotificationListener.kt +++ b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/notification/GitLabPushNotificationListener.kt @@ -13,7 +13,7 @@ internal class GitLabPushNotificationListener(private val project: Project) : Gi GitPushRepoResult.Type.SUCCESS, GitPushRepoResult.Type.NEW_BRANCH, GitPushRepoResult.Type.FORCED -> { - project.service().showReviewCreationNotification() + project.service().showReviewCreationNotification(pushResult.targetBranch) } else -> {} }