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

Function serializeProjectWithItems

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

serialize creates a map from field to field values

(project *Project)

Source from the content-addressed store, hash-verified

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