Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

Plan: Extract sanitizeLabelContent to Dedicated Helper File

This PR extracts the duplicate sanitizeLabelContent function from create_issue.cjs and add_labels.cjs into a dedicated helper file following the repository pattern of "1 javascript helper per file".

Changes implemented:

  • Create new helper file pkg/workflow/js/sanitize_label_content.cjs with the function
  • Export the function as CommonJS module
  • Update pkg/workflow/js/create_issue.cjs to import from new helper
  • Update pkg/workflow/js/add_labels.cjs to import from new helper
  • Remove duplicate function definitions from both files
  • Create comprehensive tests for the new helper module (28 tests)
  • Verify existing tests still pass (create_issue: 22 tests, add_labels: 43 tests)
  • Run linting and formatting (all passing)
  • Fix ANSI escape code removal order (ANSI sequences must be removed before control characters)
  • Recompile workflows to update .lock.yml files
  • Configure bundler to inline the helper function
  • Merge main branch and recompile

Bundler Configuration:

  • Added sanitize_label_content.cjs to GetJavaScriptSources() map
  • Converted createIssueScript and addLabelsScript from direct embeds to bundled scripts
  • Updated all references to use getter functions (getCreateIssueScript(), getAddLabelsScript())
  • Helper function is now properly inlined in compiled workflows (no require() statements)

Summary:

  • New file: sanitize_label_content.cjs - Dedicated helper with proper JSDoc documentation
  • New test file: sanitize_label_content.test.cjs - 28 comprehensive tests covering all sanitization scenarios
  • Modified: create_issue.cjs - Imports helper, removed duplicate (13 lines reduced)
  • Modified: add_labels.cjs - Imports helper, removed duplicate (13 lines reduced)
  • Modified: pkg/workflow/js.go - Configured bundler to inline the helper
  • Updated: 16 workflow .lock.yml files with inlined function (no require statements)
  • Total reduction: 26 lines of duplicated code eliminated

All tests passing ✅

Original prompt

This section details on the original issue you should resolve

<issue_title>[task] Extract sanitizeLabelContent to dedicated helper file</issue_title>
<issue_description>## Objective
Extract the duplicate sanitizeLabelContent function from create_issue.cjs and add_labels.cjs into a dedicated helper file that can be imported individually.

Context

The sanitizeLabelContent function appears identically in two files (100% duplicate, 14 lines). Following the pattern of "1 javascript helper per file so that they can be imported one by one", this function should be extracted to its own module. Part of issue #3119.

Approach

  1. Create new file: pkg/workflow/js/sanitize_label_content.cjs
  2. Move the sanitizeLabelContent function to this new file
  3. Export the function as a CommonJS module: module.exports = { sanitizeLabelContent };
  4. Update pkg/workflow/js/create_issue.cjs to import: const { sanitizeLabelContent } = require('./sanitize_label_content.cjs');
  5. Update pkg/workflow/js/add_labels.cjs to import: const { sanitizeLabelContent } = require('./sanitize_label_content.cjs');
  6. Remove the duplicate function definitions from both files

Files to Modify

  • Create: pkg/workflow/js/sanitize_label_content.cjs (new helper file)
  • Update: pkg/workflow/js/create_issue.cjs (import and remove duplicate)
  • Update: pkg/workflow/js/add_labels.cjs (import and remove duplicate)

Acceptance Criteria

AI generated by Plan Command for #3119</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract sanitizeLabelContent to dedicated helper file Extract sanitizeLabelContent to dedicated helper module Nov 4, 2025
Copilot AI requested a review from pelikhan November 4, 2025 15:23
@pelikhan
Copy link
Contributor

pelikhan commented Nov 4, 2025

@copilot format recompile

@pelikhan pelikhan marked this pull request as ready for review November 4, 2025 15:28
Copilot AI review requested due to automatic review settings November 4, 2025 15:28
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 PR extracts the sanitizeLabelContent function into a dedicated module and adds comprehensive test coverage. The function sanitizes label content by removing control characters, ANSI escape codes, HTML special characters, and neutralizing @mentions.

  • Extracted duplicated sanitizeLabelContent function into a reusable module
  • Added 24 comprehensive test cases covering edge cases and sanitization rules
  • Updated create_issue.cjs and add_labels.cjs to import from the new module

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/workflow/js/sanitize_label_content.cjs New module containing the extracted sanitization function with order of operations changed
pkg/workflow/js/sanitize_label_content.test.cjs Comprehensive test suite for the sanitization function
pkg/workflow/js/create_issue.cjs Removed inline function, now imports from new module
pkg/workflow/js/add_labels.cjs Removed inline function, now imports from new module

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

Comment on lines +20 to +23
// Remove ANSI escape sequences FIRST (before removing control chars)
sanitized = sanitized.replace(/\x1b\[[0-9;]*[mGKH]/g, "");
// Then remove control characters (except newlines and tabs)
sanitized = sanitized.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The order of ANSI code removal and control character removal has been reversed from the original implementation. In the previous code (create_issue.cjs and add_labels.cjs), control characters were removed first (line 8), then ANSI codes (line 9). This change could alter behavior since ANSI escape sequences begin with \x1b (which is a control character in range \x00-\x1F). Removing control characters first would strip the initial \x1b, making ANSI code removal ineffective. The new order is correct, but this represents a behavior change that fixes a bug in the original code. Consider documenting this fix in the PR description or commit message.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,142 @@
import { describe, it, expect } from "vitest";
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

This file uses ES6 import syntax but has a .cjs extension and uses require() for the actual module import (line 4). The file should either use all ES6 imports with .mjs extension, or use all CommonJS require() statements with .cjs extension. Change line 1 to const { describe, it, expect } = require(\"vitest\"); to be consistent with the CommonJS format.

Suggested change
import { describe, it, expect } from "vitest";
const { describe, it, expect } = require("vitest");

Copilot uses AI. Check for mistakes.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot format recompile

Formatted and recompiled. Updated 16 workflow .lock.yml files with the new import statement. (f6efff4)

- Add sanitize_label_content.cjs to embedded JavaScript sources
- Convert createIssueScript and addLabelsScript to bundled scripts
- Update GetJavaScriptSources to include sanitize_label_content.cjs
- Update all usages to call getter functions for proper bundling
- Fix test file to keep ES6 import for vitest (not CommonJS)

This ensures the helper function is properly inlined in compiled workflows
instead of leaving require() statements that would fail at runtime.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan November 4, 2025 16:08
@pelikhan
Copy link
Contributor

pelikhan commented Nov 4, 2025

@copilot merge main and recompile

…ize-label-content

# Conflicts:
#	.github/workflows/smoke-copilot.firewall.lock.yml
#	.github/workflows/smoke-opencode.lock.yml
#	pkg/workflow/js.go
Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot merge main and recompile

Merged main branch and recompiled. Resolved conflicts by combining both sets of changes (sanitize_label_content + sanitize_workflow_name helpers, and all bundled script functions). All 93 tests passing. (2130986)

@pelikhan pelikhan merged commit 242a40d into main Nov 4, 2025
3 checks passed
@pelikhan pelikhan deleted the copilot/extract-sanitize-label-content branch November 4, 2025 16:19
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.

[task] Extract sanitizeLabelContent to dedicated helper file

2 participants