Files
archie/internal/domain/workflow/test_run.go
T

67 lines
2.2 KiB
Go

package workflow
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/events"
)
// SuppressForgeWrites makes tc skip every forge and push write, recording
// each as a forge_suppressed event on the step that attempted it. A test run
// uses it so an operator's draft cannot touch a repository.
func SuppressForgeWrites(tc *TaskContext) {
tc.Forge = suppressedForge{Forger: tc.Forge, tc: tc}
tc.Trees = suppressedTrees{Trees: tc.Trees, tc: tc}
}
// suppress records one skipped write.
func (tc *TaskContext) suppress(action string) {
tc.Emit(events.KindForgeSuppressed, tc.Stage, action, nil)
}
type suppressedForge struct {
Forger
tc *TaskContext
}
func (f suppressedForge) CloseIssue(_ context.Context, owner, repo string, number int, _ string) error {
f.tc.suppress(fmt.Sprintf("Would close issue %s/%s#%d", owner, repo, number))
return nil
}
func (f suppressedForge) CreatePR(_ context.Context, owner, repo, title, head, base, _ string) (int, error) {
f.tc.suppress(fmt.Sprintf("Would open PR %q in %s/%s from %s into %s", title, owner, repo, head, base))
return 0, nil
}
func (f suppressedForge) LinkBranch(_ context.Context, owner, repo string, number int, branch string) error {
f.tc.suppress(fmt.Sprintf("Would link %s to %s/%s#%d", branch, owner, repo, number))
return nil
}
func (f suppressedForge) CreateReviewComments(_ context.Context, owner, repo string, number int, _ string, review Review) error {
f.tc.suppress(fmt.Sprintf("Would post a %s review with %d comments on %s/%s#%d", review.Event, len(review.Comments), owner, repo, number))
return nil
}
func (f suppressedForge) Comment(_ context.Context, owner, repo string, number int, body string) (int64, error) {
f.tc.suppress(fmt.Sprintf("Would comment on %s/%s#%d: %s", owner, repo, number, body))
return 0, nil
}
func (f suppressedForge) ReplyToReview(_ context.Context, owner, repo string, number int, _ int64, body string) error {
f.tc.suppress(fmt.Sprintf("Would reply to a review on %s/%s#%d: %s", owner, repo, number, body))
return nil
}
type suppressedTrees struct {
Trees
tc *TaskContext
}
func (t suppressedTrees) Push(_ context.Context, _, branch string) error {
t.tc.suppress(fmt.Sprintf("Would push branch %s", branch))
return nil
}