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

Method parse

pkg/workflow/permissions_parser.go:35–154  ·  view source on GitHub ↗

parse parses the permissions YAML and populates the internal structures

()

Source from the content-addressed store, hash-verified

33
34// parse parses the permissions YAML and populates the internal structures
35func (p *PermissionsParser) parse() {
36 if p.rawPermissions == "" {
37 permissionsParserLog.Print("No permissions to parse")
38 return
39 }
40
41 permissionsParserLog.Printf("Parsing permissions YAML: length=%d", len(p.rawPermissions))
42
43 // Remove the "permissions:" prefix if present and get just the YAML content
44 yamlContent := strings.TrimSpace(p.rawPermissions)
45 if strings.HasPrefix(yamlContent, "permissions:") {
46 // Extract everything after "permissions:"
47 lines := strings.Split(yamlContent, "\n")
48 if len(lines) > 1 {
49 // Get the lines after the first, and normalize indentation
50 contentLines := lines[1:]
51 var normalizedLines []string
52
53 // Find the common indentation to remove
54 minIndent := -1
55 for _, line := range contentLines {
56 if strings.TrimSpace(line) == "" {
57 continue // Skip empty lines
58 }
59 indent := 0
60 for _, r := range line {
61 if r == ' ' || r == '\t' {
62 indent++
63 } else {
64 break
65 }
66 }
67 if minIndent == -1 || indent < minIndent {
68 minIndent = indent
69 }
70 }
71
72 // Remove common indentation from all lines
73 if minIndent > 0 {
74 for _, line := range contentLines {
75 if strings.TrimSpace(line) == "" {
76 normalizedLines = append(normalizedLines, "")
77 } else if len(line) > minIndent {
78 normalizedLines = append(normalizedLines, line[minIndent:])
79 } else {
80 normalizedLines = append(normalizedLines, line)
81 }
82 }
83 } else {
84 normalizedLines = contentLines
85 }
86
87 yamlContent = strings.Join(normalizedLines, "\n")
88 } else {
89 // Single line format like "permissions: read-all"
90 parts := strings.SplitN(lines[0], ":", 2)
91 if len(parts) == 2 {
92 yamlContent = strings.TrimSpace(parts[1])

Callers 1

NewPermissionsParserFunction · 0.95

Calls 2

PrintMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected