Skip to content
Merged
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
6 changes: 3 additions & 3 deletions internal/strategy/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *Strategy) handleRequest(w http.ResponseWriter, r *http.Request) {
slog.String("host", host),
slog.String("path", pathValue))

if strings.HasSuffix(pathValue, "/snapshot") {
if strings.HasSuffix(pathValue, "/snapshot.tar.zst") {
s.handleSnapshotRequest(w, r, host, pathValue)
return
}
Expand Down Expand Up @@ -345,15 +345,15 @@ func ExtractRepoPath(pathValue string) string {
return repoPath
}

func (s *Strategy) serveCachedArtifact(w http.ResponseWriter, r *http.Request, host, pathValue, artifact string) {
func (s *Strategy) serveCachedArtifact(w http.ResponseWriter, r *http.Request, host, pathValue, urlSuffix, artifact string) {
ctx := r.Context()
logger := logging.FromContext(ctx)

logger.DebugContext(ctx, artifact+" request",
slog.String("host", host),
slog.String("path", pathValue))

pathValue = strings.TrimSuffix(pathValue, "/"+artifact)
pathValue = strings.TrimSuffix(pathValue, "/"+urlSuffix)
repoPath := ExtractRepoPath(pathValue)
upstreamURL := "https://" + host + "/" + repoPath
cacheKey := cache.NewKey(upstreamURL + "." + artifact)
Expand Down
2 changes: 1 addition & 1 deletion internal/strategy/git/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ func (s *Strategy) scheduleSnapshotJobs(repo *gitclone.Repository) {
}

func (s *Strategy) handleSnapshotRequest(w http.ResponseWriter, r *http.Request, host, pathValue string) {
s.serveCachedArtifact(w, r, host, pathValue, "snapshot")
s.serveCachedArtifact(w, r, host, pathValue, "snapshot.tar.zst", "snapshot")
}
8 changes: 4 additions & 4 deletions internal/strategy/git/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func TestSnapshotHTTPEndpoint(t *testing.T) {
assert.NotZero(t, handler)

// Test successful snapshot request
req := httptest.NewRequest(http.MethodGet, "/git/github.com/org/repo/snapshot", nil)
req := httptest.NewRequest(http.MethodGet, "/git/github.com/org/repo/snapshot.tar.zst", nil)
req = req.WithContext(ctx)
req.SetPathValue("host", "github.com")
req.SetPathValue("path", "org/repo/snapshot")
req.SetPathValue("path", "org/repo/snapshot.tar.zst")
w := httptest.NewRecorder()

handler.ServeHTTP(w, req)
Expand All @@ -68,10 +68,10 @@ func TestSnapshotHTTPEndpoint(t *testing.T) {
assert.Equal(t, snapshotData, w.Body.Bytes())

// Test snapshot not found
req = httptest.NewRequest(http.MethodGet, "/git/github.com/org/nonexistent/snapshot", nil)
req = httptest.NewRequest(http.MethodGet, "/git/github.com/org/nonexistent/snapshot.tar.zst", nil)
req = req.WithContext(ctx)
req.SetPathValue("host", "github.com")
req.SetPathValue("path", "org/nonexistent/snapshot")
req.SetPathValue("path", "org/nonexistent/snapshot.tar.zst")
w = httptest.NewRecorder()

handler.ServeHTTP(w, req)
Expand Down