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

Function convertExpiresIntegerLineToDayString

pkg/cli/codemod_expires_integer.go:111–134  ·  view source on GitHub ↗

convertExpiresIntegerLineToDayString converts an expires line with an integer value to use a day string. For example: " expires: 7" -> " expires: 7d" Lines that already use a string format (e.g., "expires: 7d", "expires: 24h") are left unchanged. Returns the (possibly converted) line and wheth

(line string)

Source from the content-addressed store, hash-verified

109// Lines that already use a string format (e.g., "expires: 7d", "expires: 24h") are left unchanged.
110// Returns the (possibly converted) line and whether a conversion was made.
111func convertExpiresIntegerLineToDayString(line string) (string, bool) {
112 indent := getIndentation(line)
113 trimmedLine := strings.TrimSpace(line)
114
115 // Extract the value part after "expires:"
116 valuePart := strings.TrimPrefix(trimmedLine, "expires:")
117
118 // Match an integer value optionally followed by whitespace and a comment
119 matches := expiresIntegerValuePattern.FindStringSubmatch(valuePart)
120 if matches == nil {
121 // Not an integer value (already a string like "7d" or "false")
122 return line, false
123 }
124
125 intValue := matches[2] // the digits
126 trailingWS := matches[3] // whitespace between value and comment
127 comment := matches[4] // optional trailing comment
128
129 // Build the new line, preserving any trailing comment
130 if comment != "" {
131 return fmt.Sprintf("%sexpires: %sd%s%s", indent, intValue, trailingWS, comment), true
132 }
133 return fmt.Sprintf("%sexpires: %sd", indent, intValue), true
134}

Calls 1

getIndentationFunction · 0.85

Tested by 1