Skip to content

Commit 67613f0

Browse files
committed
Fix GitClone test executor repo metadata outputs
1 parent 74cb6f0 commit 67613f0

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

api/testing/executor.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"log/slog"
8+
"net/url"
89
"os"
910
"os/exec"
1011
"path/filepath"
@@ -1496,9 +1497,14 @@ func (e *TestExecutor) executeGitClone(block api.ParsedComponent, step TestStep,
14961497
// Store outputs
14971498
result.Outputs["clone_path"] = absolutePath
14981499
result.Outputs["file_count"] = fmt.Sprintf("%d", fileCount)
1500+
result.Outputs["repo_url"] = cloneURL
14991501
if ref != "" {
15001502
result.Outputs["ref"] = ref
15011503
}
1504+
if owner, repo := parseOwnerRepoFromURL(cloneURL); owner != "" {
1505+
result.Outputs["repo_owner"] = owner
1506+
result.Outputs["repo_name"] = repo
1507+
}
15021508

15031509
// Store in block outputs for downstream access
15041510
e.blockOutputs[block.ID] = result.Outputs
@@ -1519,7 +1525,34 @@ func (e *TestExecutor) executeGitClone(block api.ParsedComponent, step TestStep,
15191525
return result
15201526
}
15211527

1528+
// parseOwnerRepoFromURL extracts owner/repo from HTTPS or SSH-style git URLs.
1529+
func parseOwnerRepoFromURL(rawURL string) (owner, repo string) {
1530+
// Handle SSH-style URLs: git@github.com:org/repo.git
1531+
if idx := strings.Index(rawURL, ":"); idx >= 0 && !strings.Contains(rawURL, "://") {
1532+
path := rawURL[idx+1:]
1533+
path = strings.TrimSuffix(path, ".git")
1534+
parts := strings.SplitN(path, "/", 3)
1535+
if len(parts) >= 2 {
1536+
return parts[0], parts[1]
1537+
}
1538+
return "", ""
1539+
}
1540+
1541+
parsed, err := url.Parse(rawURL)
1542+
if err != nil {
1543+
return "", ""
1544+
}
1545+
1546+
path := strings.Trim(parsed.Path, "/")
1547+
path = strings.TrimSuffix(path, ".git")
15221548

1549+
parts := strings.SplitN(path, "/", 3)
1550+
if len(parts) < 2 {
1551+
return "", ""
1552+
}
1553+
1554+
return parts[0], parts[1]
1555+
}
15231556

15241557
// getSessionEnvVar reads an env var from the session.
15251558
func (e *TestExecutor) getSessionEnvVar(key string) string {

api/testing/executor_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ func TestExecuteGitClone_Success(t *testing.T) {
733733
assert.Equal(t, "success", cloneResult.ActualStatus)
734734
assert.NotEmpty(t, cloneResult.Outputs["clone_path"])
735735
assert.Equal(t, "2", cloneResult.Outputs["file_count"]) // README.md + src/main.go
736+
assert.Equal(t, repoURL, cloneResult.Outputs["repo_url"])
737+
assert.NotEmpty(t, cloneResult.Outputs["repo_owner"])
738+
assert.NotEmpty(t, cloneResult.Outputs["repo_name"])
736739

737740
// Verify cloned files exist on disk
738741
clonePath := cloneResult.Outputs["clone_path"]

0 commit comments

Comments
 (0)