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

Function serializeProjectWithItems

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

serialize creates a map from field to field values

(project *Project)

Source from the content-addressed store, hash-verified

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