fix(taskactions): abandon leaves the forge issue open
This commit is contained in:
1 parent
04b9b9b3e3
commit
db7d9c790b
7 files changed
+41
-10
No files matched your search
@@ -251,12 +251,14 @@ func (s Service) applyStop(ctx context.Context, task *Task, actor Actor, o outco
|
||||
}
|
||||
|
||||
func (s Service) applyCancelOrAbandon(ctx context.Context, task *Task, action taskstate.Action, actor Actor, o outcome) (outcome, error) {
|
||||
from, kind, verb := "queued", events.KindTaskCancelled, "cancelled"
|
||||
if action == taskstate.ActionAbandon {
|
||||
from, kind, verb = "parked", events.KindTaskAbandoned, "abandoned"
|
||||
// Abandoning ends archie's run, not the issue: no verb, so the issue
|
||||
// stays open for a human.
|
||||
o.event.Kind, o.event.Detail = events.KindTaskAbandoned, actor.describe("abandoned")
|
||||
return o, s.Store.Transition(ctx, task.ID, "parked", "closed_wont_do", o.event.Detail)
|
||||
}
|
||||
o.event.Kind, o.event.Detail, o.verb = kind, actor.describe(verb), verb
|
||||
return o, s.Store.Transition(ctx, task.ID, from, "closed_wont_do", o.event.Detail)
|
||||
o.event.Kind, o.event.Detail, o.verb = events.KindTaskCancelled, actor.describe("cancelled"), "cancelled"
|
||||
return o, s.Store.Transition(ctx, task.ID, "queued", "closed_wont_do", o.event.Detail)
|
||||
}
|
||||
|
||||
func (s Service) applyArchive(ctx context.Context, task *Task, actor Actor, o outcome) (outcome, error) {
|
||||
|
||||
@@ -209,3 +209,32 @@ func TestActorForCarriesTheKindAndLeavesTheActionUnattributedWithoutAPrincipal(t
|
||||
t.Fatal("the zero Actor reported itself as a human")
|
||||
}
|
||||
}
|
||||
|
||||
// TestOnlyRejectAndCancelCloseTheIssue: abandoning is archie giving up on its
|
||||
// own run, not a verdict on the issue, so the issue stays open for a human.
|
||||
func TestOnlyRejectAndCancelCloseTheIssue(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
action taskstate.Action
|
||||
status string
|
||||
closes bool
|
||||
}{
|
||||
{taskstate.ActionReject, "waiting_human", true},
|
||||
{taskstate.ActionCancel, "queued", true},
|
||||
{taskstate.ActionAbandon, "parked", false},
|
||||
} {
|
||||
t.Run(string(tc.action), func(t *testing.T) {
|
||||
store := &fakeStore{task: &Task{ID: 7, Owner: "acme", Repo: "widgets", Status: tc.status, ForgeBacked: true}}
|
||||
closed := false
|
||||
service := Service{Store: store, CloseIssue: func(context.Context, string, string, int, string) error {
|
||||
closed = true
|
||||
return nil
|
||||
}}
|
||||
if err := service.Apply(context.Background(), nil, agentActor(), 7, tc.action); err != nil {
|
||||
t.Fatalf("Apply(%s) error = %v", tc.action, err)
|
||||
}
|
||||
if closed != tc.closes {
|
||||
t.Fatalf("Apply(%s) closed the issue = %v, want %v", tc.action, closed, tc.closes)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func ActionCatalog() []ActionMeta {
|
||||
{ID: string(ActionApprove), Label: "Approve", Kind: "primary"},
|
||||
{ID: string(ActionReject), Label: "Reject", Kind: "quiet", Confirm: `Reject "{title}"? This closes the forge issue.`},
|
||||
{ID: string(ActionRetry), Label: "Retry", Kind: "primary"},
|
||||
{ID: string(ActionAbandon), Label: "Abandon", Kind: "quiet", Confirm: `Abandon "{title}"? This closes the forge issue.`},
|
||||
{ID: string(ActionAbandon), Label: "Abandon", Kind: "quiet", Confirm: `Abandon "{title}"? Archie stops working on it; the forge issue stays open.`},
|
||||
{ID: string(ActionArchive), Label: "Archive", Kind: "quiet", Confirm: `Archive the local record for "{title}"?`},
|
||||
{ID: string(ActionOpenPR), Label: "Open PR", Kind: "link"},
|
||||
{ID: string(ActionOpenIssue), Label: "Open issue", Kind: "link"},
|
||||
|
||||
@@ -601,7 +601,7 @@ func TestLifecycleSpecificTaskActions(t *testing.T) {
|
||||
{name: "cancel queued", from: workflow.StatusQueued, action: "cancel", want: workflow.StatusClosedWontDo, closesIssue: true},
|
||||
{name: "stop running", from: workflow.StatusRunning, action: "stop", want: workflow.StatusParked, stopperResult: true},
|
||||
{name: "park stale running row", from: workflow.StatusRunning, action: "stop", want: workflow.StatusParked},
|
||||
{name: "abandon parked", from: workflow.StatusParked, action: "abandon", want: workflow.StatusClosedWontDo, closesIssue: true},
|
||||
{name: "abandon parked", from: workflow.StatusParked, action: "abandon", want: workflow.StatusClosedWontDo, closesIssue: false},
|
||||
// Reject is available from every non-terminal state and always lands in
|
||||
// the terminal Declined state, closing the forge issue.
|
||||
{name: "reject queued", from: workflow.StatusQueued, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true},
|
||||
|
||||
Reference in new issue
Block a user