Skip to content

Conversation

@almaleksia
Copy link
Contributor

Sometimes path is passed with leading slash. We can auto-correct to make sure we do not get unnecessary tool call failures.

@almaleksia almaleksia requested a review from a team as a code owner December 10, 2025 17:00
Copilot AI review requested due to automatic review settings December 10, 2025 17:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds auto-correction for path parameters passed with leading slashes to the create_or_update_file tool to prevent unnecessary tool call failures.

Key Changes:

  • Trim leading slash from path parameter in CreateOrUpdateFile function using strings.TrimPrefix(path, "/")

return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

path = strings.TrimPrefix(path, "/")
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetFileContents function also accepts a path parameter that is passed directly to client.Repositories.GetContents() and rawClient.GetRawContent() at lines 619 and 639. For consistency and to prevent similar failures, consider adding path = strings.TrimPrefix(path, "/") after the path parameter is extracted (around line 600).

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [ ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [ ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [ ]

return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

path = strings.TrimPrefix(path, "/")
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DeleteFile function also accepts a path parameter that is used in a TreeEntry at line 950. For consistency and to prevent similar failures, consider adding path = strings.TrimPrefix(path, "/") after the path parameter is extracted (around line 920).

Copilot uses AI. Check for mistakes.
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

path = strings.TrimPrefix(path, "/")
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case in Test_CreateOrUpdateFile that verifies a path with a leading slash is handled correctly. This would document the auto-correction behavior and prevent regressions.

Copilot uses AI. Check for mistakes.
@almaleksia almaleksia merged commit 90a1255 into main Dec 10, 2025
22 checks passed
@almaleksia almaleksia deleted the create-or-update-trim-path branch December 10, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants