oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "context"
5 "errors"
6
7 "amadan.net/oficina/equipo/internal/equipo/planning"
8 "amadan.net/oficina/equipo/internal/taskplan"
9 "gorm.io/gorm"
10)
11
12var errPlanApproval = &refusal{copyText("plan.awaiting_approval"), ErrConflict}
13
14var errPlanSelectionAsk = &refusal{copyText("connections.ask"), ErrUnavailable}
15var errPlanSecondFamily = &refusal{copyText("connections.second_family"), ErrUnavailable}
16
17func selectionWaitCode(err error) string {
18 if errors.Is(err, errPlanApproval) {
19 return "plan.awaiting_approval"
20 }
21 if errors.Is(err, errPlanSelectionAsk) {
22 return "connections.ask"
23 }
24 if errors.Is(err, errPlanSecondFamily) {
25 return "connections.second_family"
26 }
27 return "task.wait.setup"
28}
29
30func (s *Store) SelectPlanStep(ctx context.Context, actor Actor, taskID, stepKey string, m Mutation) (Selection, error) {
31 return s.planSelection(ctx, actor, taskID, stepKey, "", "", false, m)
32}
33func (s *Store) ConfirmPlanSelection(ctx context.Context, actor Actor, taskID, stepKey, connectionID, model string, m Mutation) (Selection, error) {
34 return s.planSelection(ctx, actor, taskID, stepKey, connectionID, model, true, m)
35}
36func (s *Store) planSelection(ctx context.Context, actor Actor, taskID, key, connection, model string, confirm bool, m Mutation) (out Selection, err error) {
37 actor.Address = normalizeAddress(actor.Address)
38 err = s.write(ctx, func(tx *gorm.DB) error {
39 out, err = s.planningAt(tx).Select(actor, taskID, key, connection, model, confirm, m)
40 return err
41 })
42 return
43}
44
45func (s *Store) selectionPolicy() planning.SelectionPolicy {
46 return planning.SelectionPolicy{
47 Select: s.selectStepConnectionConfirmed, Current: s.selectionCurrent, Subscription: subscriptionSelection,
48 ChoiceRevision: func(tx *gorm.DB, person string, project int64) (int64, error) {
49 c, _, err := choiceAt(tx, person, project)
50 return c.Revision, err
51 },
52 SpecialistRevision: func(tx *gorm.DB, key string) (int64, error) {
53 sp, err := specialistAt(tx, key)
54 return sp.Revision, err
55 },
56 Unavailable: ErrUnavailable, Conflict: ErrConflict, SecondFamily: errPlanSecondFamily,
57 }
58}
59func (s *Store) choosePlanSelection(tx *gorm.DB, t Task, p taskplan.Plan, st taskplan.Step, confirm bool) (Selection, error) {
60 return s.selectionPolicy().Choose(tx, t, p, st, confirm)
61}
62func (s *Store) selectPlanConnection(tx *gorm.DB, t Task, st taskplan.Step, excluded, runner string, availability bool) (Selection, error) {
63 return s.selectionPolicy().ForStep(tx, t, st, excluded, runner, availability)
64}
65