MCPcopy Index your code
hub / github.com/apache/devlake / getStringField

Function getStringField

backend/plugins/customize/service/service.go:299–318  ·  view source on GitHub ↗

getStringField extracts a string field from a record map. If required is true, it returns an error if the field is missing, nil, empty, or not a string. If required is false, it returns an empty string without error if the field is missing or nil, but returns an error if the field exists and is not

(record map[string]interface{}, fieldName string, required bool)

Source from the content-addressed store, hash-verified

297// If required is false, it returns an empty string without error if the field is missing or nil,
298// but returns an error if the field exists and is not a string.
299func getStringField(record map[string]interface{}, fieldName string, required bool) (string, errors.Error) {
300 value, ok := record[fieldName]
301 if !ok || value == nil {
302 if required {
303 return "", errors.Default.New(fmt.Sprintf("record without required field %s", fieldName))
304 }
305 return "", nil // Field missing or nil, but not required
306 }
307
308 strValue, ok := value.(string)
309 if !ok {
310 return "", errors.Default.New(fmt.Sprintf("%s is not a string", fieldName))
311 }
312
313 if required && strValue == "" {
314 return "", errors.Default.New(fmt.Sprintf("invalid or empty required field %s", fieldName))
315 }
316
317 return strValue, nil
318}
319
320// issueHandlerFactory returns a handler that save record into `issues`, `board_issues` and `issue_labels` table
321func (s *Service) issueHandlerFactory(boardId string, incremental bool) func(record map[string]interface{}) errors.Error {

Callers 8

TestGetStringFieldFunction · 0.70
issueHandlerFactoryMethod · 0.70
qaApiHandlerMethod · 0.70
qaTestCaseHandlerMethod · 0.70
sprintHandlerMethod · 0.70
issueChangelogHandlerMethod · 0.70
issueWorklogHandlerMethod · 0.70

Calls 1

NewMethod · 0.65

Tested by 1

TestGetStringFieldFunction · 0.56