Skip to content

Updates#750

Merged
slugb0t merged 4 commits intonext-previewfrom
next-remove
Mar 12, 2026
Merged

Updates#750
slugb0t merged 4 commits intonext-previewfrom
next-remove

Conversation

@slugb0t
Copy link
Member

@slugb0t slugb0t commented Mar 12, 2026

Summary by Sourcery

Extend preview deployment workflow to notify pull requests about preview environment status on open and ensure deployments are fully cleaned up on removal.

CI:

  • Trigger the deploy-preview-app workflow on pull request open and reopen events in addition to close.
  • Add a job that comments or updates a status message on pull requests with the current preview deployment state and URL.
  • Use a personal access token when managing preview deployments and delete deployment records after marking environments inactive.

@slugb0t slugb0t requested a review from megasanjay as a code owner March 12, 2026 00:16
@fairdataihub-bot
Copy link

Thank you for submitting this pull request! We appreciate your contribution to the project. Before we can merge it, we need to review the changes you've made to ensure they align with our code standards and meet the requirements of the project. We'll get back to you as soon as we can with feedback. Thanks again!

@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)
fairdataihub-website Ready Ready Preview, Comment Mar 12, 2026 0:25am

Request Review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 12, 2026

Reviewer's Guide

Extends the preview app deployment workflow to react to pull request openings/reopenings, adds a notification job that comments/upserts preview environment status on the PR, and strengthens cleanup by using a PAT (if available) and deleting the corresponding deployment when the preview is removed.

Sequence diagram for PR open/reopen preview status comment workflow

sequenceDiagram
    actor Developer
    participant GitHub
    participant DeployPreviewWorkflow
    participant NotifyPROnOpenJob
    participant GitHubAPI
    participant PullRequest

    Developer->>GitHub: Open_or_reopen_PR(branch)
    GitHub-->>DeployPreviewWorkflow: pull_request_event(opened_or_reopened)
    DeployPreviewWorkflow-->>NotifyPROnOpenJob: Start_job_if_branch_not_main_or_next

    NotifyPROnOpenJob->>NotifyPROnOpenJob: Compute_BRANCH_SLUG
    NotifyPROnOpenJob->>NotifyPROnOpenJob: Set_KAMAL_APP_NAME_and_KAMAL_APP_DOMAIN

    NotifyPROnOpenJob->>GitHubAPI: listDeployments(environment=KAMAL_APP_NAME, per_page=1)
    GitHubAPI-->>NotifyPROnOpenJob: deployments

    alt Deployment_exists
        NotifyPROnOpenJob->>GitHubAPI: listDeploymentStatuses(deployment_id, per_page=1)
        GitHubAPI-->>NotifyPROnOpenJob: statuses
        alt state_success
            NotifyPROnOpenJob->>NotifyPROnOpenJob: Build_body_preview_ready_with_URL_and_timestamp
        else state_in_progress
            NotifyPROnOpenJob->>NotifyPROnOpenJob: Build_body_preview_in_progress
        else other_state
            NotifyPROnOpenJob->>NotifyPROnOpenJob: Build_body_preview_after_next_push
        end
    else No_deployments
        NotifyPROnOpenJob->>NotifyPROnOpenJob: Build_body_preview_after_next_push
    end

    NotifyPROnOpenJob->>GitHubAPI: listComments(issue_number)
    GitHubAPI-->>NotifyPROnOpenJob: comments

    alt Existing_preview_comment_found
        NotifyPROnOpenJob->>GitHubAPI: updateComment(comment_id, body)
    else No_existing_preview_comment
        NotifyPROnOpenJob->>GitHubAPI: createComment(issue_number, body)
    end

    GitHubAPI-->>PullRequest: Updated_or_new_preview_status_comment
Loading

Sequence diagram for PR close preview cleanup and deployment deletion

sequenceDiagram
    actor Developer
    participant GitHub
    participant DeployPreviewWorkflow
    participant RemovePreviewJob
    participant GitHubAPI
    participant PreviewDeployment

    Developer->>GitHub: Close_PR
    GitHub-->>DeployPreviewWorkflow: pull_request_event(closed)
    DeployPreviewWorkflow-->>RemovePreviewJob: Start_remove_preview_job

    RemovePreviewJob->>GitHubAPI: listDeployments(environment=KAMAL_APP_NAME)
    GitHubAPI-->>RemovePreviewJob: deployments

    loop For_each_deployment
        RemovePreviewJob->>GitHubAPI: createDeploymentStatus(deployment_id, state=inactive, description=Preview_environment_removed)
        GitHubAPI-->>PreviewDeployment: Mark_inactive
        RemovePreviewJob->>GitHubAPI: deleteDeployment(deployment_id)
        GitHubAPI-->>RemovePreviewJob: Deployment_deleted
    end
Loading

File-Level Changes

Change Details Files
Trigger the workflow on PR open/reopen events rather than only on close.
  • Expand pull_request trigger types to include opened and reopened in addition to closed so the workflow runs earlier in the PR lifecycle
.github/workflows/deploy-preview-app.yml
Add a job that posts or updates a PR comment with the preview environment status when a PR is opened or reopened.
  • Add notify-pr-on-open job conditioned on pull_request opened/reopened events and excluding main/next branches
  • Derive a sanitized branch-based preview app name and domain and export them via GITHUB_ENV
  • Use actions/github-script to find the latest deployment for the preview environment and inspect its status
  • Generate user-facing markdown messaging for success, in-progress, or pending preview deployments
  • Idempotently create or update a bot comment starting with '## Preview deployment' on the PR
.github/workflows/deploy-preview-app.yml
Harden preview removal by using a PAT when available and deleting the associated deployment objects.
  • Switch the GitHub token used in the cleanup github-script step to prefer GH_PAT over GITHUB_TOKEN
  • After marking preview deployments inactive, also call deleteDeployment to remove the deployment records
.github/workflows/deploy-preview-app.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Preview deployment ready

Preview URL: https://website-next-remove.fairdataihub.org

Last deployed: Thu, 12 Mar 2026 00:27:47 GMT

@fairdataihub-bot
Copy link

Thanks for making updates to your pull request. Our team will take a look and provide feedback as soon as possible. Please wait for any GitHub Actions to complete before editing your pull request. If you have any additional questions or concerns, feel free to let us know. Thank you for your contributions!

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The branch-to-KAMAL_APP_NAME/KAMAL_APP_DOMAIN slug generation logic is duplicated in the new notify-pr-on-open job; consider extracting this into a single shared step or composite action to avoid future drift between jobs.
  • The logic for finding an existing preview comment relies on c.user.type === 'Bot', which will miss comments created via a PAT or non-bot user; using a more robust marker (e.g., a hidden HTML comment or a stricter body prefix) would make comment updates more reliable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The branch-to-`KAMAL_APP_NAME`/`KAMAL_APP_DOMAIN` slug generation logic is duplicated in the new `notify-pr-on-open` job; consider extracting this into a single shared step or composite action to avoid future drift between jobs.
- The logic for finding an existing preview comment relies on `c.user.type === 'Bot'`, which will miss comments created via a PAT or non-bot user; using a more robust marker (e.g., a hidden HTML comment or a stricter body prefix) would make comment updates more reliable.

## Individual Comments

### Comment 1
<location path=".github/workflows/deploy-preview-app.yml" line_range="296-297" />
<code_context>
+              issue_number,
+            });
+
+            const existing = comments.find(
+              c => c.user.type === 'Bot' && c.body.startsWith('## Preview deployment')
+            );
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Comment-matching logic may fail when using a PAT, causing duplicate preview comments.

The `c.user.type === 'Bot'` check only matches GitHub App bots (e.g. `github-actions[bot]`). With `GH_PAT`, `c.user.type` will be `'User'`, so existing preview comments won’t be found and a new one will be created on each PR open/reopen. Relax this filter (e.g. rely on `body.startsWith('## Preview deployment')` and/or check `c.user.login` against the expected account) so the workflow updates the existing comment instead of duplicating it.
</issue_to_address>

### Comment 2
<location path=".github/workflows/deploy-preview-app.yml" line_range="414-418" />
<code_context>
                 state: 'inactive',
                 description: 'Preview environment removed'
               });
+              await github.rest.repos.deleteDeployment({
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                deployment_id: deployment.id
+              });
             }

</code_context>
<issue_to_address>
**suggestion (bug_risk):** Uncaught errors from deleteDeployment can fail the cleanup job unnecessarily.

This call isn’t guarded like the later cleanup steps. If it throws (e.g., 404, permission error, transient API issue), the job will fail even though the deployment is already marked inactive. Please wrap this in try/catch or handle expected statuses (like 404/409) so best-effort cleanup doesn’t cause the overall workflow to fail.

```suggestion
              try {
                await github.rest.repos.deleteDeployment({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  deployment_id: deployment.id
                });
              } catch (error) {
                if (error && (error.status === 404 || error.status === 409)) {
                  // Deployment already gone or in a conflicting state – ignore
                  core?.info
                    ? core.info(`Non-fatal error deleting deployment ${deployment.id}: ${error.status}`)
                    : console.warn(`Non-fatal error deleting deployment ${deployment.id}:`, error);
                } else {
                  // Best-effort cleanup: log but do not fail the job
                  core?.warning
                    ? core.warning(`Failed to delete deployment ${deployment.id}: ${error.message || error}`)
                    : console.warn(`Failed to delete deployment ${deployment.id}:`, error);
                }
              }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +414 to +418
await github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Uncaught errors from deleteDeployment can fail the cleanup job unnecessarily.

This call isn’t guarded like the later cleanup steps. If it throws (e.g., 404, permission error, transient API issue), the job will fail even though the deployment is already marked inactive. Please wrap this in try/catch or handle expected statuses (like 404/409) so best-effort cleanup doesn’t cause the overall workflow to fail.

Suggested change
await github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
try {
await github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
} catch (error) {
if (error && (error.status === 404 || error.status === 409)) {
// Deployment already gone or in a conflicting state – ignore
core?.info
? core.info(`Non-fatal error deleting deployment ${deployment.id}: ${error.status}`)
: console.warn(`Non-fatal error deleting deployment ${deployment.id}:`, error);
} else {
// Best-effort cleanup: log but do not fail the job
core?.warning
? core.warning(`Failed to delete deployment ${deployment.id}: ${error.message || error}`)
: console.warn(`Failed to delete deployment ${deployment.id}:`, error);
}
}

@slugb0t slugb0t merged commit 6baf921 into next-preview Mar 12, 2026
4 of 6 checks passed
@slugb0t slugb0t deleted the next-remove branch March 12, 2026 00:25
@fairdataihub-bot
Copy link

Thanks for closing this pull request! If you have any further questions, please feel free to open a new issue. We are always happy to help!

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.

1 participant