Skip to content

Commit 6672d38

Browse files
committed
fix: remove approval PR comment, rely on GitHub deployment status only
Remove the PR comment for approval-gated deployments. The GitHub Deployment pending status already shows in the PR sidebar — no separate comment needed. Removes unused fmt import.
1 parent 01d36bb commit 6672d38

File tree

1 file changed

+0
-79
lines changed

1 file changed

+0
-79
lines changed

svc/ctrl/worker/githubwebhook/handle_push.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package githubwebhook
33
import (
44
"context"
55
"database/sql"
6-
"fmt"
76
"os"
87
"strings"
98
"time"
@@ -223,8 +222,6 @@ func (s *Service) HandlePush(ctx restate.ObjectContext, req *hydrav1.HandlePushR
223222
}, restate.WithName("github deployment status: pending"), restate.WithMaxRetryDuration(30*time.Second))
224223
}
225224

226-
// Post PR comment if we can find an open PR for this branch
227-
s.postApprovalComment(ctx, req, repo, deploymentID)
228225
continue
229226
}
230227

@@ -299,79 +296,3 @@ func (s *Service) requiresApproval(
299296
return !isCollaborator
300297
}
301298

302-
// approvalCommentMarker is a hidden HTML comment used to find and update
303-
// the approval comment instead of posting duplicate comments on each push.
304-
const approvalCommentMarker = "<!-- unkey-approval-comment -->"
305-
306-
// postApprovalComment finds an open PR for the branch and posts (or updates)
307-
// an authorization comment. Fire-and-forget — errors are logged but don't block.
308-
func (s *Service) postApprovalComment(
309-
ctx restate.ObjectContext,
310-
req *hydrav1.HandlePushRequest,
311-
repo db.GithubRepoConnection,
312-
deploymentID string,
313-
) {
314-
prNumber, err := restate.Run(ctx, func(_ restate.RunContext) (int, error) {
315-
return s.github.FindPullRequestForBranch(
316-
repo.InstallationID,
317-
req.GetRepositoryFullName(),
318-
req.GetBranch(),
319-
)
320-
}, restate.WithName("find PR for branch"), restate.WithMaxRetryDuration(30*time.Second))
321-
if err != nil {
322-
logger.Error("failed to find PR for approval comment", "error", err)
323-
return
324-
}
325-
326-
if prNumber == 0 {
327-
logger.Info("no open PR found for branch, skipping approval comment",
328-
"branch", req.GetBranch(),
329-
"deployment_id", deploymentID,
330-
)
331-
return
332-
}
333-
334-
comment := fmt.Sprintf(
335-
approvalCommentMarker+"\n"+
336-
"**Deployment Authorization Required**\n\n"+
337-
"This deployment was triggered by @%s who is not a collaborator on this repository.\n\n"+
338-
"A project member must authorize this deployment before it will proceed.\n\n"+
339-
"[Authorize Deployment](%s/deployments/%s/approve)",
340-
req.GetSenderLogin(),
341-
s.dashboardURL,
342-
deploymentID,
343-
)
344-
345-
// Try to find an existing approval comment to update
346-
existingID, findErr := restate.Run(ctx, func(_ restate.RunContext) (int64, error) {
347-
return s.github.FindBotComment(
348-
repo.InstallationID,
349-
req.GetRepositoryFullName(),
350-
prNumber,
351-
approvalCommentMarker,
352-
)
353-
}, restate.WithName("find existing approval comment"), restate.WithMaxRetryDuration(30*time.Second))
354-
if findErr != nil {
355-
logger.Info("could not search for existing approval comment", "error", findErr)
356-
}
357-
358-
if existingID > 0 {
359-
_ = restate.RunVoid(ctx, func(_ restate.RunContext) error {
360-
return s.github.UpdateIssueComment(
361-
repo.InstallationID,
362-
req.GetRepositoryFullName(),
363-
existingID,
364-
comment,
365-
)
366-
}, restate.WithName("update approval comment"), restate.WithMaxRetryDuration(30*time.Second))
367-
} else {
368-
_ = restate.RunVoid(ctx, func(_ restate.RunContext) error {
369-
return s.github.CreateIssueComment(
370-
repo.InstallationID,
371-
req.GetRepositoryFullName(),
372-
prNumber,
373-
comment,
374-
)
375-
}, restate.WithName("post approval comment"), restate.WithMaxRetryDuration(30*time.Second))
376-
}
377-
}

0 commit comments

Comments
 (0)