Skip to content

feat: CreateBranch should auto-resolve branch name to commit SHA#2

Merged
zy84338719 merged 1 commit into
mainfrom
feat/create-branch-auto-resolve-ref
May 17, 2026
Merged

feat: CreateBranch should auto-resolve branch name to commit SHA#2
zy84338719 merged 1 commit into
mainfrom
feat/create-branch-auto-resolve-ref

Conversation

@zy84338719
Copy link
Copy Markdown
Member

Summary

Closes #1

GitHub's CreateRef API requires a full 40-character commit SHA as the ref parameter. However, users naturally pass branch names like "main" or "feature/xxx", which results in a 422 error.

Changes

  • provider/util.go: Added isCommitSHA() helper to detect 40-char hex SHA strings
  • provider/github.go: CreateBranch now auto-detects whether ref is a SHA or branch name. If not a SHA, it resolves via ListCommits(ctx, owner, repo, {Branch: ref, PerPage: 1}) transparently
  • provider/github_test.go: Updated existing test mock to handle commits resolution, added TestGitHub_CreateBranch_WithSHA for direct SHA pass-through

Other Platforms

No changes needed for GitLab, Gitea, Forgejo, Tencent Code — their APIs already accept branch names as refs natively.

GitHub's CreateRef API requires a full 40-char commit SHA, but users
naturally pass branch names like 'main' or 'feature/xxx'. This change
auto-detects whether the ref is a SHA or a branch name and resolves
branch names to their latest commit SHA via ListCommits.

Closes #1
Copilot AI review requested due to automatic review settings May 17, 2026 12:51
@zy84338719 zy84338719 merged commit da65f1e into main May 17, 2026
1 check failed
@zy84338719 zy84338719 review requested due to automatic review settings May 17, 2026 13:14
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.

feat: CreateBranch should auto-resolve branch name to commit SHA

1 participant