Skip to content

Commit b84f213

Browse files
authored
fix: support -uses along with uses (#5)
fix: handles actions that might be -uses
1 parent a51c0e5 commit b84f213

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

.mise.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

cmd/root.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,16 @@ var rootCmd = &cobra.Command{
118118
updated, err := UpdateWorkflowActionSHAs(ctx, client, filePath)
119119
if err != nil {
120120
// Log errors related to processing a single file but continue to the next.
121-
log.Printf("❌ Failed to process %s: %v", filePath, err)
121+
log.Printf("❌ Failed to process %s: %v", filePath, err)
122122
} else if updated > 0 {
123123
// Log success if updates were made.
124-
log.Printf("✅ Updated %d action(s) in %s", updated, filePath)
124+
log.Printf("✅ Updated %d action(s) in %s", updated, filePath)
125125
totalUpdates += updated
126126
} else {
127127
// Log if no updates were needed for the file.
128-
log.Printf("ℹ️ No actions needed updating in %s", filePath)
128+
log.Printf("ℹ️ No actions needed updating in %s", filePath)
129129
}
130130
}
131-
132131
// Final summary of total updates made across all files.
133132
log.Printf("Finished processing. Total actions updated across all files: %d", totalUpdates)
134133
},
@@ -265,7 +264,7 @@ func handleUsesValue(
265264
}
266265

267266
// If the reference is not a SHA, attempt to resolve it to a full SHA using the GitHub API.
268-
log.Printf("🔍 Resolving SHA for: %s/%s@%s (line %d)", action.Name,
267+
log.Printf("🔍 Resolving SHA for: %s/%s@%s (line %d)", action.Name,
269268
action.Repo,
270269
action.Ref,
271270
lineNum,
@@ -441,11 +440,19 @@ func applyUpdatesToLines(originalContent string, updates map[int]string) (string
441440
// Trim whitespace from the beginning of the line to check if it starts with 'uses:'.
442441
trimmedLine := strings.TrimSpace(line)
443442
// Verify that the line actually starts with 'uses:' (case-sensitive as per YAML spec).
444-
if strings.HasPrefix(trimmedLine, "uses:") {
443+
if strings.HasPrefix(trimmedLine, "uses:") ||
444+
strings.HasPrefix(trimmedLine, "- uses:") {
445445
// Identify the leading indentation (spaces and tabs) of the original line.
446446
indentation := line[:len(line)-len(strings.TrimLeft(line, " \t"))]
447-
// Construct the new line by adding the original indentation, "uses: ", and the new value.
448-
newLine := indentation + "uses: " + newUsesValue
447+
// Construct the new line, preserving the dash if it exists
448+
newLine := ""
449+
if strings.HasPrefix(trimmedLine, "- uses:") {
450+
// If it has the dash prefix, maintain it in the updated line
451+
newLine = indentation + "- uses: " + newUsesValue
452+
} else {
453+
// Regular "uses:" line without dash
454+
newLine = indentation + "uses: " + newUsesValue
455+
}
449456
// Write the new line to the output buffer.
450457
output.WriteString(newLine)
451458
} else {

githubclient/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewClient(ctx context.Context) (*github.Client, error) {
117117
// Create the final HTTP client using the wrapped authenticated transport.
118118
httpClient = &http.Client{Transport: cachingTransport}
119119
} else {
120-
fmt.Println("⚠️ No GITHUB_TOKEN found, using unauthenticated requests (lower rate limit).")
120+
fmt.Println("⚠️ No GITHUB_TOKEN found, using unauthenticated requests (lower rate limit).")
121121
// If no token is found, use the cache transport directly wrapped in our custom transport.
122122
// Unauthenticated requests have much lower rate limits (60/hour vs 5000/hour).
123123
debugTransport := &CachingTransport{Transport: cacheTransport}

0 commit comments

Comments
 (0)