Skip to content

Conversation

@almaleksia
Copy link
Contributor

Summary

This PR aims to significantly reduce failure rate for push_files tool.

  1. Added auto-init of repository if it is empty.
  2. Added auto-creation of branch if it doesn't exist

Why

push_files tool fails too often due to rigid assumptions that both ref that files are pushed to exists and repo is not empty. However, it is very often not the case and we shouldn't fail on such common cases.

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Prompts tested (tool changes only)

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

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 enhances the push_files tool to automatically handle two common failure scenarios: empty repositories and non-existent branches. Instead of failing when encountering these conditions, the tool now initializes empty repositories with an initial commit and creates missing branches from the default branch.

Key changes:

  • Added auto-initialization of empty repositories when a 409 Conflict status is detected
  • Added auto-creation of branches from the default branch when a branch is not found
  • Improved error handling and resource cleanup with nil checks before closing response bodies

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pkg/github/repositories.go Implements auto-init logic for empty repositories and auto-creation of non-existent branches; adds two helper functions initializeRepository and createReferenceFromDefaultBranch
pkg/github/repositories_test.go Adds comprehensive test coverage for empty repository scenarios, branch auto-creation failures, and updates existing test expectations to match new behavior

@almaleksia almaleksia force-pushed the almaleksia/push_files-improvements branch from 77142a8 to bf28276 Compare December 23, 2025 11:50
@almaleksia almaleksia force-pushed the almaleksia/push_files-improvements branch from 44a21fd to 7ea39cc Compare December 23, 2025 12:00
Base automatically changed from almaleksia/auto-resolve-default-branch to main December 23, 2025 14:24
@almaleksia almaleksia marked this pull request as ready for review December 23, 2025 14:24
@almaleksia almaleksia requested a review from a team as a code owner December 23, 2025 14:24
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

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

It's too big for me to review while off, but really nice improvement!

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.

3 participants