Skip to content

feat: add PR comment for deployment status#5295

Merged
Flo4604 merged 5 commits intomainfrom
feat/pr-deployment-comment
Mar 19, 2026
Merged

feat: add PR comment for deployment status#5295
Flo4604 merged 5 commits intomainfrom
feat/pr-deployment-comment

Conversation

@Flo4604
Copy link
Member

@Flo4604 Flo4604 commented Mar 12, 2026

What does this PR do?

Refactors GitHub deployment status reporting by extracting it from the deploy service into a dedicated GitHubStatusService virtual object. This new service manages both GitHub Deployments API status updates and PR comment creation/updates in a single, stateful component.

The implementation includes:

  • A new GitHubStatusService virtual object keyed by deployment ID that persists GitHub deployment IDs and PR comment IDs in Restate state
  • Init method that creates GitHub deployments and PR comments with deployment status tables
  • ReportStatus method that updates both GitHub deployment status and PR comment rows
  • GitHub API client methods for PR operations: finding PRs by branch, creating/updating issue comments, and searching for existing bot comments
  • Automatic PR comment management with markdown tables showing deployment status for each app/environment combination
  • Removal of the old UpdateGitHubDeploymentStatus RPC method and related status reporter classes

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Create a pull request with deployment configuration
  • Trigger a deployment workflow for the PR
  • Verify that a GitHub deployment is created and a deployment comment appears on the PR with the correct table format
  • Run multiple deployments for different apps/environments on the same PR
  • Confirm that each deployment gets its own row in the shared comment table
  • Test deployment status updates (pending → in_progress → success/failure) and verify both the GitHub deployment status and PR comment rows update accordingly
  • Verify that existing GitHub deployments (created during approval flow) are properly reused

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Mar 19, 2026 5:46pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b79d93de-4a7f-44bd-a2e1-d2ed31c3c1f2

📥 Commits

Reviewing files that changed from the base of the PR and between 5c78173 and 8c87fd5.

⛔ Files ignored due to path filters (5)
  • gen/proto/hydra/v1/BUILD.bazel is excluded by !**/gen/**
  • gen/proto/hydra/v1/deploy.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • gen/proto/hydra/v1/deploy_restate.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • gen/proto/hydra/v1/github_status.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • gen/proto/hydra/v1/github_status_restate.pb.go is excluded by !**/*.pb.go, !**/gen/**
📒 Files selected for processing (21)
  • svc/api/internal/testutil/seed/seed.go
  • svc/ctrl/integration/harness.go
  • svc/ctrl/proto/hydra/v1/deploy.proto
  • svc/ctrl/proto/hydra/v1/github_status.proto
  • svc/ctrl/services/deployment/create_deployment.go
  • svc/ctrl/worker/BUILD.bazel
  • svc/ctrl/worker/deploy/BUILD.bazel
  • svc/ctrl/worker/deploy/deploy_handler.go
  • svc/ctrl/worker/deploy/status_reporter.go
  • svc/ctrl/worker/deploy/status_reporter_github.go
  • svc/ctrl/worker/deploy/status_reporter_noop.go
  • svc/ctrl/worker/deploy/update_github_deployment_status_handler.go
  • svc/ctrl/worker/github/client.go
  • svc/ctrl/worker/github/interface.go
  • svc/ctrl/worker/github/noop.go
  • svc/ctrl/worker/githubstatus/BUILD.bazel
  • svc/ctrl/worker/githubstatus/comment.go
  • svc/ctrl/worker/githubstatus/init_handler.go
  • svc/ctrl/worker/githubstatus/report_handler.go
  • svc/ctrl/worker/githubstatus/service.go
  • svc/ctrl/worker/run.go

📝 Walkthrough

Walkthrough

This PR refactors GitHub deployment status reporting from an inline handler pattern to a dedicated Restate virtual object service. The old UpdateGitHubDeploymentStatus RPC and status-reporter implementations are removed. A new GitHubStatusService is introduced with Init and ReportStatus RPCs to manage deployment lifecycle (create/update statuses and PR comments). The deploy workflow is updated to use this new service, and the GitHub client gains PR and comment management methods.

Changes

Cohort / File(s) Summary
SQL null initialization
svc/api/internal/testutil/seed/seed.go, svc/ctrl/integration/harness.go, svc/ctrl/services/deployment/create_deployment.go
Explicitly initialize sql.NullInt64 and sql.NullString fields with Valid: false to clarify null state for PrNumber and ForkRepositoryFullName.
Proto definitions
svc/ctrl/proto/hydra/v1/deploy.proto, svc/ctrl/proto/hydra/v1/github_status.proto
Removed UpdateGitHubDeploymentStatus RPC and related messages from deploy.proto. Added new GitHubStatusService with Init and ReportStatus RPCs, plus GitHubDeploymentState enum and request/response messages in new github_status.proto.
GitHub status service implementation
svc/ctrl/worker/githubstatus/service.go, svc/ctrl/worker/githubstatus/init_handler.go, svc/ctrl/worker/githubstatus/report_handler.go, svc/ctrl/worker/githubstatus/comment.go
New Restate virtual object service for GitHub deployment tracking. Init creates deployments and PR comments; ReportStatus updates both with fire-and-forget semantics. comment.go provides PR comment formatting and upsert logic.
Old status reporter removal
svc/ctrl/worker/deploy/status_reporter.go, svc/ctrl/worker/deploy/status_reporter_github.go, svc/ctrl/worker/deploy/status_reporter_noop.go, svc/ctrl/worker/deploy/update_github_deployment_status_handler.go
Deleted interface-based status reporter pattern and handler for updating GitHub deployments via RPC.
Deploy workflow refactoring
svc/ctrl/worker/deploy/deploy_handler.go
Replaced statusReporter.Report(...) calls with ghStatus.ReportStatus().Send(...) to use new service. Added initGitHubStatus helper to initialize the service and emit status transitions at workflow boundaries. Added formatEnvironmentLabel and formatDomainPrefix helpers.
GitHub client enhancements
svc/ctrl/worker/github/client.go, svc/ctrl/worker/github/interface.go, svc/ctrl/worker/github/noop.go
Extended GitHubClient with PR and comment methods: FindPullRequestForBranch, CreateIssueComment, UpdateIssueComment, FindBotComment. Noop client returns errNotConfigured for new methods.
Build configuration
svc/ctrl/worker/BUILD.bazel, svc/ctrl/worker/deploy/BUILD.bazel, svc/ctrl/worker/githubstatus/BUILD.bazel
Added new githubstatus Bazel target and dependency. Removed deleted status reporter files from deploy target srcs.
Service registration
svc/ctrl/worker/run.go
Registered new GitHubStatusService with Restate server alongside other hydra services.

Sequence Diagram(s)

sequenceDiagram
    participant DW as Deploy Workflow
    participant GS as GitHubStatusService
    participant GC as GitHub Client
    participant DB as Database
    participant GA as GitHub API

    DW->>GS: Init (repo, commit, branch, pr_number)
    activate GS
    GS->>DB: Load repo connection
    GS->>GA: Create deployment (if no existing ID)
    GA-->>GS: GitHub deployment ID
    GS->>DB: Update deployment with GitHub ID
    GS->>GC: Find PR by branch
    GC->>GA: Query pull requests
    GA-->>GC: PR number
    GC-->>GS: PR number
    GS->>GC: Find or create PR comment
    GC->>GA: GET/POST comment
    GA-->>GC: Comment ID
    GC-->>GS: Comment ID
    GS->>DB: Store GitHub IDs in Restate state
    GS-->>DW: Init complete
    deactivate GS

    loop At each workflow boundary
        DW->>GS: ReportStatus (state, description)
        activate GS
        GS->>DB: Read persisted config & IDs
        alt GitHub deployment exists
            GS->>GA: CreateDeploymentStatus (state, description)
            GA-->>GS: Status updated (no-wait)
        end
        alt PR comment exists
            GS->>GC: UpdateIssueComment (new row)
            GC->>GA: PATCH comment
            GA-->>GC: Comment updated (no-wait)
            GC-->>GS: Done
        end
        GS-->>DW: ReportStatus complete
        deactivate GS
    end
Loading
sequenceDiagram
    participant OldDW as Deploy Workflow (Old)
    participant SR as StatusReporter (Old)
    participant GH as GitHub API
    participant DB as Database

    OldDW->>SR: Create/Report status
    activate SR
    SR->>DB: Load repo connection
    SR->>GH: CreateDeploymentStatus
    GH-->>SR: Response
    SR-->>OldDW: Done
    deactivate SR

    participant NewDW as Deploy Workflow (New)
    participant NGS as GitHubStatusService (New)
    participant NGC as GitHub Client (New)

    NewDW->>NGS: ReportStatus (fire-and-forget)
    activate NGS
    NGS->>NGC: CreateDeploymentStatus & UpdateIssueComment
    NGC->>GH: Parallel requests
    GH-->>NGC: Responses (logged, not returned)
    NGC-->>NGS: Done
    NGS-->>NewDW: Returns immediately
    deactivate NGS
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pr-deployment-comment
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Command failed


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member Author

Flo4604 commented Mar 12, 2026

@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from 1f59d61 to a0f9eb8 Compare March 12, 2026 17:14
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 7bcd633 to 3ded3ce Compare March 12, 2026 17:14
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from a0f9eb8 to fdc18b3 Compare March 13, 2026 13:44
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 3ded3ce to b0fd3be Compare March 13, 2026 13:44
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from b0fd3be to a0effc8 Compare March 13, 2026 13:59
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from fdc18b3 to 5e195ef Compare March 13, 2026 13:59
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from a0effc8 to 2c18337 Compare March 13, 2026 14:34
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from 764db6e to 1ce4525 Compare March 13, 2026 14:34
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from 5c41b85 to 4df0fab Compare March 16, 2026 11:24
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 2c18337 to 468c209 Compare March 16, 2026 11:24
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 468c209 to dc1627b Compare March 16, 2026 11:31
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from 4df0fab to 943b341 Compare March 16, 2026 11:31
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from dc1627b to 3e055d9 Compare March 16, 2026 11:52
@Flo4604 Flo4604 force-pushed the feat/deployment-approval-ui branch from 01db7ed to 36a3aed Compare March 16, 2026 11:52
Base automatically changed from feat/deployment-approval-ui to feat/external-contributor-protection March 16, 2026 11:58
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 3e055d9 to d8f659b Compare March 16, 2026 12:00
@Flo4604 Flo4604 force-pushed the feat/external-contributor-protection branch from 1425f22 to 8ca4d20 Compare March 19, 2026 11:14
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 939c7dc to 4557f1b Compare March 19, 2026 11:14
@Flo4604 Flo4604 force-pushed the feat/external-contributor-protection branch from 8b4f652 to c909b42 Compare March 19, 2026 16:11
@Flo4604 Flo4604 force-pushed the feat/pr-deployment-comment branch from 4557f1b to 3134e2f Compare March 19, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants