feat(gitea): pull-request create/list/get/merge endpoints

This commit is contained in:
2026-08-29 16:11:58 -05:00
parent c251cd6a98
commit 5b35e8cd84
3 changed files with 278 additions and 6 deletions
+13 -6
View File
@@ -9,6 +9,8 @@
package fakegitea
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
@@ -206,8 +208,10 @@ func (s *Server) addRepoLocked(owner, name, defaultBranch string, branches []str
}
func (st *repoState) addBranch(name string) string {
// Deterministic distinct 40-hex shas (fake but well-formed).
sha := fmt.Sprintf("%040x", len(st.order)+1)
// Distinct, well-formed 40-hex shas derived from the branch key, so
// short-sha (>= 7 chars) resolution is unambiguous like real git.
sum := sha256.Sum256([]byte(st.repo.FullName + "/" + name))
sha := hex.EncodeToString(sum[:])[:40]
if _, ok := st.branches[name]; !ok {
st.order = append(st.order, name)
}
@@ -464,14 +468,17 @@ func (s *Server) listBranches(owner, name string) (int, string) {
}
// resolveRef maps a ref (full sha, sha prefix, or branch name) to a commit
// sha; ok=false when nothing matches.
// sha; ok=false when nothing matches. Prefix matches scan branches in
// insertion order for determinism.
func (st *repoState) resolveRef(ref string) (string, bool) {
if sha, ok := st.branches[ref]; ok {
return sha, true
}
for _, sha := range st.branches {
if strings.HasPrefix(sha, ref) && len(ref) >= 7 {
return sha, true
if len(ref) >= 7 {
for _, b := range st.order {
if strings.HasPrefix(st.branches[b], ref) {
return st.branches[b], true
}
}
}
return "", false