Skip to content

Commit 6d616b1

Browse files
authored
Merge pull request #1245 from entireio/trail-watch-review-events-endpoint
Update trail watch review event endpoint
2 parents 944f9b3 + acd3d01 commit 6d616b1

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

cmd/entire/cli/api/trail_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ type TrailListResponse struct {
1616

1717
// TrailResource represents a single trail from the API.
1818
type TrailResource struct {
19+
ID string `json:"id,omitempty"`
1920
Number int `json:"number,omitempty"`
20-
TrailID string `json:"trail_id"`
2121
Branch string `json:"branch"`
2222
Base string `json:"base"`
2323
Title string `json:"title"`
@@ -42,7 +42,7 @@ type TrailResource struct {
4242
func (r *TrailResource) ToMetadata() *trail.Metadata {
4343
m := &trail.Metadata{
4444
Number: r.Number,
45-
TrailID: trail.ID(r.TrailID),
45+
TrailID: trail.ID(r.ID),
4646
Branch: r.Branch,
4747
Base: r.Base,
4848
Title: r.Title,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package api
2+
3+
import "testing"
4+
5+
func TestTrailResourceToMetadataUsesID(t *testing.T) {
6+
t.Parallel()
7+
8+
metadata := (&TrailResource{ID: "trail-db-id", Branch: "feature/x"}).ToMetadata()
9+
if got := metadata.TrailID.String(); got != "trail-db-id" {
10+
t.Fatalf("metadata TrailID = %q, want stable API id", got)
11+
}
12+
}

cmd/entire/cli/trail_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func runTrailCreate(cmd *cobra.Command, title, body, base, branch, statusStr str
611611
return fmt.Errorf("failed to decode create response: %w", err)
612612
}
613613

614-
fmt.Fprintf(w, "Created trail %q for branch %s (ID: %s)\n", createResp.Trail.Title, createResp.Trail.Branch, createResp.Trail.TrailID)
614+
fmt.Fprintf(w, "Created trail %q for branch %s (ID: %s)\n", createResp.Trail.Title, createResp.Trail.Branch, createResp.Trail.ID)
615615

616616
// --- Phase 3: Post-creation local operations ---
617617

@@ -743,7 +743,7 @@ func runTrailUpdate(ctx context.Context, w, errW io.Writer, insecureHTTP bool, s
743743
// Build update request with only changed fields
744744
updateReq := buildTrailUpdateRequest(found, statusStr, title, body, labelAdd, labelRemove)
745745

746-
resp, err := client.Patch(ctx, trailsBasePath(host, owner, repoName)+"/"+found.TrailID, updateReq)
746+
resp, err := client.Patch(ctx, trailsBasePath(host, owner, repoName)+"/"+found.ID, updateReq)
747747
if err != nil {
748748
return fmt.Errorf("failed to update trail: %w", err)
749749
}

cmd/entire/cli/trail_watch_cmd.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ connection (~50s) and on transient network errors.
5656
If <number> is omitted, the trail for the current branch is used.
5757
5858
This command resolves the trail's id internally and streams
59-
GET /api/v1/review-events?trail_id=<id>&stream=1.
59+
GET /api/v1/trails/<id>/reviews/events with Accept: text/event-stream.
6060
6161
Events emitted by the server:
6262
ready initial frame, includes trail and cursor
@@ -188,10 +188,10 @@ func resolveTrailWatchTarget(ctx context.Context, client *api.Client, number int
188188
if found == nil {
189189
return "", "", fmt.Errorf("no trail found for branch %q (pass an explicit trail number)", branch)
190190
}
191-
if found.TrailID == "" {
191+
if found.ID == "" {
192192
return "", "", fmt.Errorf("trail for branch %q has no id yet", branch)
193193
}
194-
return found.TrailID, trailWatchDescription(host, owner, repo, found.Number, found.TrailID), nil
194+
return found.ID, trailWatchDescription(host, owner, repo, found.Number, found.ID), nil
195195
}
196196

197197
func resolveTrailWatchNumber(ctx context.Context, client *api.Client, number int) (trailID, description string, err error) {
@@ -206,10 +206,10 @@ func resolveTrailWatchNumber(ctx context.Context, client *api.Client, number int
206206
if found == nil {
207207
return "", "", fmt.Errorf("no trail #%d found in %s/%s/%s", number, host, owner, repo)
208208
}
209-
if found.TrailID == "" {
209+
if found.ID == "" {
210210
return "", "", fmt.Errorf("trail #%d has no id yet", number)
211211
}
212-
return found.TrailID, trailWatchDescription(host, owner, repo, found.Number, found.TrailID), nil
212+
return found.ID, trailWatchDescription(host, owner, repo, found.Number, found.ID), nil
213213
}
214214

215215
func trailWatchDescription(host, owner, repo string, number int, trailID string) string {
@@ -220,10 +220,7 @@ func trailWatchDescription(host, owner, repo string, number int, trailID string)
220220
}
221221

222222
func reviewEventsPath(trailID string) string {
223-
query := url.Values{}
224-
query.Set("trail_id", trailID)
225-
query.Set("stream", "1")
226-
return "/api/v1/review-events?" + query.Encode()
223+
return "/api/v1/trails/" + url.PathEscape(trailID) + "/reviews/events"
227224
}
228225

229226
type streamCloseReason int

cmd/entire/cli/trail_watch_cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func fakeSSEServer(t *testing.T, frames []string) (*httptest.Server, *string) {
4040

4141
func TestReviewEventsPath(t *testing.T) {
4242
got := reviewEventsPath("trail id/with slash")
43-
want := "/api/v1/review-events?stream=1&trail_id=trail+id%2Fwith+slash"
43+
want := "/api/v1/trails/trail%20id%2Fwith%20slash/reviews/events"
4444
if got != want {
4545
t.Fatalf("reviewEventsPath = %q, want %q", got, want)
4646
}

0 commit comments

Comments
 (0)