From cca4b5e552da1f5acd7f06350b2d172dee14218b Mon Sep 17 00:00:00 2001 From: Aayush Gupta <43479002+Aayyush@users.noreply.github.com> Date: Fri, 15 Jul 2022 07:38:54 -0700 Subject: [PATCH] Add apply checks filter (#268) --- server/events/vcs/inject.go | 12 +++++++++--- server/events/vcs/inject_lyft.go | 2 +- server/events/vcs/mergeability.go | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/server/events/vcs/inject.go b/server/events/vcs/inject.go index 46344044a7..93110a6166 100644 --- a/server/events/vcs/inject.go +++ b/server/events/vcs/inject.go @@ -4,7 +4,7 @@ package vcs func NewPullMergeabilityChecker(commitStatusPrefix string) MergeabilityChecker { statusFilters := newValidStatusFilters(commitStatusPrefix) - checksFilters := newValidChecksFilters() + checksFilters := newValidChecksFilters(commitStatusPrefix) return &PullMergeabilityChecker{ supplementalChecker: newSupplementalMergeabilityChecker(statusFilters, checksFilters), @@ -13,6 +13,8 @@ func NewPullMergeabilityChecker(commitStatusPrefix string) MergeabilityChecker { func newValidStatusFilters(commitStatusPrefix string) []ValidStatusFilter { titleMatcher := StatusTitleMatcher{TitlePrefix: commitStatusPrefix} + + // TODO: Remove apply status filter after github checks is fully rolled out. applyStatusFilter := &ApplyStatusFilter{ statusTitleMatcher: titleMatcher, } @@ -22,9 +24,13 @@ func newValidStatusFilters(commitStatusPrefix string) []ValidStatusFilter { } } -func newValidChecksFilters() []ValidChecksFilter { +func newValidChecksFilters(commitStatusPrefix string) []ValidChecksFilter { + titleMatcher := StatusTitleMatcher{TitlePrefix: commitStatusPrefix} + applyChecksFilter := &ApplyChecksFilter{ + statusTitleMatcher: titleMatcher, + } return []ValidChecksFilter{ - SuccessConclusionFilter, + SuccessConclusionFilter, applyChecksFilter, } } diff --git a/server/events/vcs/inject_lyft.go b/server/events/vcs/inject_lyft.go index 9b9e921264..11b942f22b 100644 --- a/server/events/vcs/inject_lyft.go +++ b/server/events/vcs/inject_lyft.go @@ -8,7 +8,7 @@ func NewLyftPullMergeabilityChecker(commitStatusPrefix string) MergeabilityCheck statusFilters := newValidStatusFilters(commitStatusPrefix) statusFilters = append(statusFilters, lyft.NewSQFilter()) - checksFilters := newValidChecksFilters() + checksFilters := newValidChecksFilters(commitStatusPrefix) supplementalChecker := newSupplementalMergeabilityChecker(statusFilters, checksFilters) supplementalChecker = lyft.NewOwnersStatusChecker(supplementalChecker) diff --git a/server/events/vcs/mergeability.go b/server/events/vcs/mergeability.go index 26ffe31021..90b2807e1e 100644 --- a/server/events/vcs/mergeability.go +++ b/server/events/vcs/mergeability.go @@ -50,6 +50,24 @@ type ValidChecksFilter interface { Filter(status []*github.CheckRun) []*github.CheckRun } +// ApplyChecksFilter filters statuses that correspond to atlantis apply +type ApplyChecksFilter struct { + statusTitleMatcher StatusTitleMatcher +} + +func (d ApplyChecksFilter) Filter(checks []*github.CheckRun) []*github.CheckRun { + var filtered []*github.CheckRun + for _, check := range checks { + if d.statusTitleMatcher.MatchesCommand(*check.Name, "apply") { + continue + } + + filtered = append(filtered, check) + } + + return filtered +} + // ConclusionFilter filters checks that match a given conclusion type ConclusionFilter string