Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix: updated action to include state (#40385)

Ali Waseem23c7c8c63e14
diff --git a/.github/workflows/dashboard-pr-reminder.yml b/.github/workflows/dashboard-pr-reminder.yml
index 4ba62a53844..876b0d6c4ab 100644
--- a/.github/workflows/dashboard-pr-reminder.yml
+++ b/.github/workflows/dashboard-pr-reminder.yml
@@ -16,114 +16,16 @@ jobs:
check-dashboard-prs:
runs-on: ubuntu-latest
steps:
+ - name: Checkout repository
+ uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
+
- name: Find Dashboard PRs older than 24 hours
id: find-prs
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
- const TWENTY_FOUR_HOURS_AGO = new Date(Date.now() - 24 * 60 * 60 * 1000);
- const DASHBOARD_PATH = 'apps/studio/';
-
- console.log(`Looking for PRs older than: ${TWENTY_FOUR_HOURS_AGO.toISOString()}`);
-
- const stalePRs = [];
- let page = 1;
- let hasMore = true;
-
- // Fetch PRs page by page, newest first
- while (hasMore && page <= 10) { // Limit to 10 pages (1000 PRs) as safety measure
- console.log(`Fetching page ${page}...`);
-
- const { data: prs } = await github.rest.pulls.list({
- owner: context.repo.owner,
- repo: context.repo.repo,
- state: 'open',
- sort: 'created',
- direction: 'desc',
- per_page: 100,
- page: page
- });
-
- if (prs.length === 0) {
- hasMore = false;
- break;
- }
-
- // Check each PR
- for (const pr of prs) {
- // Skip PRs from forks - only check internal PRs
- if (pr.head.repo && pr.head.repo.full_name !== context.repo.owner + '/' + context.repo.repo) {
- console.log(`PR #${pr.number} is from a fork, skipping...`);
- continue;
- }
-
- // Skip dependabot PRs
- if (pr.user.login === 'dependabot[bot]' || pr.user.login === 'dependabot') {
- console.log(`PR #${pr.number} is from dependabot, skipping...`);
- continue;
- }
-
- // Skip draft PRs
- if (pr.draft) {
- console.log(`PR #${pr.number} is a draft, skipping...`);
- continue;
- }
-
- const createdAt = new Date(pr.created_at);
-
- // If this PR is newer than 24 hours, skip it
- if (createdAt > TWENTY_FOUR_HOURS_AGO) {
- console.log(`PR #${pr.number} is too new, skipping...`);
- continue;
- }
-
- // If we've reached PRs older than what we're checking, we can stop
- // But we still need to check if they touch Dashboard files
- console.log(`Checking PR #${pr.number}: ${pr.title}`);
-
- // Fetch files changed in this PR
- const { data: files } = await github.rest.pulls.listFiles({
- owner: context.repo.owner,
- repo: context.repo.repo,
- pull_number: pr.number,
- per_page: 100
- });
-
- // Check if any file is under apps/studio/
- const touchesDashboard = files.some(file => file.filename.startsWith(DASHBOARD_PATH));
-
- if (touchesDashboard) {
- const hoursOld = Math.floor((Date.now() - createdAt.getTime()) / (1000 * 60 * 60));
- const daysOld = Math.floor(hoursOld / 24);
-
- stalePRs.push({
- number: pr.number,
- title: pr.title,
- url: pr.html_url,
- author: pr.user.login,
- createdAt: pr.created_at,
- hoursOld: hoursOld,
- daysOld: daysOld,
- fileCount: files.filter(f => f.filename.startsWith(DASHBOARD_PATH)).length
- });
-
- console.log(`✓ Found stale Dashboard PR #${pr.number}`);
- }
- }
-
- page++;
- }
-
- console.log(`Found ${stalePRs.length} stale Dashboard PRs`);
-
- // Sort by age (oldest first)
- stalePRs.sort((a, b) => a.hoursOld - b.hoursOld);
-
- // Store results for next step
- core.setOutput('stale_prs', JSON.stringify(stalePRs));
- core.setOutput('count', stalePRs.length);
-
- return stalePRs;
+ const findStalePRs = require('./scripts/actions/find-stale-dashboard-prs.js');
+ return await findStalePRs({ github, context, core });
- name: Send Slack notification
if: fromJSON(steps.find-prs.outputs.count) > 0
@@ -133,87 +35,10 @@ jobs:
STALE_PRS_JSON: ${{ steps.find-prs.outputs.stale_prs }}
with:
script: |
+ const sendSlackNotification = require('./scripts/actions/send-slack-pr-notification.js');
const stalePRs = JSON.parse(process.env.STALE_PRS_JSON);
- const count = stalePRs.length;
-
- // Build PR blocks with proper escaping for Slack mrkdwn
- const prBlocks = stalePRs.map(pr => {
- // Format age display
- const remainingHours = pr.hoursOld % 24;
- const ageText = pr.daysOld > 0
- ? `${pr.daysOld}d ${remainingHours}h`
- : `${pr.hoursOld}h`;
-
- // Escape special characters for Slack mrkdwn (escape &, <, >)
- const escapeSlack = (text) => {
- return text
- .replace(/&/g, '&amp;')
- .replace(/</g, '&lt;')
- .replace(/>/g, '&gt;');
- };
-
- // Truncate title if too long (max 3000 chars for entire text field)
- const maxTitleLength = 200;
- const safeTitle = pr.title.length > maxTitleLength
- ? escapeSlack(pr.title.substring(0, maxTitleLength) + '...')
- : escapeSlack(pr.title);
-
- return {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `*<${pr.url}|#${pr.number}: ${safeTitle}>*\n:bust_in_silhouette: @${pr.author} • :clock3: ${ageText} old • :file_folder: ${pr.fileCount} Dashboard files`
- }
- };
- });
-
- // Slack has a 50 block limit, we use 3 for header/intro/divider
- // So we can show max 47 PRs
- const MAX_PRS_TO_SHOW = 47;
- const prBlocksToShow = prBlocks.slice(0, MAX_PRS_TO_SHOW);
- const hasMorePRs = prBlocks.length > MAX_PRS_TO_SHOW;
-
- // Build complete Slack message
- const slackMessage = {
- text: "Dashboard PRs needing attention",
- blocks: [
- {
- type: "header",
- text: {
- type: "plain_text",
- text: "Dashboard PRs Older Than 24 Hours"
- }
- },
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `There are *${count}* open PRs affecting /apps/studio/ that are older than 24 hours:${hasMorePRs ? ` (showing first ${MAX_PRS_TO_SHOW})` : ''}`
- }
- },
- {
- type: "divider"
- },
- ...prBlocksToShow
- ]
- };
-
- // Send to Slack
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
- const response = await fetch(webhookUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(slackMessage)
- });
-
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(`Slack notification failed: ${response.status} ${response.statusText}\n${errorText}`);
- }
-
- console.log('✓ Slack notification sent successfully!');
+ await sendSlackNotification(stalePRs, webhookUrl);
- name: No stale PRs found
if: fromJSON(steps.find-prs.outputs.count) == 0
diff --git a/scripts/actions/find-stale-dashboard-prs.js b/scripts/actions/find-stale-dashboard-prs.js
new file mode 100644
index 00000000000..afd0d2efc85
--- /dev/null
+++ b/scripts/actions/find-stale-dashboard-prs.js
@@ -0,0 +1,214 @@
+/**
+ * Finds stale Dashboard PRs (older than 24 hours) and fetches their status
+ * including review status and mergeable state.
+ *
+ * @param {Object} github - GitHub API client from actions/github-script
+ * @param {Object} context - GitHub Actions context
+ * @param {Object} core - GitHub Actions core utilities
+ * @returns {Array} Array of stale PRs with status information
+ */
+module.exports = async ({ github, context, core }) => {
+ const TWENTY_FOUR_HOURS_AGO = new Date(Date.now() - 24 * 60 * 60 * 1000)
+ const DASHBOARD_PATH = 'apps/studio/'
+
+ console.log(`Looking for PRs older than: ${TWENTY_FOUR_HOURS_AGO.toISOString()}`)
+
+ const stalePRs = []
+ let page = 1
+ let hasMore = true
+
+ // Fetch PRs page by page, newest first
+ while (hasMore && page <= 10) {
+ // Limit to 10 pages (1000 PRs) as safety measure
+ console.log(`Fetching page ${page}...`)
+
+ const { data: prs } = await github.rest.pulls.list({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'open',
+ sort: 'created',
+ direction: 'desc',
+ per_page: 100,
+ page: page,
+ })
+
+ if (prs.length === 0) {
+ hasMore = false
+ break
+ }
+
+ // Check each PR
+ for (const pr of prs) {
+ // Skip PRs from forks - only check internal PRs
+ if (pr.head.repo && pr.head.repo.full_name !== context.repo.owner + '/' + context.repo.repo) {
+ console.log(`PR #${pr.number} is from a fork, skipping...`)
+ continue
+ }
+
+ // Skip dependabot PRs
+ if (pr.user.login === 'dependabot[bot]' || pr.user.login === 'dependabot') {
+ console.log(`PR #${pr.number} is from dependabot, skipping...`)
+ continue
+ }
+
+ // Skip draft PRs
+ if (pr.draft) {
+ console.log(`PR #${pr.number} is a draft, skipping...`)
+ continue
+ }
+
+ const createdAt = new Date(pr.created_at)
+
+ // If this PR is newer than 24 hours, skip it
+ if (createdAt > TWENTY_FOUR_HOURS_AGO) {
+ console.log(`PR #${pr.number} is too new, skipping...`)
+ continue
+ }
+
+ console.log(`Checking PR #${pr.number}: ${pr.title}`)
+
+ // Fetch files changed in this PR
+ const { data: files } = await github.rest.pulls.listFiles({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pr.number,
+ per_page: 100,
+ })
+
+ // Check if any file is under apps/studio/
+ const touchesDashboard = files.some((file) => file.filename.startsWith(DASHBOARD_PATH))
+
+ if (touchesDashboard) {
+ const hoursOld = Math.floor((Date.now() - createdAt.getTime()) / (1000 * 60 * 60))
+ const daysOld = Math.floor(hoursOld / 24)
+
+ // Fetch review status
+ let reviewStatus = 'no-reviews'
+ let reviewEmoji = ':eyes:'
+ try {
+ const { data: reviews } = await github.rest.pulls.listReviews({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pr.number,
+ per_page: 100,
+ })
+
+ if (reviews.length === 0) {
+ reviewStatus = 'no-reviews'
+ reviewEmoji = ':eyes:'
+ } else {
+ // Get the most recent review from each reviewer
+ const latestReviews = {}
+ reviews.forEach((review) => {
+ if (
+ !latestReviews[review.user.login] ||
+ new Date(review.submitted_at) >
+ new Date(latestReviews[review.user.login].submitted_at)
+ ) {
+ latestReviews[review.user.login] = review
+ }
+ })
+
+ // Check for most critical state (Changes Requested > Approved > Commented)
+ const states = Object.values(latestReviews).map((r) => r.state)
+ if (states.includes('CHANGES_REQUESTED')) {
+ reviewStatus = 'changes-requested'
+ reviewEmoji = ':warning:'
+ } else if (states.includes('APPROVED')) {
+ reviewStatus = 'approved'
+ reviewEmoji = ':heavy_check_mark:'
+ } else {
+ reviewStatus = 'commented'
+ reviewEmoji = ':speech_balloon:'
+ }
+ }
+ } catch (error) {
+ console.log(
+ `Warning: Could not fetch review status for PR #${pr.number}: ${error.message}`
+ )
+ }
+
+ // Get mergeable state
+ let mergeableStatus = 'unknown'
+ let mergeableEmoji = ':grey_question:'
+
+ // Fetch full PR details to get mergeable state (it's not always in the list response)
+ try {
+ const { data: fullPR } = await github.rest.pulls.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pr.number,
+ })
+
+ const mergeableState = fullPR.mergeable_state
+
+ switch (mergeableState) {
+ case 'clean':
+ mergeableStatus = 'ready'
+ mergeableEmoji = ':rocket:'
+ break
+ case 'dirty':
+ mergeableStatus = 'conflicts'
+ mergeableEmoji = ':collision:'
+ break
+ case 'blocked':
+ mergeableStatus = 'blocked'
+ mergeableEmoji = ':no_entry:'
+ break
+ case 'unstable':
+ mergeableStatus = 'unstable'
+ mergeableEmoji = ':warning:'
+ break
+ case 'behind':
+ mergeableStatus = 'behind'
+ mergeableEmoji = ':arrow_down:'
+ break
+ case 'draft':
+ mergeableStatus = 'draft'
+ mergeableEmoji = ':pencil2:'
+ break
+ default:
+ mergeableStatus = mergeableState || 'unknown'
+ mergeableEmoji = ':grey_question:'
+ }
+ } catch (error) {
+ console.log(
+ `Warning: Could not fetch mergeable state for PR #${pr.number}: ${error.message}`
+ )
+ }
+
+ stalePRs.push({
+ number: pr.number,
+ title: pr.title,
+ url: pr.html_url,
+ author: pr.user.login,
+ createdAt: pr.created_at,
+ hoursOld: hoursOld,
+ daysOld: daysOld,
+ fileCount: files.filter((f) => f.filename.startsWith(DASHBOARD_PATH)).length,
+ reviewStatus: reviewStatus,
+ reviewEmoji: reviewEmoji,
+ mergeableStatus: mergeableStatus,
+ mergeableEmoji: mergeableEmoji,
+ })
+
+ console.log(
+ `✓ Found stale Dashboard PR #${pr.number} (Review: ${reviewStatus}, Mergeable: ${mergeableStatus})`
+ )
+ }
+ }
+
+ page++
+ }
+
+ console.log(`Found ${stalePRs.length} stale Dashboard PRs`)
+
+ // Sort by age (newest first)
+ stalePRs.sort((a, b) => a.hoursOld - b.hoursOld)
+
+ // Store results for next step
+ core.setOutput('stale_prs', JSON.stringify(stalePRs))
+ core.setOutput('count', stalePRs.length)
+
+ return stalePRs
+}
diff --git a/scripts/actions/send-slack-pr-notification.js b/scripts/actions/send-slack-pr-notification.js
new file mode 100644
index 00000000000..c9e56b04123
--- /dev/null
+++ b/scripts/actions/send-slack-pr-notification.js
@@ -0,0 +1,110 @@
+/**
+ * Sends a Slack notification with stale Dashboard PRs
+ *
+ * @param {Array} stalePRs - Array of stale PRs from find-stale-dashboard-prs.js
+ * @param {string} webhookUrl - Slack webhook URL
+ */
+module.exports = async (stalePRs, webhookUrl) => {
+ const count = stalePRs.length
+
+ // Build PR blocks with proper escaping for Slack mrkdwn
+ const prBlocks = stalePRs.map((pr) => {
+ // Format age display
+ const remainingHours = pr.hoursOld % 24
+ const ageText = pr.daysOld > 0 ? `${pr.daysOld}d ${remainingHours}h` : `${pr.hoursOld}h`
+
+ // Escape special characters for Slack mrkdwn (escape &, <, >)
+ const escapeSlack = (text) => {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
+ }
+
+ // Truncate title if too long (max 3000 chars for entire text field)
+ const maxTitleLength = 200
+ const safeTitle =
+ pr.title.length > maxTitleLength
+ ? escapeSlack(pr.title.substring(0, maxTitleLength) + '...')
+ : escapeSlack(pr.title)
+
+ // Format status text
+ const reviewStatusText =
+ pr.reviewStatus === 'approved'
+ ? 'Approved'
+ : pr.reviewStatus === 'changes-requested'
+ ? 'Changes Requested'
+ : pr.reviewStatus === 'commented'
+ ? 'Commented'
+ : 'Needs Review'
+
+ const mergeableStatusText =
+ pr.mergeableStatus === 'ready'
+ ? 'Ready to Merge'
+ : pr.mergeableStatus === 'conflicts'
+ ? 'Has Conflicts'
+ : pr.mergeableStatus === 'blocked'
+ ? 'Blocked'
+ : pr.mergeableStatus === 'unstable'
+ ? 'Unstable'
+ : pr.mergeableStatus === 'behind'
+ ? 'Behind Base'
+ : pr.mergeableStatus === 'draft'
+ ? 'Draft'
+ : 'Unknown'
+
+ return {
+ type: 'section',
+ text: {
+ type: 'mrkdwn',
+ text: `*<${pr.url}|#${pr.number}: ${safeTitle}>*\n:bust_in_silhouette: @${pr.author} • :clock3: ${ageText} old • :file_folder: ${pr.fileCount} Dashboard files\n${pr.reviewEmoji} ${reviewStatusText} • ${pr.mergeableEmoji} ${mergeableStatusText}`,
+ },
+ }
+ })
+
+ // Slack has a 50 block limit, we use 3 for header/intro/divider
+ // So we can show max 47 PRs
+ const MAX_PRS_TO_SHOW = 47
+ const prBlocksToShow = prBlocks.slice(0, MAX_PRS_TO_SHOW)
+ const hasMorePRs = prBlocks.length > MAX_PRS_TO_SHOW
+
+ // Build complete Slack message
+ const slackMessage = {
+ text: 'Dashboard PRs needing attention',
+ blocks: [
+ {
+ type: 'header',
+ text: {
+ type: 'plain_text',
+ text: 'Dashboard PRs Older Than 24 Hours',
+ },
+ },
+ {
+ type: 'section',
+ text: {
+ type: 'mrkdwn',
+ text: `There are *${count}* open PRs affecting /apps/studio/ that are older than 24 hours:${hasMorePRs ? ` (showing first ${MAX_PRS_TO_SHOW})` : ''}`,
+ },
+ },
+ {
+ type: 'divider',
+ },
+ ...prBlocksToShow,
+ ],
+ }
+
+ // Send to Slack
+ const response = await fetch(webhookUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(slackMessage),
+ })
+
+ if (!response.ok) {
+ const errorText = await response.text()
+ throw new Error(
+ `Slack notification failed: ${response.status} ${response.statusText}\n${errorText}`
+ )
+ }
+
+ console.log('✓ Slack notification sent successfully!')
+}