From 983f8b021c0f3a4c89a033b38903ac8982dcd5a0 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Fri, 3 May 2024 14:13:58 -0700 Subject: [PATCH] feat: warn if branch has had unreleased commits for N days --- action-audit.js | 10 ++++++++++ constants.js | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/action-audit.js b/action-audit.js index 9279abd..f4360cc 100644 --- a/action-audit.js +++ b/action-audit.js @@ -15,6 +15,8 @@ const { SLACK_BOT_TOKEN, ACTION_TYPE, AUDIT_POST_CHANNEL, + MILLISECONDS_PER_DAY, + UNRELEASED_DAYS_WARN_THRESHOLD, } = require('./constants'); const Actions = { @@ -49,6 +51,14 @@ async function run() { let text = ''; if (ACTION_TYPE === Actions.UNRELEASED) { text += buildUnreleasedCommitsMessage(branch, commits, initiatedBy); + const earliestCommit = commits[0]; + const unreleasedDays = Math.floor( + (Date.now() - new Date(earliestCommit.committer.date).getTime()) / + MILLISECONDS_PER_DAY, + ); + if (unreleasedDays > UNRELEASED_DAYS_WARN_THRESHOLD) { + text += `\n ⚠️ *There have been unreleased commits on \`${branch}\` for ${unreleasedDays} days!*`; + } } else if (ACTION_TYPE === Actions.NEEDS_MANUAL) { text += buildNeedsManualPRsMessage( branch, diff --git a/constants.js b/constants.js index 9a4f18c..15fbd1b 100644 --- a/constants.js +++ b/constants.js @@ -16,6 +16,10 @@ const RELEASE_BRANCH_PATTERN = /^(\d)+-(?:(?:[0-9]+-x$)|(?:x+-y$))$/; const BUMP_COMMIT_PATTERN = /Bump v(\d)+.(\d)+.(\d)+(-(beta|nightly)(.\d+))?/; +const MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24; + +const UNRELEASED_DAYS_WARN_THRESHOLD = 8; + module.exports = { ACTION_TYPE, AUDIT_POST_CHANNEL, @@ -27,4 +31,6 @@ module.exports = { REPO_NAME, SLACK_BOT_TOKEN, UNRELEASED_GITHUB_APP_CREDS, + MILLISECONDS_PER_DAY, + UNRELEASED_DAYS_WARN_THRESHOLD, };