Skip to content
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
2 changes: 2 additions & 0 deletions pullrequest/review/reviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/go-chi/httplog"
pe "github.com/marqeta/pr-bot/errors"
Expand Down Expand Up @@ -44,6 +45,7 @@ func (r *reviewer) Approve(ctx context.Context, id id.PR, body string, opts Appr
return r.handleAutoMergeError(ctx, id, err)
}
oplog.Info().Msgf("enabled auto merge on PR")
time.Sleep(500 * time.Millisecond)
err = r.api.AddReview(ctx, id, body, gh.Approve)
if err != nil {
oplog.Err(err).Msgf("error approving PR")
Expand Down
27 changes: 27 additions & 0 deletions pullrequest/review/reviewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

gh "github.com/marqeta/pr-bot/github"
"github.com/marqeta/pr-bot/id"
Expand Down Expand Up @@ -176,6 +177,32 @@ func Test_reviewer_Approve(t *testing.T) {
}
}

func Test_reviewer_Approve_Sleep(t *testing.T) {
ctx := context.Background()
mockAPI := gh.NewMockAPI(t)
metrics := metrics.NewNoopEmitter()
r := review.NewReviewer(mockAPI, metrics)

// Set up expectations
mockAPI.EXPECT().EnableAutoMerge(ctx, sampleID(), githubv4.PullRequestMergeMethodMerge).Return(nil)
mockAPI.EXPECT().AddReview(ctx, sampleID(), "LGTM", gh.Approve).Return(nil)

// Measure the time to verify sleep
start := time.Now()
err := r.Approve(ctx, sampleID(), "LGTM", review.ApproveOptions{
MergeMethod: githubv4.PullRequestMergeMethodMerge,
})
duration := time.Since(start)

// Verify no error and sleep duration is at least 500ms
if err != nil {
t.Errorf("Approve() error = %v, want nil", err)
}
if duration < 500*time.Millisecond {
t.Errorf("Sleep duration = %v, want at least 500ms", duration)
}
}

func Test_reviewer_Comment(t *testing.T) {
ctx := context.Background()

Expand Down