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 "amadan.net/oficina/equipo/internal/copydesk"
5 "amadan.net/oficina/equipo/internal/wire"
6 "encoding/json"
7 "errors"
8 "gorm.io/gorm"
9)
10
11func (t *txn) copyRecorded(s stepRecord) (bool, error) {
12 if s.State != wire.StepDone || !s.Pushed {
13 return false, nil
14 }
15 var c wire.CopyResult
16 if json.Unmarshal([]byte(s.CopyResult), &c) != nil || c.Owner != s.CopyOwner || c.Delegation != s.CopyRevision || c.Extraction.Version != 1 {
17 return false, nil
18 }
19 words, err := copydesk.ValidateReview(c.Extraction.Strings, c.Review)
20 if err != nil {
21 return false, nil
22 }
23 if c.Suggestions {
24 return true, nil
25 }
26 var rows []copyReviewRecord
27 if err := t.db.Where("step_id = ? AND attempt = ?", s.ID, s.Attempt).Find(&rows).Error; err != nil {
28 return false, err
29 }
30 records := []copydesk.Record{}
31 for _, r := range rows {
32 records = append(records, copydesk.Record{Key: r.Key, Hash: r.Hash, Candidate: r.Candidate, Owner: r.Owner, Revision: r.Delegation})
33 }
34 for _, w := range words {
35 if w.Action != "accept" || !copydesk.Accepted(copydesk.Literal{Key: w.Key, Text: w.Text}, s.CandidateSHA, copydesk.Delegation{Owner: s.CopyOwner, Revision: s.CopyRevision}, records) {
36 return false, nil
37 }
38 }
39 return true, nil
40}
41func (t *txn) copyReady(k taskRecord, candidate string) (bool, error) {
42 d, err := t.copyDelegation(k.ProjectID)
43 if err != nil {
44 return false, err
45 }
46 if d.Owner == "" {
47 return true, nil
48 }
49 var s stepRecord
50 err = t.db.Where("task_id = ? AND specialist = ?", k.ID, wire.SpecialistCopy).Order("idx DESC").First(&s).Error
51 if errors.Is(err, gorm.ErrRecordNotFound) {
52 return false, nil
53 }
54 if err != nil {
55 return false, err
56 }
57 if s.CandidateSHA != candidate || s.CopyOwner != d.Owner || s.CopyRevision != d.Revision {
58 return false, nil
59 }
60 if s.State == wire.StepDone && s.Note == "copy-skip" {
61 return true, nil
62 }
63 return t.copyRecorded(s)
64}
65