MCPcopy
hub / github.com/cli/cli / serializeProjectWithItems

Function serializeProjectWithItems

pkg/cmd/project/shared/queries/queries.go:1763–1791  ·  view source on GitHub ↗

serialize creates a map from field to field values

(project *Project)

Source from the content-addressed store, hash-verified

1761
1762// serialize creates a map from field to field values
1763func serializeProjectWithItems(project *Project) []map[string]interface{} {
1764 fields := make(map[string]string)
1765
1766 // make a map of fields by ID
1767 for _, f := range project.Fields.Nodes {
1768 fields[f.ID()] = camelCase(f.Name())
1769 }
1770 itemsSlice := make([]map[string]interface{}, 0)
1771
1772 // for each value, look up the name by ID
1773 // and set the value to the field value
1774 for _, i := range project.Items.Nodes {
1775 o := make(map[string]interface{})
1776 o["id"] = i.Id
1777 if projectItem := i.DetailedItem(); projectItem != nil {
1778 o["content"] = projectItem.ExportData(nil)
1779 } else {
1780 o["content"] = nil
1781 }
1782 for _, v := range i.FieldValues.Nodes {
1783 id := v.ID()
1784 value := projectFieldValueData(v)
1785
1786 o[fields[id]] = value
1787 }
1788 itemsSlice = append(itemsSlice, o)
1789 }
1790 return itemsSlice
1791}
1792
1793// camelCase converts a string to camelCase, which is useful for turning Go field names to JSON keys.
1794func camelCase(s string) string {

Callers 1

DetailedItemsMethod · 0.85

Calls 6

camelCaseFunction · 0.85
projectFieldValueDataFunction · 0.85
DetailedItemMethod · 0.80
IDMethod · 0.65
NameMethod · 0.65
ExportDataMethod · 0.65

Tested by

no test coverage detected