feat: added vercel support for deployments + domains#567
Conversation
WalkthroughAdds a new Vercel provider. Wires it into the provider registry and constructor, implements a Vercel API client and data types, and provides a Provider with service selection, identification, and resource enumeration (projects -> deployments/domains) using Vercel’s API with optional team scoping. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Inventory as Inventory
participant Provider as Vercel Provider
participant API as Vercel API Client
Note over Inventory,Provider: Initialization
User->>Inventory: Configure provider name="vercel"
Inventory->>Inventory: nameToProvider("vercel")
Inventory->>Provider: vercel.New(options)
activate Provider
Provider->>API: newAPIClient(token, teamId)
deactivate Provider
Inventory-->>User: Provider instance
sequenceDiagram
autonumber
participant Caller as Caller
participant Provider as Vercel Provider
participant API as Vercel API Client
participant Vercel as Vercel HTTP API
Note over Provider: Resources enumeration
Caller->>Provider: Resources(ctx)
Provider->>API: ListProjects(req)
API->>Vercel: GET /v8/projects[?teamId]
Vercel-->>API: 200 OK + projects JSON
API-->>Provider: ListProjectsResponse
alt services include "deployments"
Provider->>Provider: Map LatestDeployments -> resources
end
alt services include "domains"
Provider->>Provider: Map production aliases -> resources
end
Provider-->>Caller: Resources
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
pkg/inventory/inventory.go(3 hunks)pkg/providers/vercel/api.go(1 hunks)pkg/providers/vercel/api_types.go(1 hunks)pkg/providers/vercel/vercel.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/inventory/inventory.go (1)
pkg/providers/vercel/vercel.go (2)
Services(10-10)New(20-51)
pkg/providers/vercel/api.go (1)
pkg/providers/vercel/api_types.go (2)
ListProjectsRequest(3-19)ListProjectsResponse(21-23)
pkg/providers/vercel/vercel.go (3)
pkg/schema/schema.go (6)
ServiceMap(254-254)OptionBlock(195-195)ErrNoSuchKey(166-168)Resources(39-42)NewResources(45-50)Resource(142-163)pkg/inventory/inventory.go (1)
New(37-52)pkg/providers/vercel/api_types.go (1)
ListProjectsRequest(3-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Analyze (go)
- GitHub Check: Test Builds (1.22.x, windows-latest)
- GitHub Check: Test Builds (1.22.x, ubuntu-latest)
- GitHub Check: Test Builds (1.22.x, macOS-latest)
- GitHub Check: release-test
- GitHub Check: Lint Test
| // Search projects by the name field. | ||
| // Required: No | ||
| Search string `json:"string,omitempty"` | ||
| } |
There was a problem hiding this comment.
Wrong JSON tag breaks search filter.
ListProjectsRequest.Search is tagged as json:"string,omitempty"; the Vercel API expects search, so this field will never be serialized correctly. Please fix the tag so future requests can filter projects.
Apply this diff:
- Search string `json:"string,omitempty"`
+ Search string `json:"search,omitempty"`📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Search projects by the name field. | |
| // Required: No | |
| Search string `json:"string,omitempty"` | |
| } | |
| // Search projects by the name field. | |
| // Required: No | |
| Search string `json:"search,omitempty"` | |
| } |
🤖 Prompt for AI Agents
In pkg/providers/vercel/api_types.go around lines 16 to 19, the JSON tag for
ListProjectsRequest.Search is incorrect ("json:\"string,omitempty\""); change it
to the expected API field name by updating the tag to
"json:\"search,omitempty\"" so the Search field is serialized as "search" in
requests.
| res, err := c.httpClient.Do(req) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "unable to perform request") | ||
| } | ||
| if res.StatusCode < 200 || res.StatusCode >= 300 { | ||
| var responseBody map[string]interface{} | ||
| err = json.NewDecoder(res.Body).Decode(&responseBody) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("response returned status code %d, path: %s", res.StatusCode, path) | ||
| } | ||
|
|
||
| // Try to prettyprint the response body | ||
| // If that is not possible we return the raw body | ||
| pretty, err := json.MarshalIndent(responseBody, "", " ") | ||
| if err != nil { | ||
| return nil, fmt.Errorf("response returned status code %d: %+v, path: %s", res.StatusCode, responseBody, path) | ||
| } | ||
| return nil, fmt.Errorf("response returned status code %d: %+v, path: %s", res.StatusCode, string(pretty), path) | ||
| } |
There was a problem hiding this comment.
Close non-2xx response bodies.
When we hit a non-2xx status we decode the body and return but never close it, leaking connections in the transport. Add a defer res.Body.Close() immediately after Do (or explicitly close before every return path).
🤖 Prompt for AI Agents
In pkg/providers/vercel/api.go around lines 92 to 110, the HTTP response body
from c.httpClient.Do(req) is not closed on non-2xx paths causing connection
leaks; add resource cleanup by calling defer res.Body.Close() immediately after
a successful Do (right after checking err) or explicitly call res.Body.Close()
before each return in the non-2xx branch so the response body is always closed
regardless of decode/marshal errors.
| func (c *vercelClient) ListProjects(req ListProjectsRequest) (res ListProjectsResponse, err error) { | ||
| apiRequest := newApiRequest("GET", "/v8/projects", &res) | ||
| if c.config.Teamid != "" { | ||
| apiRequest.Query.Add("teamId", c.config.Teamid) | ||
| } | ||
| err = c.Call(apiRequest) | ||
| if err != nil { | ||
| return ListProjectsResponse{}, fmt.Errorf("unable to fetch projects: %w", err) | ||
| } |
There was a problem hiding this comment.
Honor pagination and request filters.
ListProjects stops after the first page and drops every filter in ListProjectsRequest. Vercel paginates /v8/projects (default limit 20), so larger orgs will lose assets. Please extend ListProjectsResponse to capture the pagination cursor, loop until exhaustion, and propagate Limit/Since/Until/Search into the query string so callers can scope requests.
🤖 Prompt for AI Agents
In pkg/providers/vercel/api.go around lines 131 to 139, ListProjects currently
issues a single GET to /v8/projects and ignores ListProjectsRequest filters and
pagination; update it to propagate req.Limit, req.Since, req.Until, and
req.Search into apiRequest.Query, extend ListProjectsResponse to carry the
pagination cursor (e.g., Next or Cursor), and implement a loop that calls the
API repeatedly, appending returned projects to a cumulative response and
updating the query cursor until the API indicates no more pages or the requested
limit is satisfied; return the combined response and any error.
|
@coderabbitai update the issue with a proper description of the implemented functionality |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 409 🏁 Script executed: Length of output: 56 @Mzack9999: I've updated issue #566 with a comprehensive description of the implemented functionality. The update includes:
The issue now clearly documents what was delivered in PR #567. |
…api-support feat: added vercel support for deployments + domains
Closes #566
Summary by CodeRabbit