-
Notifications
You must be signed in to change notification settings - Fork 295
refactor: implement semantic function clustering improvements across pkg/ #19926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/logger" | ||
| ) | ||
|
|
||
| var permissionsReadCodemodLog = logger.New("cli:codemod_permissions_read") | ||
|
|
||
| // getPermissionsReadCodemod creates a codemod for converting invalid "read" and "write" shorthands | ||
| func getPermissionsReadCodemod() Codemod { | ||
| return Codemod{ | ||
| ID: "permissions-read-to-read-all", | ||
| Name: "Convert invalid permissions shorthand", | ||
| Description: "Converts 'permissions: read' to 'permissions: read-all' and 'permissions: write' to 'permissions: write-all' as per GitHub Actions spec", | ||
| IntroducedIn: "0.5.0", | ||
| Apply: func(content string, frontmatter map[string]any) (string, bool, error) { | ||
| // Check if permissions exist | ||
| permissionsValue, hasPermissions := frontmatter["permissions"] | ||
| if !hasPermissions { | ||
| return content, false, nil | ||
| } | ||
|
|
||
| // Check if permissions uses invalid shorthand (read or write) | ||
| hasInvalidShorthand := false | ||
| if strValue, ok := permissionsValue.(string); ok { | ||
| if strValue == "read" || strValue == "write" { | ||
| hasInvalidShorthand = true | ||
| } | ||
| } | ||
|
|
||
| if !hasInvalidShorthand { | ||
| return content, false, nil | ||
| } | ||
|
|
||
| newContent, applied, err := applyFrontmatterLineTransform(content, func(lines []string) ([]string, bool) { | ||
| var modified bool | ||
| result := make([]string, len(lines)) | ||
| for i, line := range lines { | ||
| trimmedLine := strings.TrimSpace(line) | ||
|
|
||
| // Check for permissions line with shorthand | ||
| if strings.HasPrefix(trimmedLine, "permissions:") { | ||
| // Handle shorthand on same line: "permissions: read" or "permissions: write" | ||
| if strings.Contains(trimmedLine, ": read") && !strings.Contains(trimmedLine, "read-all") && !strings.Contains(trimmedLine, ": read\n") { | ||
| // Make sure it's "permissions: read" and not "contents: read" | ||
| if strings.TrimSpace(strings.Split(line, ":")[0]) == "permissions" { | ||
| result[i] = strings.Replace(line, ": read", ": read-all", 1) | ||
| modified = true | ||
| permissionsReadCodemodLog.Printf("Replaced 'permissions: read' with 'permissions: read-all' on line %d", i+1) | ||
| continue | ||
| } | ||
| } else if strings.Contains(trimmedLine, ": write") && !strings.Contains(trimmedLine, "write-all") { | ||
| // Make sure it's "permissions: write" and not "contents: write" | ||
| if strings.TrimSpace(strings.Split(line, ":")[0]) == "permissions" { | ||
| result[i] = strings.Replace(line, ": write", ": write-all", 1) | ||
| modified = true | ||
| permissionsReadCodemodLog.Printf("Replaced 'permissions: write' with 'permissions: write-all' on line %d", i+1) | ||
| continue | ||
| } | ||
| } | ||
| } | ||
|
|
||
| result[i] = line | ||
| } | ||
| return result, modified | ||
| }) | ||
| if applied { | ||
| permissionsReadCodemodLog.Print("Applied permissions read/write to read-all/write-all migration") | ||
| } | ||
| return newContent, applied, err | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Package console provides terminal UI components and formatting utilities for | ||
| // the gh-aw CLI. | ||
| // | ||
| // # Naming Convention: Format* vs Render* | ||
| // | ||
| // Functions in this package follow a consistent naming convention: | ||
| // | ||
| // - Format* functions return a formatted string for a single item or message. | ||
| // They are pure string transformations with no side effects. | ||
| // Examples: FormatSuccessMessage, FormatErrorMessage, FormatFileSize, | ||
| // FormatCommandMessage, FormatProgressMessage. | ||
| // | ||
| // - Render* functions produce multi-element or structured output (tables, boxes, | ||
| // trees, structs). They may return strings, slices of strings, or write | ||
| // directly to output. They are used when the output requires layout or | ||
| // structural composition. | ||
| // Examples: RenderTable, RenderStruct, RenderTitleBox, RenderErrorBox, | ||
| // RenderInfoSection, RenderTree, RenderComposedSections. | ||
| // | ||
| // # Output Routing | ||
| // | ||
| // All diagnostic output (messages, warnings, errors) should be written to stderr. | ||
| // Structured data output (JSON, hashes, graphs) should be written to stdout. | ||
| // Use fmt.Fprintln(os.Stderr, ...) with the Format* helpers for diagnostic output. | ||
| package console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trimmedLineis produced bystrings.TrimSpace(line), so it will never contain a newline. The!strings.Contains(trimmedLine, ": read\n")check is therefore redundant/unreachable and can be removed to simplify the condition.