Skip to content

[jsweep] Clean messages_run_status.cjs#23824

Merged
pelikhan merged 1 commit intomainfrom
jsweep/clean-messages-run-status-a8db0c7a4574b1e7
Apr 1, 2026
Merged

[jsweep] Clean messages_run_status.cjs#23824
pelikhan merged 1 commit intomainfrom
jsweep/clean-messages-run-status-a8db0c7a4574b1e7

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 1, 2026

Summary

Cleaned actions/setup/js/messages_run_status.cjs — a Node.js context module (no github-script globals) that provides run-status message generation for workflow execution notifications.

Changes

messages_run_status.cjs

Extracted renderConfiguredMessage() helper to eliminate a 7× repeated pattern:

// ❌ BEFORE: Repeated in every function (7 times)
function getRunStartedMessage(ctx) {
  const messages = getMessages();
  const templateContext = toSnakeCase(ctx);
  const defaultMessage = "🚀 [{workflow_name}]({run_url}) has started processing this {event_type}";
  return messages?.runStarted ? renderTemplate(messages.runStarted, templateContext) : renderTemplate(defaultMessage, templateContext);
}

// ✅ AFTER: One-liner using shared helper
function getRunStartedMessage(ctx) {
  return renderConfiguredMessage("runStarted", "🚀 [{workflow_name}]({run_url}) has started processing this {event_type}", ctx);
}

Also removed the unused /// <reference types="@actions/github-script" /> directive — this module only uses require(), no core/github/context globals.

messages_run_status.test.cjs (new file)

Added 20 test cases covering all 7 exported functions:

  • Default template substitution (all placeholders replaced correctly)
  • Custom template from GH_AW_SAFE_OUTPUT_MESSAGES env var
  • camelCase and snake_case key substitution
  • Multiple status values for getRunFailureMessage
  • Full SHA vs short SHA in getCommitPushedMessage
  • Fallback to default when config has only unrelated keys

Validation ✅

Check Status
npm run format:cjs ✓ All files use Prettier code style
npm run lint:cjs ✓ All checks passed
npm run typecheck ✓ No type errors
npm run test:js ✓ All 20 new tests pass (15 pre-existing failures in unrelated files)

Generated by jsweep - JavaScript Unbloater ·

  • expires on Apr 3, 2026, 4:48 AM UTC

- Extract renderConfiguredMessage() helper to eliminate 7x repeated pattern
  (getMessages + toSnakeCase + ternary renderTemplate call)
- Remove unused /// <reference types="@actions/github-script" /> directive
  (module uses no github-script globals)
- Each exported function is now a readable one-liner
- Add comprehensive test file with 20 test cases covering all 7 functions,
  default templates, custom templates, placeholder substitution,
  camelCase/snake_case keys, and fallback behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review April 1, 2026 04:52
Copilot AI review requested due to automatic review settings April 1, 2026 04:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the run-status message generator module to remove duplicated “configured vs default template” logic and adds dedicated unit tests for the run-status message functions.

Changes:

  • Extracted a shared renderConfiguredMessage() helper to centralize message rendering with optional config overrides.
  • Removed an unused @actions/github-script reference directive from messages_run_status.cjs.
  • Added messages_run_status.test.cjs with coverage for defaults, config overrides, and placeholder substitution behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/messages_run_status.cjs Refactors message generation to use a shared helper for default/configured template rendering.
actions/setup/js/messages_run_status.test.cjs Adds Vitest coverage for all exported run-status message helpers and template substitution cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/
function renderConfiguredMessage(messageKey, defaultTemplate, ctx) {
const messages = getMessages();
const template = messages?.[messageKey] ?? defaultTemplate;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

renderConfiguredMessage uses nullish-coalescing (messages?.[messageKey] ?? defaultTemplate). This changes behavior vs the previous truthy check: an empty-string configured message will now override the default, and a non-string (e.g. false, 0) would be passed into renderTemplate and throw at runtime (template.replace is not a function). Consider preserving the prior semantics and adding a type guard, e.g. only use the configured value when it is a non-empty string; otherwise fall back to defaultTemplate (and optionally emit a warning for invalid types).

Suggested change
const template = messages?.[messageKey] ?? defaultTemplate;
const configuredTemplate = messages && messages[messageKey];
const template = typeof configuredTemplate === "string" && configuredTemplate
? configuredTemplate
: defaultTemplate;

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 1, 2026

@copilot review comments

@pelikhan pelikhan merged commit 165783c into main Apr 1, 2026
11 of 12 checks passed
@pelikhan pelikhan deleted the jsweep/clean-messages-run-status-a8db0c7a4574b1e7 branch April 1, 2026 05:06
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

@copilot review comments

Applied the suggested type guard in renderConfiguredMessage. The fix uses typeof configuredTemplate === "string" && configuredTemplate to ensure configured values are only used when they are non-empty strings, falling back to defaultTemplate for empty strings, non-strings (false, 0, etc.), or missing keys — preserving the prior truthy-check semantics and preventing renderTemplate from receiving non-string values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants