MCPcopy Index your code
hub / github.com/git-bug/git-bug / Validate

Method Validate

entity/dag/operation.go:168–204  ·  view source on GitHub ↗

Validate check the OpBase for errors

(op Operation, opType OperationType)

Source from the content-addressed store, hash-verified

166
167// Validate check the OpBase for errors
168func (base *OpBase) Validate(op Operation, opType OperationType) error {
169 if base.OperationType == 0 {
170 return fmt.Errorf("operation type unset")
171 }
172 if base.OperationType != opType {
173 return fmt.Errorf("incorrect operation type (expected: %v, actual: %v)", opType, base.OperationType)
174 }
175
176 if op.Time().Unix() == 0 {
177 return fmt.Errorf("time not set")
178 }
179
180 if base.author == nil {
181 return fmt.Errorf("author not set")
182 }
183
184 if err := op.Author().Validate(); err != nil {
185 return errors.Wrap(err, "author")
186 }
187
188 if op, ok := op.(OperationWithFiles); ok {
189 for _, hash := range op.GetFiles() {
190 if !hash.IsValid() {
191 return fmt.Errorf("file with invalid hash %v", hash)
192 }
193 }
194 }
195
196 if len(base.Nonce) > 64 {
197 return fmt.Errorf("nonce is too big")
198 }
199 if len(base.Nonce) < 20 {
200 return fmt.Errorf("nonce is too small")
201 }
202
203 return nil
204}
205
206// IsAuthored is a sign post method for gqlgen
207func (base *OpBase) IsAuthored() {}

Callers

nothing calls this directly

Calls 6

ErrorfMethod · 0.80
IsValidMethod · 0.80
TimeMethod · 0.65
ValidateMethod · 0.65
AuthorMethod · 0.65
GetFilesMethod · 0.65

Tested by

no test coverage detected