Skip to content

Commit 33dd025

Browse files
committed
fix: remove PR comment code, add log_url to approval checks
- Remove FindPullRequestForBranch, CreateIssueComment, UpdateIssueComment, FindBotComment from GitHub client interface and implementations - Delete github_comment.go (PR comment reporter) - Remove all updatePRComment calls from deploy_handler.go - Add log_url to pending GitHub deployment status in approval flow so clicking the check on GitHub links to the dashboard approval page - Fix exhaustruct lint for seed/harness test files
1 parent 6672d38 commit 33dd025

File tree

9 files changed

+26
-293
lines changed

9 files changed

+26
-293
lines changed

svc/ctrl/integration/harness/harness.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func New(t *testing.T) *Harness {
173173
DB: database,
174174
Clickhouse: chClient,
175175
DefaultDomain: "test.example.com",
176+
DashboardURL: "https://app.unkey.com",
176177
Vault: vaultClient,
177178
SentinelImage: "test-sentinel:latest",
178179

svc/ctrl/integration/seed/seed.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,16 @@ func (h *Seeder) CreateProject(ctx context.Context, req CreateProjectRequest) db
146146
require.NoError(h.t, err)
147147

148148
return db.Project{
149-
ID: project.ID,
150-
WorkspaceID: project.WorkspaceID,
151-
Name: project.Name,
152-
Slug: project.Slug,
153-
DeleteProtection: project.DeleteProtection,
154-
CreatedAt: project.CreatedAt,
155-
UpdatedAt: project.UpdatedAt,
156-
Pk: 0,
157-
DepotProjectID: sql.NullString{String: "", Valid: false},
149+
ID: project.ID,
150+
WorkspaceID: project.WorkspaceID,
151+
Name: project.Name,
152+
Slug: project.Slug,
153+
DeleteProtection: project.DeleteProtection,
154+
DeploymentProtection: project.DeploymentProtection,
155+
CreatedAt: project.CreatedAt,
156+
UpdatedAt: project.UpdatedAt,
157+
Pk: 0,
158+
DepotProjectID: sql.NullString{String: "", Valid: false},
158159
}
159160
}
160161

svc/ctrl/worker/deploy/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ go_library(
1010
"deployment_step.go",
1111
"doc.go",
1212
"domains.go",
13-
"github_comment.go",
1413
"github_status.go",
1514
"promote_handler.go",
1615
"rollback_handler.go",

svc/ctrl/worker/deploy/deploy_handler.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -178,35 +178,7 @@ func (w *Workflow) Deploy(ctx restate.ObjectContext, req *hydrav1.DeployRequest)
178178
// --- GitHub Deployment Status ---
179179
// Look up repo connection to determine if we should report to GitHub.
180180
// Uses the interface so the noop is free — no nil checks needed.
181-
ghResult := w.createStatusReporter(ctx, deployment, project, app, environment, workspace)
182-
statusReporter := ghResult.reporter
183-
repoConn := ghResult.repoConn
184-
envURL := ghResult.environmentURL
185-
186-
// --- PR Comment ---
187-
// Post/update a Vercel-style deployment comment on the PR with status and preview URL.
188-
var prComment *prCommentReporter
189-
if ghResult.hasRepoConn && deployment.GitBranch.Valid {
190-
191-
prComment = newPRCommentReporter(ctx, w.github, repoConn.InstallationID, repoConn.RepositoryFullName, deployment.GitBranch.String)
192-
prComment.Update(ctx, []deploymentCommentRow{{
193-
Environment: environment.Slug,
194-
Status: "🔨 Building",
195-
PreviewURL: envURL,
196-
UpdatedAt: time.Now(),
197-
}})
198-
}
199-
200-
updatePRComment := func(status string) {
201-
if prComment != nil {
202-
prComment.Update(ctx, []deploymentCommentRow{{
203-
Environment: environment.Slug,
204-
Status: status,
205-
PreviewURL: envURL,
206-
UpdatedAt: time.Now(),
207-
}})
208-
}
209-
}
181+
statusReporter := w.createStatusReporter(ctx, deployment, project, app, environment, workspace).reporter
210182

211183
statusReporter.Report(ctx, "in_progress", "Building container image...")
212184

@@ -216,12 +188,10 @@ func (w *Workflow) Deploy(ctx restate.ObjectContext, req *hydrav1.DeployRequest)
216188
})
217189
if err != nil {
218190
statusReporter.Report(ctx, "failure", "Build failed")
219-
updatePRComment("❌ Failed (Build)")
220191
return nil, err
221192
}
222193

223194
statusReporter.Report(ctx, "in_progress", "Deploying to regions...")
224-
updatePRComment("🚀 Deploying")
225195

226196
// --- Deploy ---
227197
err = w.DeploymentStep(ctx, db.DeploymentStepsStepDeploying, deployment, func(stepCtx restate.ObjectContext) error {
@@ -247,7 +217,6 @@ func (w *Workflow) Deploy(ctx restate.ObjectContext, req *hydrav1.DeployRequest)
247217

248218
if err != nil {
249219
statusReporter.Report(ctx, "failure", "Deployment to regions failed")
250-
updatePRComment("❌ Failed (Deploy)")
251220
return nil, err
252221
}
253222

@@ -260,7 +229,6 @@ func (w *Workflow) Deploy(ctx restate.ObjectContext, req *hydrav1.DeployRequest)
260229
})
261230
if err != nil {
262231
statusReporter.Report(ctx, "failure", "Routing configuration failed")
263-
updatePRComment("❌ Failed (Routing)")
264232
return nil, err
265233
}
266234

@@ -284,12 +252,10 @@ func (w *Workflow) Deploy(ctx restate.ObjectContext, req *hydrav1.DeployRequest)
284252
})
285253
if err != nil {
286254
statusReporter.Report(ctx, "failure", "Finalization failed")
287-
updatePRComment("❌ Failed (Finalize)")
288255
return nil, err
289256
}
290257

291258
statusReporter.Report(ctx, "success", "Deployment is live")
292-
updatePRComment("✅ Ready")
293259

294260
logger.Info("deployment workflow completed",
295261
"deployment_id", deployment.ID,

svc/ctrl/worker/deploy/github_comment.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

svc/ctrl/worker/github/client.go

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -365,97 +365,3 @@ func (c *Client) IsCollaborator(installationID int64, repo string, username stri
365365
return value, nil
366366
}
367367

368-
// FindPullRequestForBranch finds an open pull request for the given branch.
369-
// Returns the PR number, or 0 if no open PR exists.
370-
func (c *Client) FindPullRequestForBranch(installationID int64, repo string, branch string) (int, error) {
371-
headers, err := c.ghHeaders(installationID)
372-
if err != nil {
373-
return 0, err
374-
}
375-
376-
parts := strings.SplitN(repo, "/", 2)
377-
if len(parts) != 2 {
378-
return 0, fault.New("invalid repo format, expected owner/repo")
379-
}
380-
owner := parts[0]
381-
382-
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/pulls?head=%s:%s&state=open&per_page=1",
383-
repo, url.QueryEscape(owner), url.QueryEscape(branch))
384-
385-
type ghPR struct {
386-
Number int `json:"number"`
387-
}
388-
389-
prs, err := httpclient.Request[[]ghPR](c.httpClient, http.MethodGet, apiURL, headers, nil, http.StatusOK)
390-
if err != nil {
391-
return 0, err
392-
}
393-
394-
if len(prs) == 0 {
395-
return 0, nil
396-
}
397-
398-
return prs[0].Number, nil
399-
}
400-
401-
// CreateIssueComment posts a comment on a GitHub issue or pull request.
402-
func (c *Client) CreateIssueComment(installationID int64, repo string, issueNumber int, body string) error {
403-
headers, err := c.ghHeaders(installationID)
404-
if err != nil {
405-
return err
406-
}
407-
408-
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/issues/%d/comments", repo, issueNumber)
409-
410-
return httpclient.Do(c.httpClient, http.MethodPost, apiURL, headers, map[string]string{"body": body}, http.StatusCreated)
411-
}
412-
413-
// UpdateIssueComment updates an existing comment on a GitHub issue or PR.
414-
func (c *Client) UpdateIssueComment(installationID int64, repo string, commentID int64, body string) error {
415-
headers, err := c.ghHeaders(installationID)
416-
if err != nil {
417-
return err
418-
}
419-
420-
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/issues/comments/%d", repo, commentID)
421-
422-
return httpclient.Do(c.httpClient, http.MethodPatch, apiURL, headers, map[string]string{"body": body}, http.StatusOK)
423-
}
424-
425-
// FindBotComment searches for a comment on a PR that contains the given marker
426-
// string. Returns the comment ID if found, or 0 if no matching comment exists.
427-
// Paginates through all comments to find it.
428-
func (c *Client) FindBotComment(installationID int64, repo string, issueNumber int, marker string) (int64, error) {
429-
headers, err := c.ghHeaders(installationID)
430-
if err != nil {
431-
return 0, err
432-
}
433-
434-
type ghComment struct {
435-
ID int64 `json:"id"`
436-
Body string `json:"body"`
437-
}
438-
439-
page := 1
440-
for {
441-
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/issues/%d/comments?per_page=100&page=%d", repo, issueNumber, page)
442-
443-
comments, reqErr := httpclient.Request[[]ghComment](c.httpClient, http.MethodGet, apiURL, headers, nil, http.StatusOK)
444-
if reqErr != nil {
445-
return 0, reqErr
446-
}
447-
448-
for _, comment := range comments {
449-
if strings.Contains(comment.Body, marker) {
450-
return comment.ID, nil
451-
}
452-
}
453-
454-
if len(comments) < 100 {
455-
break
456-
}
457-
page++
458-
}
459-
460-
return 0, nil
461-
}

svc/ctrl/worker/github/interface.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ type GitHubClient interface {
2727
// IsCollaborator checks whether a GitHub user is a collaborator on a repository.
2828
IsCollaborator(installationID int64, repo string, username string) (bool, error)
2929

30-
// FindPullRequestForBranch finds an open pull request for the given branch.
31-
// Returns the PR number, or 0 if no open PR exists.
32-
FindPullRequestForBranch(installationID int64, repo string, branch string) (int, error)
33-
34-
// CreateIssueComment posts a comment on a GitHub issue or pull request.
35-
CreateIssueComment(installationID int64, repo string, issueNumber int, body string) error
36-
37-
// UpdateIssueComment updates an existing comment on a GitHub issue or PR.
38-
UpdateIssueComment(installationID int64, repo string, commentID int64, body string) error
39-
40-
// FindBotComment searches for a comment on a PR that contains the given marker string.
41-
// Returns the comment ID if found, or 0 if no matching comment exists.
42-
FindBotComment(installationID int64, repo string, issueNumber int, marker string) (int64, error)
4330
}
4431

4532
// CommitInfo holds metadata about a single Git commit retrieved from the GitHub API.

svc/ctrl/worker/github/noop.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,6 @@ func (n *Noop) IsCollaborator(_ int64, _ string, _ string) (bool, error) {
4949
return false, errNotConfigured
5050
}
5151

52-
// FindPullRequestForBranch returns an error indicating GitHub is not configured.
53-
func (n *Noop) FindPullRequestForBranch(_ int64, _ string, _ string) (int, error) {
54-
return 0, errNotConfigured
55-
}
56-
57-
// CreateIssueComment returns an error indicating GitHub is not configured.
58-
func (n *Noop) CreateIssueComment(_ int64, _ string, _ int, _ string) error {
59-
return errNotConfigured
60-
}
61-
62-
// UpdateIssueComment returns an error indicating GitHub is not configured.
63-
func (n *Noop) UpdateIssueComment(_ int64, _ string, _ int64, _ string) error {
64-
return errNotConfigured
65-
}
66-
67-
// FindBotComment returns an error indicating GitHub is not configured.
68-
func (n *Noop) FindBotComment(_ int64, _ string, _ int, _ string) (int64, error) {
69-
return 0, errNotConfigured
70-
}
71-
7252
// GetBranchHeadCommitPublic retrieves the HEAD commit using the public GitHub
7353
// API without authentication. Works for public repositories even when GitHub
7454
// App credentials are not configured.

0 commit comments

Comments
 (0)