Skip to content

Commit 7f18d4e

Browse files
committed
fix: clean up inline structs, fix context types, return workspace error
1 parent 325dfcd commit 7f18d4e

File tree

9 files changed

+70
-86
lines changed

9 files changed

+70
-86
lines changed

gen/proto/ctrl/v1/deployment.pb.go

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/proto/hydra/v1/deploy.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/proto/hydra/v1/deploy_restate.pb.go

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svc/ctrl/proto/ctrl/v1/deployment.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ enum DeploymentStatus {
1414
DEPLOYMENT_STATUS_FINALIZING = 8;
1515
DEPLOYMENT_STATUS_READY = 5;
1616
DEPLOYMENT_STATUS_FAILED = 6;
17-
// 9 and 10 were AWAITING_APPROVAL and REJECTED, removed in no-table authorization refactor.
18-
reserved 9, 10;
1917
}
2018

2119
// Source type for deployment creation

svc/ctrl/worker/deploy/github_status.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,16 @@ func (r *githubStatusReporter) Report(ctx restate.ObjectSharedContext, state str
130130
}, restate.WithName("github deployment status: "+state), restate.WithMaxRetryDuration(30*time.Second))
131131
}
132132

133-
// statusReporterResult holds the status reporter and related context needed
134-
// by other GitHub integrations (e.g. PR comments).
135-
type statusReporterResult struct {
136-
reporter deploymentStatusReporter
137-
repoConn db.GithubRepoConnection
138-
hasRepoConn bool
139-
environmentURL string
140-
}
141-
142133
// createStatusReporter builds the appropriate deployment status reporter.
143134
// Returns a GitHub reporter if a repo connection exists, otherwise a noop.
144-
// Also returns the repo connection and environment URL for use by PR comments.
145135
func (w *Workflow) createStatusReporter(
146136
ctx restate.ObjectContext,
147137
deployment db.Deployment,
148138
project db.Project,
149139
app db.App,
150140
environment db.Environment,
151141
workspace db.Workspace,
152-
) statusReporterResult {
153-
prefix := project.Slug
154-
if app.Slug != "default" {
155-
prefix = project.Slug + "-" + app.Slug
156-
}
157-
envURL := fmt.Sprintf("https://%s-%s-%s.%s", prefix, environment.Slug, workspace.Slug, w.defaultDomain)
158-
142+
) deploymentStatusReporter {
159143
repoConn, err := restate.Run(ctx, func(runCtx restate.RunContext) (db.GithubRepoConnection, error) {
160144
return db.Query.FindGithubRepoConnectionByAppId(runCtx, w.db.RO(), deployment.AppID)
161145
}, restate.WithName("find github repo connection"))
@@ -164,14 +148,19 @@ func (w *Workflow) createStatusReporter(
164148
"app_id", deployment.AppID,
165149
"error", err,
166150
)
167-
return statusReporterResult{reporter: NewNoopStatusReporter(), environmentURL: envURL}
151+
return NewNoopStatusReporter()
168152
}
169153

170154
envLabel := project.Slug + " - " + environment.Slug
171155
if app.Slug != "default" {
172156
envLabel = project.Slug + "/" + app.Slug + " - " + environment.Slug
173157
}
174158

159+
prefix := project.Slug
160+
if app.Slug != "default" {
161+
prefix = project.Slug + "-" + app.Slug
162+
}
163+
envURL := fmt.Sprintf("https://%s-%s-%s.%s", prefix, environment.Slug, workspace.Slug, w.defaultDomain)
175164
logURL := fmt.Sprintf("%s/%s/projects/%s/deployments/%s", w.dashboardURL, workspace.Slug, project.ID, deployment.ID)
176165

177166
reporter := newGithubStatusReporter(
@@ -181,10 +170,5 @@ func (w *Workflow) createStatusReporter(
181170
deployment.ID, environment.Slug == "production",
182171
)
183172
reporter.Create(ctx)
184-
return statusReporterResult{
185-
reporter: reporter,
186-
repoConn: repoConn,
187-
hasRepoConn: true,
188-
environmentURL: envURL,
189-
}
173+
return reporter
190174
}

svc/ctrl/worker/deploy/update_github_deployment_status_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// UpdateGitHubDeploymentStatus looks up a deployment's GitHub deployment ID and
1111
// repo connection, then reports the requested state to the GitHub Deployments API.
1212
// This runs on the worker which owns the GitHub App credentials.
13-
func (w *Workflow) UpdateGitHubDeploymentStatus(ctx restate.WorkflowSharedContext, req *hydrav1.UpdateGitHubDeploymentStatusRequest) (*hydrav1.UpdateGitHubDeploymentStatusResponse, error) {
13+
func (w *Workflow) UpdateGitHubDeploymentStatus(ctx restate.ObjectContext, req *hydrav1.UpdateGitHubDeploymentStatusRequest) (*hydrav1.UpdateGitHubDeploymentStatusResponse, error) {
1414
deployment, err := restate.Run(ctx, func(ctx restate.RunContext) (*db.Deployment, error) {
1515
d, findErr := db.Query.FindDeploymentById(ctx, w.db.RO(), req.DeploymentId)
1616
if findErr != nil {

svc/ctrl/worker/github/client.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ type ghDeploymentResponse struct {
4848
ID int64 `json:"id"`
4949
}
5050

51+
// ghCheckRunResponse is the subset of GitHub's check-run creation response.
52+
type ghCheckRunResponse struct {
53+
ID int64 `json:"id"`
54+
}
55+
56+
// ghCheckRun is a single check run entry from the list endpoint.
57+
type ghCheckRun struct {
58+
ID int64 `json:"id"`
59+
Name string `json:"name"`
60+
}
61+
62+
// ghCheckRunsResponse is the response from GitHub's list check-runs endpoint.
63+
type ghCheckRunsResponse struct {
64+
CheckRuns []ghCheckRun `json:"check_runs"`
65+
}
66+
5167
// ClientConfig holds configuration for creating a [Client] instance.
5268
type ClientConfig struct {
5369
// AppID is the numeric ID assigned to the GitHub App during registration.
@@ -343,10 +359,6 @@ func (c *Client) CreateCheckRun(installationID int64, repo string, headSHA strin
343359

344360
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/check-runs", repo)
345361

346-
type ghCheckRunResponse struct {
347-
ID int64 `json:"id"`
348-
}
349-
350362
payload := map[string]interface{}{
351363
"name": name,
352364
"head_sha": headSHA,
@@ -400,14 +412,6 @@ func (c *Client) ListCheckRunsForRef(installationID int64, repo string, ref stri
400412
apiURL += "?check_name=" + url.QueryEscape(checkName)
401413
}
402414

403-
type ghCheckRun struct {
404-
ID int64 `json:"id"`
405-
Name string `json:"name"`
406-
}
407-
type ghCheckRunsResponse struct {
408-
CheckRuns []ghCheckRun `json:"check_runs"`
409-
}
410-
411415
result, err := httpclient.Request[ghCheckRunsResponse](c.httpClient, http.MethodGet, apiURL, headers, nil, http.StatusOK)
412416
if err != nil {
413417
return nil, err

0 commit comments

Comments
 (0)