oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package chat
2
3import (
4 "slices"
5
6 "amadan.net/oficina/equipo/internal/wire"
7)
8
9// recheckMac runs again the checks of the person's tasks that wait for a
10// Mac, when runner (just enrolled, or back online) fits them: Ready to
11// merge, approved, their newest checks not run because no runner could
12// (needs_macos), the branch still at that candidate and no merge of it.
13// The checks are placed afresh on that exact candidate through the usual
14// placement (nextStep), so a pass merges under the slice 4c policy
15// (advance grants it) and a failure takes the fix round. Once per
16// candidate per runner: a reconnect of the same runner runs nothing. A
17// Mac whose sandbox is not proven runs nothing again (macsandbox.go);
18// its first hello saying it is proven looks again.
19func (t *txn) recheckMac(person, runner string) error {
20 rs, err := t.runners(person)
21 if err != nil {
22 return err
23 }
24 primary, err := t.s.authority.PrimaryRunner(t.db, person)
25 if err != nil {
26 return err
27 }
28 var mac *runnerInfo
29 relay := false
30 for i := range rs {
31 if rs[i].ID == runner && rs[i].Online && slices.Contains(rs[i].tags(), wire.TagMacOS) {
32 mac = &rs[i]
33 }
34 if rs[i].ID == primary && rs[i].Protocol >= wire.Protocol2 {
35 relay = true
36 }
37 }
38 if mac == nil || !relay && runner != primary || !mac.sandboxProven() {
39 // Not a Mac, placement would end on the primary again, or the
40 // Mac's sandbox is not proven.
41 return nil
42 }
43 var tasks []taskRecord
44 if err := t.db.Where("creator = ? AND stage = ? AND cancel_requested = ?", person, wire.StageReadyToMerge, false).Order("created_at, id").Find(&tasks).Error; err != nil {
45 return err
46 }
47 for i := range tasks {
48 k := &tasks[i]
49 steps, err := t.steps(k.ID)
50 if err != nil {
51 return err
52 }
53 p := progressFor(*k, steps)
54 c := p.checks
55 if p.moved || p.merge != nil || p.eng == nil || p.eng.Person != person || c == nil || c.State != wire.StepDone || c.Checks != wire.ChecksCannotRun || c.Reason != "needs_macos" {
56 continue
57 }
58 if _, _, verdict, _ := p.judged(); verdict != wire.VerdictApprove {
59 continue
60 }
61 needs := decodeList(c.Needs)
62 if len(needs) == 0 {
63 if needs, err = t.checksNeeds(*k, *c); err != nil {
64 return err
65 }
66 }
67 if !slices.Contains(needs, wire.TagMacOS) || !mac.fits(needs, decodeList(c.RefusedBy)) {
68 continue
69 }
70 var ran int64
71 if err := t.db.Model(&stepRecord{}).Where("task_id = ? AND specialist = ? AND candidate_sha = ? AND recheck_by = ?", k.ID, wire.SpecialistChecks, p.candidate, runner).Count(&ran).Error; err != nil {
72 return err
73 }
74 if ran > 0 {
75 continue
76 }
77 // The card asked whether to merge without checks; they run now. Merge
78 // authority's ruling: the pass may merge on its own only when the
79 // card asked solely because checks could not run, or the person chose
80 // Wait for a Mac; then the card goes and the outcome decides afresh.
81 // For any other reason the SHA stays asked and the pass only
82 // re-decides the card's words (autoMerge).
83 may, err := t.recheckMayMerge(*k, p)
84 if err != nil {
85 return err
86 }
87 if may {
88 if err := t.withdrawMergeCards(*k); err != nil {
89 return err
90 }
91 k.MergeAsked = ""
92 if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("merge_asked", "").Error; err != nil {
93 return err
94 }
95 }
96 s := stepRecord{Specialist: wire.SpecialistChecks, Person: p.eng.Person, Round: p.eng.Round, BaseSHA: k.BaseSHA, CandidateSHA: p.candidate, RecheckBy: runner}
97 k.Stage = wire.StageInReview
98 if err := t.nextStep(k, steps, s); err != nil {
99 return err
100 }
101 }
102 return nil
103}
104