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

Function convertExpiresIntegersToDayStrings

pkg/cli/codemod_expires_integer.go:66–105  ·  view source on GitHub ↗

convertExpiresIntegersToDayStrings converts integer expires values to day strings within safe-outputs blocks. Only affects expires lines nested inside a safe-outputs block.

(lines []string)

Source from the content-addressed store, hash-verified

64// convertExpiresIntegersToDayStrings converts integer expires values to day strings within safe-outputs blocks.
65// Only affects expires lines nested inside a safe-outputs block.
66func convertExpiresIntegersToDayStrings(lines []string) ([]string, bool) {
67 var result []string
68 var modified bool
69 var inSafeOutputsBlock bool
70 var safeOutputsIndent string
71
72 for i, line := range lines {
73 trimmedLine := strings.TrimSpace(line)
74
75 // Track if we're in the safe-outputs block
76 if strings.HasPrefix(trimmedLine, "safe-outputs:") {
77 inSafeOutputsBlock = true
78 safeOutputsIndent = getIndentation(line)
79 result = append(result, line)
80 continue
81 }
82
83 // Check if we've left the safe-outputs block
84 if inSafeOutputsBlock && len(trimmedLine) > 0 && !strings.HasPrefix(trimmedLine, "#") {
85 if hasExitedBlock(line, safeOutputsIndent) {
86 inSafeOutputsBlock = false
87 }
88 }
89
90 // Convert integer expires to day string if inside safe-outputs block
91 if inSafeOutputsBlock && strings.HasPrefix(trimmedLine, "expires:") {
92 newLine, converted := convertExpiresIntegerLineToDayString(line)
93 if converted {
94 result = append(result, newLine)
95 modified = true
96 expiresIntegerCodemodLog.Printf("Converted integer expires to day string on line %d", i+1)
97 continue
98 }
99 }
100
101 result = append(result, line)
102 }
103
104 return result, modified
105}
106
107// convertExpiresIntegerLineToDayString converts an expires line with an integer value to use a day string.
108// For example: " expires: 7" -> " expires: 7d"

Callers

nothing calls this directly

Calls 4

getIndentationFunction · 0.85
hasExitedBlockFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected