Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: go/src/infra/monorail/validation.go

Issue 2037143002: Monorail client in Go (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package monorail
6
7 import "fmt"
8
9 // Validate checks the message for errors.
10 func (i *IssueRef) Validate() error {
seanmccullough1 2016/06/03 18:45:33 I see. This could be annoying to do without adding
nodir 2016/06/03 18:56:12 yeah, we use this approach a lot in luci-go.
11 if i == nil {
12 return fmt.Errorf("is nil")
13 }
14 if i.ProjectId == "" {
15 return fmt.Errorf("no projectId")
16 }
17 if i.IssueId == 0 {
18 return fmt.Errorf("no issueId")
19 }
20 return nil
21 }
22
23 // Validate checks the message for errors.
24 func (a *AtomPerson) Validate() error {
25 if a == nil {
26 return fmt.Errorf("is nil")
27 }
28 if a.Name == "" {
29 return fmt.Errorf("no name")
30 }
31 return nil
32 }
33
34 // Validate checks the message for errors.
35 func (i *Issue) Validate() error {
36 if i == nil {
37 return fmt.Errorf("is nil")
38 }
39 if i.Status == "" {
40 return fmt.Errorf("no status")
41 }
42 for _, ref := range i.BlockedOn {
43 if err := ref.Validate(); err != nil {
44 return fmt.Errorf("blockedOn: %s", err)
45 }
46 }
47
48 seen := map[string]struct{}{}
49 for _, cc := range i.Cc {
50 if err := cc.Validate(); err != nil {
51 return fmt.Errorf("cc: %s", err)
52 }
53 // Monorail does not like duplicates in CC list.
54 if _, saw := seen[cc.Name]; saw {
55 return fmt.Errorf("cc: duplicate %s", cc.Name)
56 }
57 seen[cc.Name] = struct{}{}
58 }
59
60 if i.Owner != nil {
61 if err := i.Owner.Validate(); err != nil {
62 return err
63 }
64 }
65
66 return nil
67 }
68
69 // Validate checks the message for errors.
70 func (i *InsertIssueRequest) Validate() error {
71 if i.ProjectId == "" {
72 return fmt.Errorf("no projectId")
73 }
74 if err := i.Issue.Validate(); err != nil {
75 return fmt.Errorf("issue: %s", err)
76 }
77 if i.Issue.Id != 0 {
78 return fmt.Errorf("issue: must not have id")
79 }
80 return nil
81 }
OLDNEW
« go/src/infra/monorail/monorail.proto ('K') | « go/src/infra/monorail/pb.discovery.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698