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
9 changes: 9 additions & 0 deletions packages/code-storage-go/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ func (r *Repo) ListBranches(ctx context.Context, options ListBranchesOptions) (L
if options.Limit > 0 {
params.Set("limit", itoa(options.Limit))
}
if options.Ephemeral != nil {
params.Set("ephemeral", strconv.FormatBool(*options.Ephemeral))
}
if len(params) == 0 {
params = nil
}
Expand Down Expand Up @@ -356,6 +359,9 @@ func (r *Repo) ListCommits(ctx context.Context, options ListCommitsOptions) (Lis
if options.Limit > 0 {
params.Set("limit", itoa(options.Limit))
}
if options.Ephemeral != nil {
params.Set("ephemeral", strconv.FormatBool(*options.Ephemeral))
}
if len(params) == 0 {
params = nil
}
Expand Down Expand Up @@ -686,6 +692,9 @@ func (r *Repo) Grep(ctx context.Context, options GrepOptions) (GrepResult, error
if ref != "" {
body.Ref = ref
}
if options.Ephemeral != nil {
body.Ephemeral = options.Ephemeral
}
if len(options.Paths) > 0 {
body.Paths = options.Paths
}
Expand Down
88 changes: 88 additions & 0 deletions packages/code-storage-go/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,39 @@ func TestGrepRequestBody(t *testing.T) {
}
}

func TestGrepEphemeralRequestBody(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/repos/grep" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
var body map[string]interface{}
_ = json.NewDecoder(r.Body).Decode(&body)
if body["ephemeral"] != true {
t.Fatalf("expected ephemeral=true, got %v", body["ephemeral"])
}
if body["ref"] != "feature" {
t.Fatalf("expected ref=feature, got %v", body["ref"])
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"query":{"pattern":"SEARCH","case_sensitive":false},"repo":{"ref":"feature","commit":"deadbeef"},"matches":[],"has_more":false}`))
}))
defer server.Close()

client, err := NewClient(Options{Name: "acme", Key: testKey, APIBaseURL: server.URL})
if err != nil {
t.Fatalf("client error: %v", err)
}
repo := &Repo{ID: "repo", DefaultBranch: "main", client: client}

if _, err = repo.Grep(nil, GrepOptions{
Ref: "feature",
Ephemeral: boolPtr(true),
Query: GrepQuery{Pattern: "SEARCH"},
}); err != nil {
t.Fatalf("grep error: %v", err)
}
}

func TestGrepRequestLegacyRev(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/repos/grep" {
Expand Down Expand Up @@ -1289,6 +1322,61 @@ func TestListCommitsDateParsing(t *testing.T) {
}
}

func TestListBranchesEphemeralQueryParam(t *testing.T) {
var rawQuery string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/repos/branches" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
rawQuery = r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"branches":[],"has_more":false}`))
}))
defer server.Close()

client, err := NewClient(Options{Name: "acme", Key: testKey, APIBaseURL: server.URL})
if err != nil {
t.Fatalf("client error: %v", err)
}
repo := &Repo{ID: "repo", DefaultBranch: "main", client: client}

if _, err = repo.ListBranches(nil, ListBranchesOptions{Ephemeral: boolPtr(true)}); err != nil {
t.Fatalf("list branches error: %v", err)
}
if !strings.Contains(rawQuery, "ephemeral=true") {
t.Fatalf("expected ephemeral=true in query, got %q", rawQuery)
}
}

func TestListCommitsEphemeralQueryParam(t *testing.T) {
var rawQuery string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/repos/commits" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
rawQuery = r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"commits":[],"has_more":false}`))
}))
defer server.Close()

client, err := NewClient(Options{Name: "acme", Key: testKey, APIBaseURL: server.URL})
if err != nil {
t.Fatalf("client error: %v", err)
}
repo := &Repo{ID: "repo", DefaultBranch: "main", client: client}

if _, err = repo.ListCommits(nil, ListCommitsOptions{Branch: "feature", Ephemeral: boolPtr(true)}); err != nil {
t.Fatalf("list commits error: %v", err)
}
if !strings.Contains(rawQuery, "ephemeral=true") {
t.Fatalf("expected ephemeral=true in query, got %q", rawQuery)
}
if !strings.Contains(rawQuery, "branch=feature") {
t.Fatalf("expected branch=feature in query, got %q", rawQuery)
}
}

func TestListCommitsUserAgentHeader(t *testing.T) {
var headerAgent string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 1 addition & 0 deletions packages/code-storage-go/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type authorInfo struct {
type grepRequest struct {
Query grepQueryPayload `json:"query"`
Ref string `json:"ref,omitempty"`
Ephemeral *bool `json:"ephemeral,omitempty"`
Paths []string `json:"paths,omitempty"`
FileFilters *grepFileFilterPayload `json:"file_filters,omitempty"`
Context *grepContextPayload `json:"context,omitempty"`
Expand Down
13 changes: 8 additions & 5 deletions packages/code-storage-go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ type ListFilesWithMetadataResult struct {
// ListBranchesOptions configures list branches.
type ListBranchesOptions struct {
InvocationOptions
Cursor string
Limit int
Cursor string
Limit int
Ephemeral *bool
}

// BranchInfo describes a branch.
Expand Down Expand Up @@ -437,9 +438,10 @@ type DeleteTagResult struct {
// ListCommitsOptions configures list commits.
type ListCommitsOptions struct {
InvocationOptions
Branch string
Cursor string
Limit int
Branch string
Cursor string
Limit int
Ephemeral *bool
}

// CommitInfo describes a commit entry.
Expand Down Expand Up @@ -619,6 +621,7 @@ type GrepOptions struct {
Ref string
// Deprecated: use Ref instead.
Rev string
Ephemeral *bool
Query GrepQuery
Paths []string
FileFilters *GrepFileFilters
Expand Down
2 changes: 2 additions & 0 deletions packages/code-storage-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ class Repo:
*,
limit: Optional[int] = None,
cursor: Optional[str] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListBranchesResult: ...

Expand Down Expand Up @@ -742,6 +743,7 @@ class Repo:
branch: Optional[str] = None,
limit: Optional[int] = None,
cursor: Optional[str] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListCommitsResult: ...

Expand Down
12 changes: 12 additions & 0 deletions packages/code-storage-python/pierre_storage/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,15 @@ async def list_branches(
*,
cursor: Optional[str] = None,
limit: Optional[int] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListBranchesResult:
"""List branches in repository.

Args:
cursor: Pagination cursor
limit: Maximum number of branches to return
ephemeral: When true, list branches under the ephemeral namespace
ttl: Token TTL in seconds

Returns:
Expand All @@ -516,6 +518,8 @@ async def list_branches(
params["cursor"] = cursor
if limit is not None:
params["limit"] = str(limit)
if ephemeral is not None:
params["ephemeral"] = "true" if ephemeral else "false"

url = f"{self.api_base_url}/api/v{self.api_version}/repos/branches"
if params:
Expand Down Expand Up @@ -999,6 +1003,7 @@ async def list_commits(
branch: Optional[str] = None,
cursor: Optional[str] = None,
limit: Optional[int] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListCommitsResult:
"""List commits in repository.
Expand All @@ -1007,6 +1012,7 @@ async def list_commits(
branch: Branch name to list commits from
cursor: Pagination cursor
limit: Maximum number of commits to return
ephemeral: When true, resolve `branch` under the ephemeral namespace
ttl: Token TTL in seconds

Returns:
Expand All @@ -1022,6 +1028,8 @@ async def list_commits(
params["cursor"] = cursor
if limit is not None:
params["limit"] = str(limit)
if ephemeral is not None:
params["ephemeral"] = "true" if ephemeral else "false"

url = f"{self.api_base_url}/api/v{self.api_version}/repos/commits"
if params:
Expand Down Expand Up @@ -1405,6 +1413,7 @@ async def grep(
pattern: str,
ref: Optional[str] = None,
rev: Optional[str] = None,
ephemeral: Optional[bool] = None,
paths: Optional[list[str]] = None,
case_sensitive: Optional[bool] = None,
file_filters: Optional[Dict[str, Any]] = None,
Expand All @@ -1419,6 +1428,7 @@ async def grep(
pattern: Regex pattern to search for
ref: Git ref to search (defaults to server-side default branch)
rev: Deprecated alias for ref
ephemeral: When true, resolve `ref` under the ephemeral namespace
paths: Git pathspecs to restrict search
case_sensitive: Whether search is case-sensitive (default: server default)
file_filters: Optional filters with include_globs/exclude_globs/extension_filters
Expand Down Expand Up @@ -1455,6 +1465,8 @@ async def grep(
body["ref"] = ref
elif rev:
body["ref"] = rev
if ephemeral is not None:
body["ephemeral"] = bool(ephemeral)
if paths:
body["paths"] = paths
if file_filters:
Expand Down
3 changes: 3 additions & 0 deletions packages/code-storage-python/pierre_storage/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ async def list_branches(
*,
cursor: Optional[str] = None,
limit: Optional[int] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListBranchesResult:
"""List branches in the repository."""
Expand Down Expand Up @@ -745,6 +746,7 @@ async def list_commits(
branch: Optional[str] = None,
cursor: Optional[str] = None,
limit: Optional[int] = None,
ephemeral: Optional[bool] = None,
ttl: Optional[int] = None,
) -> ListCommitsResult:
"""List commits in the repository."""
Expand Down Expand Up @@ -833,6 +835,7 @@ async def grep(
pattern: str,
ref: Optional[str] = None,
rev: Optional[str] = None,
ephemeral: Optional[bool] = None,
paths: Optional[list[str]] = None,
case_sensitive: Optional[bool] = None,
file_filters: Optional[Dict[str, Any]] = None,
Expand Down
Loading
Loading