Skip to content

Commit 0163635

Browse files
authored
Merge pull request #99 from tstromberg/main
Mark blocked incoming PRs as blocked as soon as we see them
2 parents 16202dd + 0b003df commit 0163635

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

cmd/review-goose/filtering_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,66 @@ func TestExtractOrgFromRepo(t *testing.T) {
158158
})
159159
}
160160
}
161+
162+
// TestIsAlreadyTrackedAsBlocked tests that sprinkler correctly identifies blocked PRs
163+
func TestIsAlreadyTrackedAsBlocked(t *testing.T) {
164+
app := &App{
165+
incoming: []PR{
166+
{URL: "https://github.com/org1/repo1/pull/1", IsBlocked: true},
167+
{URL: "https://github.com/org1/repo1/pull/2", IsBlocked: false},
168+
{URL: "https://github.com/org1/repo1/pull/3", NeedsReview: true, IsBlocked: false}, // NeedsReview but not IsBlocked
169+
},
170+
outgoing: []PR{
171+
{URL: "https://github.com/org2/repo2/pull/10", IsBlocked: true},
172+
{URL: "https://github.com/org2/repo2/pull/11", IsBlocked: false},
173+
},
174+
}
175+
176+
sm := &sprinklerMonitor{app: app}
177+
178+
tests := []struct {
179+
name string
180+
url string
181+
want bool
182+
}{
183+
{
184+
name: "incoming PR is blocked",
185+
url: "https://github.com/org1/repo1/pull/1",
186+
want: true,
187+
},
188+
{
189+
name: "incoming PR is not blocked",
190+
url: "https://github.com/org1/repo1/pull/2",
191+
want: false,
192+
},
193+
{
194+
name: "incoming PR needs review but is not blocked",
195+
url: "https://github.com/org1/repo1/pull/3",
196+
want: false,
197+
},
198+
{
199+
name: "outgoing PR is blocked",
200+
url: "https://github.com/org2/repo2/pull/10",
201+
want: true,
202+
},
203+
{
204+
name: "outgoing PR is not blocked",
205+
url: "https://github.com/org2/repo2/pull/11",
206+
want: false,
207+
},
208+
{
209+
name: "unknown PR",
210+
url: "https://github.com/org3/repo3/pull/99",
211+
want: false,
212+
},
213+
}
214+
215+
for _, tt := range tests {
216+
t.Run(tt.name, func(t *testing.T) {
217+
got := sm.isAlreadyTrackedAsBlocked(tt.url, "test", 1)
218+
if got != tt.want {
219+
t.Errorf("isAlreadyTrackedAsBlocked(%q) = %v, want %v", tt.url, got, tt.want)
220+
}
221+
})
222+
}
223+
}

cmd/review-goose/github.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ func (app *App) fetchTurnDataSync(ctx context.Context, issues []*github.Issue, u
610610
continue
611611
}
612612
(*incoming)[i].NeedsReview = needsReview
613+
(*incoming)[i].IsBlocked = isBlocked
613614
(*incoming)[i].ActionReason = actionReason
614615
(*incoming)[i].ActionKind = actionKind
615616
(*incoming)[i].TestState = testState

0 commit comments

Comments
 (0)