-
Notifications
You must be signed in to change notification settings - Fork 369
refactor: split mixed-concern files identified by semantic function clustering analysis #24101
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
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,28 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/modelcontextprotocol/go-sdk/jsonrpc" | ||
| ) | ||
|
|
||
| // newMCPError creates a jsonrpc.Error with the given code, message, and optional data. | ||
| // The data value is marshaled via mcpErrorData. | ||
| func newMCPError(code int64, msg string, data any) error { | ||
| return &jsonrpc.Error{Code: code, Message: msg, Data: mcpErrorData(data)} | ||
| } | ||
|
|
||
| // mcpErrorData marshals data to JSON for use in jsonrpc.Error.Data field. | ||
| // Returns nil if marshaling fails to avoid errors in error handling. | ||
| func mcpErrorData(v any) json.RawMessage { | ||
| if v == nil { | ||
| return nil | ||
| } | ||
| data, err := json.Marshal(v) | ||
| if err != nil { | ||
| // Log the error but return nil to avoid breaking error handling | ||
| mcpLog.Printf("Failed to marshal error data: %v", err) | ||
| return nil | ||
| } | ||
| return data | ||
| } |
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,47 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/workflow" | ||
| ) | ||
|
|
||
| // getRepository retrieves the current repository name (owner/repo format). | ||
| // Results are cached for 1 hour to avoid repeated queries. | ||
| // Checks GITHUB_REPOSITORY environment variable first, then falls back to gh repo view. | ||
| func getRepository() (string, error) { | ||
| // Check cache first | ||
| if repo, ok := mcpCache.GetRepo(); ok { | ||
| mcpLog.Printf("Using cached repository: %s", repo) | ||
| return repo, nil | ||
| } | ||
|
|
||
| // Try GITHUB_REPOSITORY environment variable first | ||
| repo := os.Getenv("GITHUB_REPOSITORY") | ||
| if repo != "" { | ||
| mcpLog.Printf("Got repository from GITHUB_REPOSITORY: %s", repo) | ||
| mcpCache.SetRepo(repo) | ||
| return repo, nil | ||
| } | ||
|
|
||
| // Fall back to gh repo view | ||
| mcpLog.Print("Querying repository using gh repo view") | ||
| cmd := workflow.ExecGH("repo", "view", "--json", "nameWithOwner", "--jq", ".nameWithOwner") | ||
| output, err := cmd.Output() | ||
| if err != nil { | ||
| mcpLog.Printf("Failed to get repository: %v", err) | ||
| return "", fmt.Errorf("failed to get repository: %w", err) | ||
| } | ||
|
|
||
| repo = strings.TrimSpace(string(output)) | ||
| if repo == "" { | ||
| return "", errors.New("repository not found") | ||
| } | ||
|
|
||
| mcpLog.Printf("Got repository from gh repo view: %s", repo) | ||
| mcpCache.SetRepo(repo) | ||
| return repo, nil | ||
| } |
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,4 @@ | ||
| package cli | ||
|
|
||
| // boolPtr returns a pointer to the given bool value, used for optional *bool fields. | ||
| func boolPtr(b bool) *bool { return &b } |
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.
New helpers
FormatDurationMsandFormatDurationNsare added butformat_test.gocurrently only coversFormatDuration. Since these helpers are now shared by multiple packages, please add unit tests covering representative and edge cases (e.g., <1s ms formatting, minute+ formatting, ns<=0 returning "—", and sub-second ns rounding behavior).