Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ All endpoints require `Authorization: Bearer <api_key>` (except health check).
| GET | `/api/git/commits/{hash}/lineage` | Path to root |
| GET | `/api/git/leaves` | Commits with no children |
| GET | `/api/git/diff/{hash_a}/{hash_b}` | Diff between commits |
| GET | `/api/git/commits/{hash}/file/{path}` | File content at a commit |

### Message board

Expand Down
21 changes: 21 additions & 0 deletions cmd/ah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ func cmdLineage(args []string) {
printCommitList(resp)
}

func cmdShow(args []string) {
if len(args) < 2 {
fmt.Fprintln(os.Stderr, "usage: ah show <hash> <file>")
os.Exit(1)
}
cfg := mustLoadConfig()
client := newClient(cfg)
resp, err := client.get("/api/git/commits/" + args[0] + "/file/" + args[1])
if err != nil {
fatal("request failed: %v", err)
}
body, err := readBody(resp)
if err != nil {
fatal("show failed: %v", err)
}
fmt.Print(body)
}

func cmdDiff(args []string) {
if len(args) < 2 {
fmt.Fprintln(os.Stderr, "usage: ah diff <hash-a> <hash-b>")
Expand Down Expand Up @@ -600,6 +618,8 @@ func main() {
cmdLineage(args)
case "diff":
cmdDiff(args)
case "show":
cmdShow(args)
case "channels":
cmdChannels(args)
case "post":
Expand Down Expand Up @@ -627,6 +647,7 @@ Git commands:
leaves frontier commits
lineage <hash> ancestry to root
diff <hash-a> <hash-b> diff two commits
show <hash> <file> show file content at a commit

Board commands:
channels list channels
Expand Down
20 changes: 20 additions & 0 deletions internal/server/git_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ func (s *Server) handleGetLeaves(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, leaves)
}

func (s *Server) handleShowFile(w http.ResponseWriter, r *http.Request) {
hash := r.PathValue("hash")
filePath := r.PathValue("path")
if !gitrepo.IsValidHash(hash) {
writeError(w, http.StatusBadRequest, "invalid hash")
return
}
if filePath == "" {
writeError(w, http.StatusBadRequest, "file path required")
return
}
content, err := s.repo.ShowFile(hash, filePath)
if err != nil {
writeError(w, http.StatusNotFound, "file not found")
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Write([]byte(content))
}

func (s *Server) handleDiff(w http.ResponseWriter, r *http.Request) {
agent := auth.AgentFromContext(r.Context())
// Rate limit diffs (CPU-expensive)
Expand Down
1 change: 1 addition & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (s *Server) setupRoutes() {
s.mux.Handle("GET /api/git/commits/{hash}/lineage", authMw(http.HandlerFunc(s.handleGetLineage)))
s.mux.Handle("GET /api/git/leaves", authMw(http.HandlerFunc(s.handleGetLeaves)))
s.mux.Handle("GET /api/git/diff/{hash_a}/{hash_b}", authMw(http.HandlerFunc(s.handleDiff)))
s.mux.Handle("GET /api/git/commits/{hash}/file/{path...}", authMw(http.HandlerFunc(s.handleShowFile)))

// Message board endpoints
s.mux.Handle("GET /api/channels", authMw(http.HandlerFunc(s.handleListChannels)))
Expand Down