MCPcopy Create free account
hub / github.com/github/gh-aw / buildNormalizedSortedJSON

Function buildNormalizedSortedJSON

pkg/workflow/safe_outputs_config_helpers.go:20–39  ·  view source on GitHub ↗
(names []string, valueFn func(string) string)

Source from the content-addressed store, hash-verified

18var safeOutputsConfigGenLog = logger.New("workflow:safe_outputs_config_generation_helpers")
19
20func buildNormalizedSortedJSON(names []string, valueFn func(string) string) (string, error) {
21 values := make(map[string]string, len(names))
22 for _, name := range names {
23 normalizedName := stringutil.NormalizeSafeOutputIdentifier(name)
24 values[normalizedName] = valueFn(normalizedName)
25 }
26
27 keys := sliceutil.SortedKeys(values)
28
29 ordered := make(map[string]string, len(keys))
30 for _, k := range keys {
31 ordered[k] = values[k]
32 }
33
34 jsonBytes, err := json.Marshal(ordered)
35 if err != nil {
36 return "", err
37 }
38 return string(jsonBytes), nil
39}
40
41// buildCustomSafeOutputJobsJSON builds a JSON mapping of custom safe output job names to empty
42// strings, for use in the GH_AW_SAFE_OUTPUT_JOBS env var of the handler manager step.

Callers 2

Calls 2

SortedKeysFunction · 0.92

Tested by

no test coverage detected