| OLD | NEW |
| (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 { |
| 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 for _, c := range i.Components { |
| 61 if c == "" { |
| 62 return fmt.Errorf("empty component") |
| 63 } |
| 64 } |
| 65 |
| 66 for _, label := range i.Labels { |
| 67 if label == "" { |
| 68 return fmt.Errorf("empty label") |
| 69 } |
| 70 } |
| 71 |
| 72 if i.Owner != nil { |
| 73 if err := i.Owner.Validate(); err != nil { |
| 74 return err |
| 75 } |
| 76 } |
| 77 |
| 78 return nil |
| 79 } |
| 80 |
| 81 // Validate checks the message for errors. |
| 82 func (i *InsertIssueRequest) Validate() error { |
| 83 if i.ProjectId == "" { |
| 84 return fmt.Errorf("no projectId") |
| 85 } |
| 86 if err := i.Issue.Validate(); err != nil { |
| 87 return fmt.Errorf("issue: %s", err) |
| 88 } |
| 89 if i.Issue.Id != 0 { |
| 90 return fmt.Errorf("issue: must not have id") |
| 91 } |
| 92 return nil |
| 93 } |
| OLD | NEW |