Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

Both assign_to_user.cjs and unassign_from_user.cjs contained identical 23-line blocks for issue number resolution and 8-line blocks for assignee extraction.

Changes

New helper functions in safe_output_helpers.cjs:

  • resolveIssueNumber(message) - Resolves issue number from message field or context payload
  • extractAssignees(message) - Extracts assignees array, supporting both assignee (singular) and assignees (plural) forms

Refactored handlers:

  • assign_to_user.cjs - Replaced inline logic with helper calls (41 lines → 13 lines)
  • unassign_from_user.cjs - Replaced inline logic with helper calls (41 lines → 13 lines)

Example

// Before: 31 lines of inline logic per file
let issueNumber;
if (assignItem.issue_number !== undefined) {
  issueNumber = parseInt(String(assignItem.issue_number), 10);
  if (isNaN(issueNumber)) {
    return { success: false, error: `Invalid issue_number: ${assignItem.issue_number}` };
  }
} else {
  const contextIssue = context.payload?.issue?.number;
  if (!contextIssue) {
    return { success: false, error: "No issue number available" };
  }
  issueNumber = contextIssue;
}

// After: 9 lines using shared helper
const issueResult = resolveIssueNumber(assignItem);
if (!issueResult.success) {
  core.warning(`Skipping assign_to_user: ${issueResult.error}`);
  return { success: false, error: issueResult.error };
}
const issueNumber = issueResult.issueNumber;

Net: 82 lines of duplicate code consolidated into 52 lines of reusable helpers.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/github/gh-aw/actions/artifacts/5489103278/zip
    • Triggering command: /usr/bin/curl curl -L -H Accept: application/vnd.github+json -H X-GitHub-Api-Version: 2022-11-28 REDACTED -o agent-artifacts.zip (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[code-simplifier] Extract duplicate logic to safe output helper functions</issue_title>
<issue_description>## Code Simplification - 2026-02-12

This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • actions/setup/js/assign_to_user.cjs - Reduced 41 lines by extracting duplicate issue number resolution and assignee extraction logic
  • actions/setup/js/unassign_from_user.cjs - Reduced 67 lines by using shared helper functions for common operations
  • actions/setup/js/safe_output_helpers.cjs - Added 45 lines of reusable helper functions

Improvements Made

  1. Reduced Code Duplication

    • Both assign_to_user.cjs and unassign_from_user.cjs contained identical 23-line blocks for determining issue numbers from messages or context
    • Both files had identical 8-line blocks for extracting assignees (supporting both singular and plural forms)
    • Total duplication eliminated: 108 lines
  2. Enhanced Maintainability

    • Centralized issue number resolution logic in resolveIssueNumber() helper
    • Centralized assignee extraction logic in extractAssignees() helper
    • Future changes to this logic only need to be made once
  3. Preserved Functionality

    • All validation logic remains identical
    • Error messages are unchanged
    • Return values and behavior are preserved
  4. Applied Project Standards

    • Followed existing helper file patterns (*_helpers.cjs)
    • Used consistent JSDoc documentation
    • Maintained existing code style and conventions

Changes Based On

Recent changes from:

Testing

  • ✅ JavaScript syntax validated (node -c)
  • ✅ Code formatting passes (make fmt-cjs)
  • ✅ Linting passes (make lint-cjs)
  • ✅ No functional changes - behavior is identical
  • ✅ Both handlers use same validation and error handling logic

Code Metrics

  • Lines removed: 108 (41 from assign_to_user + 67 from unassign_from_user)
  • Lines added: 45 (new helper functions)
  • Net reduction: 63 lines
  • Duplication eliminated: 100%

Helper Functions Added

/**
 * Determine issue number from message or context
 * `@param` {Object} message - Message object that may contain issue_number
 * `@returns` \{\{success: true, issueNumber: number} | {success: false, error: string}}
 */
function resolveIssueNumber(message)

/**
 * Extract assignees from message supporting both singular and plural forms
 * `@param` {Object} message - Message object that may contain assignee or assignees
 * `@returns` {string[]} Array of assignee usernames
 */
function extractAssignees(message)

Review Focus

Please verify:

  • Helper functions correctly replicate original behavior
  • Error handling is preserved
  • Both assign_to_user and unassign_from_user handlers work correctly
  • No unintended side effects in other files using safe_output_helpers.cjs

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

AI generated by Code Simplifier

  • expires on Feb 13, 2026, 8:06 PM UTC

[!NOTE]
This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download patch artifact

The patch file is available in the agent-artifacts artifact in the workflow run linked above.

To apply the patch locally:

# Download the artifact from the workflow run https://github.com/github/gh-aw/actions/runs/21962022385
# (Use GitHub MCP tools if gh CLI is not available)
gh run download 21962022385 -n agent-artifacts

# The patch file will be at agent-artifacts/tmp/gh-aw/aw.patch after download
# Apply the patch
git am agent-artifacts/tmp/gh-aw/aw.patch
Show patch preview (250 of 250 lines)
From 8eb0259e405d63e22924d6b9a1b576f071ea59b9 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Thu, 12 Feb 2026 20:02:38 +0000
Subject: [PATCH] refactor: extract duplicate logic to safe output helper
 functions

Extract duplicate issue number resolution and assignee extraction logic
from assign_to_user and unassign_from_user handlers into reusable
helper functions in safe_output_helpers.cjs.

Changes:
- Add resolveIssueNumber() helper for determining issue number from
  message or context with proper validation
- Add extractAssignees() helper for hand...

</details>


> **Custom agent used: agentic-workflows**
> GitHub Agentic Workflows (gh-aw) - Create, debug, and upgrade AI-powered workflows with intelligent prompt routing



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes github/gh-aw#15234

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

- Add resolveIssueNumber() helper in safe_output_helpers.cjs
- Add extractAssignees() helper in safe_output_helpers.cjs
- Update assign_to_user.cjs to use new helper functions
- Update unassign_from_user.cjs to use new helper functions
- Reduces 108 lines of duplicate code to 52 lines of reusable helpers
- Net reduction: 56 lines (58 lines removed, 2 lines added for imports)
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract duplicate logic to safe output helper functions Extract duplicate logic to safe output helper functions Feb 12, 2026
Copilot AI requested a review from pelikhan February 12, 2026 21:24
@pelikhan pelikhan marked this pull request as ready for review February 12, 2026 21:25
Copilot AI review requested due to automatic review settings February 12, 2026 21:25
Copy link
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

This pull request extracts duplicate code from assign_to_user.cjs and unassign_from_user.cjs into reusable helper functions in safe_output_helpers.cjs. Both handlers contained identical logic for determining issue numbers from messages or context (23 lines) and extracting assignees supporting both singular and plural forms (8 lines).

Changes:

  • Added resolveIssueNumber() helper to centralize issue number resolution logic with validation
  • Added extractAssignees() helper to handle both assignee (singular) and assignees (plural) field formats
  • Refactored both assign_to_user.cjs and unassign_from_user.cjs to use the shared helpers, reducing duplication by 82 lines

Reviewed changes

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

File Description
actions/setup/js/safe_output_helpers.cjs Added two new exported helper functions: resolveIssueNumber() for issue number resolution and extractAssignees() for extracting assignee arrays from messages
actions/setup/js/assign_to_user.cjs Replaced 31 lines of inline logic with calls to the new shared helpers, maintaining identical behavior
actions/setup/js/unassign_from_user.cjs Replaced 31 lines of inline logic with calls to the new shared helpers, maintaining identical behavior

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

Comment on lines +265 to +308
function resolveIssueNumber(message) {
// Determine issue number
let issueNumber;
if (message.issue_number !== undefined) {
issueNumber = parseInt(String(message.issue_number), 10);
if (isNaN(issueNumber)) {
return {
success: false,
error: `Invalid issue_number: ${message.issue_number}`,
};
}
} else {
// Use context issue if available
const contextIssue = context.payload?.issue?.number;
if (!contextIssue) {
return {
success: false,
error: "No issue number available",
};
}
issueNumber = contextIssue;
}

return {
success: true,
issueNumber: issueNumber,
};
}

/**
* Extract assignees from message supporting both singular and plural forms
* @param {Object} message - Message object that may contain assignee or assignees
* @returns {string[]} Array of assignee usernames
*/
function extractAssignees(message) {
// Support both singular "assignee" and plural "assignees" for flexibility
let requestedAssignees = [];
if (message.assignees && Array.isArray(message.assignees)) {
requestedAssignees = message.assignees;
} else if (message.assignee) {
requestedAssignees = [message.assignee];
}
return requestedAssignees;
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The newly added helper functions resolveIssueNumber and extractAssignees lack test coverage. The existing test file safe_output_helpers.test.cjs has comprehensive tests for other helper functions like parseAllowedItems, parseMaxCount, resolveTarget, and loadCustomSafeOutputJobTypes. These new functions should have similar test coverage to ensure they handle edge cases correctly (e.g., invalid issue numbers, missing context, various assignee field formats).

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 534874c into main Feb 12, 2026
125 checks passed
@pelikhan pelikhan deleted the copilot/extract-duplicate-logic branch February 12, 2026 21:30
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.

2 participants