Skip to content

feat(push_files): use createCommitOnBranch GraphQL mutation for signed commits - #3895

Open
Asubtlecoderrr wants to merge 2 commits into
github:mainfrom
Asubtlecoderrr:feat/push-files-signed-commits
Open

Asubtlecoderrr wants to merge 2 commits into
github:mainfrom
Asubtlecoderrr:feat/push-files-signed-commits

Conversation

@Asubtlecoderrr

Copy link
Copy Markdown

Summary

Replace the five-step REST Git Data API flow in push_files with a single createCommitOnBranch GraphQL mutation so that the tool works in GitHub Enterprise environments that enforce require signed commits branch protection rules.

Why

Enterprise GitHub organisations can enable "Require signed commits" on branches. The existing implementation calls CreateTree + CreateCommit + UpdateRef via the REST Git Data API, which creates unsigned commits — these are silently rejected by that policy, making push_files completely unusable in those orgs.

The createCommitOnBranch GraphQL mutation creates web-flow signed commits (the same mechanism GitHub's own web UI uses), satisfying the enterprise policy without any special key management or GPG setup on the caller side. The change is fully backwards-compatible: the mutation works on repos whether or not the signed-commit requirement is enabled.

Verified working on GitHub Enterprise Server — the mutation is supported and produces verified commits.

What changed

  • Replaced CreateTree + GetCommit + CreateCommit + UpdateRef REST calls with a single createCommitOnBranch GraphQL mutation in PushFiles
  • File contents are base64-encoded and passed as FileAddition.Contents in the mutation input
  • The existing GetRef (and initializeRepository for empty repos) REST calls are retained — only the commit creation step changed
  • Updated Test_PushFiles: replaced tree/commit/updateref REST mocks with a GQL mutation mock; added "fails to create signed commit" error path test
  • Fixed typedRepositoryDeps GQL handler in typed_repository_outputs_test.go to dispatch responses by query type

MCP impact

  • Tool schema or behavior changed

The push_files tool now creates web-flow signed commits instead of unsigned commits. Callers on standard GitHub.com see no functional difference; callers in orgs with "require signed commits" now get a working tool instead of a silent failure.

Prompts tested (tool changes only)

  • "Push a README.md to the main branch of my repo" — succeeds on repos with and without the signed-commits requirement
  • "Update config.yaml and src/main.go in a single commit" — multi-file push works correctly
  • "Push a file to an empty repository" — initialisation path still works
  • Verified createCommitOnBranch mutation works end-to-end on GitHub Enterprise Server

Security / limits

  • Auth / permissions considered

The GraphQL mutation respects the same OAuth scopes as the REST approach (repo). No new permissions are required. Commits are web-flow signed by GitHub server-side after authenticating the caller's token — the same mechanism used by GitHub's own web editor.

Tool renaming

  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint — 0 issues
  • Tested locally with ./script/test — all 32 packages pass

Docs

  • Not needed

Skills

  • Updated relevant skills or confirmed no bundled skill applies

…d commits

Replace the five-step REST Git Data API flow (GetCommit + CreateTree +
CreateCommit + UpdateRef) in PushFiles with a single GraphQL
createCommitOnBranch mutation.

The motivation is enterprise GitHub organisations that enforce "require
signed commits" branch protection rules. The REST Git Data API creates
unsigned commits, which are rejected by that policy, making push_files
completely unusable in those environments. The createCommitOnBranch
GraphQL mutation produces web-flow signed commits, satisfying the policy
without any special key management on the caller side.

The change is fully backwards-compatible: the mutation works on repos
whether or not the signed-commit requirement is enabled.

Updated test suite:
- Replaced tree/commit/updateref REST mocks with a GQL mutation mock
- Added a "fails to create signed commit" error path test
- Fixed TypedRepositoryOutputs GQL handler to dispatch by query type
@Asubtlecoderrr
Asubtlecoderrr requested a review from a team as a code owner November 19, 2026 05:59
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 05:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The returned reference updates the SHA but leaves object.url pointing to the previous commit, causing legacy clients to retrieve stale commit data after a successful push.

1 open issue
What changed in this PR

This PR moves push_files commit creation to GraphQL’s createCommitOnBranch mutation, enabling GitHub-signed commits for repositories that require signed commits.

Changes:

  • Replace REST tree, commit, and reference-update operations with a GraphQL mutation using base64-encoded file contents.
  • Retain REST-based branch lookup, branch creation, and empty-repository initialization.
  • Update behavioral tests and shared GraphQL mocks for the new commit flow.
File Description
pkg/​github/​typed_repository_outputs_test.go Dispatch GraphQL mock responses by query type.
pkg/​github/​repositories.go Implement signed commit creation through GraphQL.
pkg/​github/​repositories_test.go Replace REST commit mocks with GraphQL success and failure cases.

Review effort: Balanced (adaptive)

Comment thread pkg/github/repositories.go Resolved
The URL was still pointing at the previous commit after updating the SHA.
Update it in-place so legacy clients following object.url get the new commit.
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.

2 participants