(fields []string)
| 403 | } |
| 404 | |
| 405 | func (issue Issue) ExportData(fields []string) map[string]interface{} { |
| 406 | v := reflect.ValueOf(issue) |
| 407 | data := map[string]interface{}{} |
| 408 | for _, f := range fields { |
| 409 | switch f { |
| 410 | case "assignees": |
| 411 | assignees := make([]interface{}, 0, len(issue.Assignees)) |
| 412 | for _, assignee := range issue.Assignees { |
| 413 | assignees = append(assignees, assignee.ExportData()) |
| 414 | } |
| 415 | data[f] = assignees |
| 416 | case "author": |
| 417 | data[f] = issue.Author.ExportData() |
| 418 | case "isPullRequest": |
| 419 | data[f] = issue.IsPullRequest() |
| 420 | case "labels": |
| 421 | labels := make([]interface{}, 0, len(issue.Labels)) |
| 422 | for _, label := range issue.Labels { |
| 423 | labels = append(labels, map[string]interface{}{ |
| 424 | "color": label.Color, |
| 425 | "description": label.Description, |
| 426 | "id": label.ID, |
| 427 | "name": label.Name, |
| 428 | }) |
| 429 | } |
| 430 | data[f] = labels |
| 431 | case "repository": |
| 432 | comp := strings.Split(issue.RepositoryURL, "/") |
| 433 | name := comp[len(comp)-1] |
| 434 | nameWithOwner := strings.Join(comp[len(comp)-2:], "/") |
| 435 | data[f] = map[string]interface{}{ |
| 436 | "name": name, |
| 437 | "nameWithOwner": nameWithOwner, |
| 438 | } |
| 439 | case "state": |
| 440 | data[f] = issue.State() |
| 441 | default: |
| 442 | sf := fieldByName(v, f) |
| 443 | data[f] = sf.Interface() |
| 444 | } |
| 445 | } |
| 446 | return data |
| 447 | } |
| 448 | |
| 449 | func fieldByName(v reflect.Value, field string) reflect.Value { |
| 450 | return v.FieldByNameFunc(func(s string) bool { |
nothing calls this directly
no test coverage detected