MCPcopy Create free account
hub / github.com/git-bug/git-bug / Validate

Method Validate

entities/identity/version.go:179–218  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

177}
178
179func (v *version) Validate() error {
180 // time must be set after a commit
181 if v.commitHash != "" && v.unixTime == 0 {
182 return fmt.Errorf("unix time not set")
183 }
184
185 if text.Empty(v.name) && text.Empty(v.login) {
186 return fmt.Errorf("either name or login should be set")
187 }
188 if !text.SafeOneLine(v.name) {
189 return fmt.Errorf("name has unsafe characters")
190 }
191
192 if !text.SafeOneLine(v.login) {
193 return fmt.Errorf("login has unsafe characters")
194 }
195
196 if !text.SafeOneLine(v.email) {
197 return fmt.Errorf("email has unsafe characters")
198 }
199
200 if v.avatarURL != "" && !text.ValidUrl(v.avatarURL) {
201 return fmt.Errorf("avatarUrl is not a valid URL")
202 }
203
204 if len(v.nonce) > 64 {
205 return fmt.Errorf("nonce is too big")
206 }
207 if len(v.nonce) < 20 {
208 return fmt.Errorf("nonce is too small")
209 }
210
211 for _, k := range v.keys {
212 if err := k.Validate(); err != nil {
213 return errors.Wrap(err, "invalid key")
214 }
215 }
216
217 return nil
218}
219
220// Write will serialize and store the version as a git blob and return
221// its hash

Callers 1

WriteMethod · 0.95

Calls 5

EmptyFunction · 0.92
SafeOneLineFunction · 0.92
ValidUrlFunction · 0.92
ErrorfMethod · 0.80
ValidateMethod · 0.65

Tested by

no test coverage detected