MCPcopy Create free account
hub / github.com/cli/cli / serializeProjectWithItems

Function serializeProjectWithItems

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

serialize creates a map from field to field values

(project *Project)

Source from the content-addressed store, hash-verified

1808
1809// serialize creates a map from field to field values
1810func serializeProjectWithItems(project *Project) []map[string]interface{} {
1811 fields := make(map[string]string)
1812
1813 // make a map of fields by ID
1814 for _, f := range project.Fields.Nodes {
1815 fields[f.ID()] = camelCase(f.Name())
1816 }
1817 itemsSlice := make([]map[string]interface{}, 0)
1818
1819 // for each value, look up the name by ID
1820 // and set the value to the field value
1821 for _, i := range project.Items.Nodes {
1822 o := make(map[string]interface{})
1823 o["id"] = i.Id
1824 if projectItem := i.DetailedItem(); projectItem != nil {
1825 o["content"] = projectItem.ExportData(nil)
1826 } else {
1827 o["content"] = nil
1828 }
1829 for _, v := range i.FieldValues.Nodes {
1830 id := v.ID()
1831 value := projectFieldValueData(v)
1832
1833 o[fields[id]] = value
1834 }
1835 itemsSlice = append(itemsSlice, o)
1836 }
1837 return itemsSlice
1838}
1839
1840// camelCase converts a string to camelCase, which is useful for turning Go field names to JSON keys.
1841func 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