Skip to content

Comments

Make discussion categories case-insensitive#14820

Merged
pelikhan merged 2 commits intomainfrom
copilot/normalize-category-names
Feb 10, 2026
Merged

Make discussion categories case-insensitive#14820
pelikhan merged 2 commits intomainfrom
copilot/normalize-category-names

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Discussion category names are case-insensitive in GitHub's API but were being validated with case-sensitive rules, rejecting valid configurations like category: "Audits".

Changes

Compile-time normalization (pkg/workflow/create_discussion.go)

  • Convert category names to lowercase during workflow compilation
  • Preserve category IDs (prefix DIC_*) unchanged
  • Replace validation error with info message

Runtime matching (actions/setup/js/create_discussion.cjs)

  • Case-insensitive comparison for category names and slugs
  • Category IDs remain case-sensitive (exact match)

Example

safe-outputs:
  create-discussion:
    category: "Audits"  # Now normalized to "audits"

Both "Audits" and "audits" match GitHub's "Audits" category. Category IDs like "DIC_kwDOGFsHUM4BsUn3" work unchanged.


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

- Normalize discussion categories to lowercase in Go compiler
- Add case-insensitive matching in JavaScript resolveCategoryId
- Update tests to verify normalization behavior
- Category IDs (DIC_*) remain unchanged

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix discussion creation for case insensitive category names Make discussion categories case-insensitive Feb 10, 2026
Copilot AI requested a review from pelikhan February 10, 2026 18:25
@pelikhan
Copy link
Contributor

@copilot lint go

@github-actions
Copy link
Contributor

🔍 PR Triage Results

Category: bug | Risk: high | Priority: 73/100

Scores Breakdown

  • Impact: 50/50 - Bug fix in core workflow compilation logic (create_discussion). High impact due to changes in compiler and runtime validation affecting all discussion creation workflows.
  • Urgency: 10/30 - Recent PR (0.4 hours old) with bug fix severity. Currently draft with pending CI.
  • Quality: 13/20 - Good quality with comprehensive test coverage (274 new test lines). Includes both unit tests and integration tests. CI pending.

📋 Recommended Action: fast_track

Rationale: This is a high-priority bug fix that addresses case-sensitivity issues in discussion category validation. The changes affect core workflow compilation logic and runtime matching behavior, requiring careful review due to the risk level. However, the comprehensive test coverage and clear fix approach make this suitable for fast-track review once CI passes.

Next Steps:

  1. ✅ Wait for CI to complete
  2. Review the normalization approach (compile-time + runtime)
  3. Verify test coverage for edge cases
  4. Consider merging once CI passes and review is complete

Triaged by PR Triage Agent on 2026-02-10T18:33:07Z

AI generated by PR Triage Agent

Copy link
Contributor Author

Copilot AI commented Feb 10, 2026

@copilot lint go

Linter passes clean - all Go code formatting and validation checks successful (974ab4f).

@pelikhan pelikhan marked this pull request as ready for review February 10, 2026 18:43
Copilot AI review requested due to automatic review settings February 10, 2026 18:43
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 makes GitHub Discussion category handling case-insensitive across both workflow compilation (Go compiler) and runtime execution (JS action), aligning validation/matching behavior with GitHub’s API semantics.

Changes:

  • Normalize configured discussion category names to lowercase during compilation while preserving DIC_* category IDs.
  • Match category names and slugs case-insensitively at runtime when resolving a category ID.
  • Update/add tests covering normalization and runtime category matching behaviors.

Reviewed changes

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

File Description
pkg/workflow/create_discussion.go Replaces strict category validation with lowercase normalization + informational messaging.
pkg/workflow/create_discussion_validation_test.go Updates tests to assert normalization behavior instead of rejection.
actions/setup/js/create_discussion.cjs Makes category name/slug matching case-insensitive while keeping ID matching exact.
actions/setup/js/create_discussion_category_normalization.test.cjs Adds runtime tests validating case-insensitive matching and ID preservation.

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

Comment on lines 65 to +81
if (categoryToMatch) {
// Try to match against category IDs first
// Try to match against category IDs first (exact match, case-sensitive)
const categoryById = categories.find(cat => cat.id === categoryToMatch);
if (categoryById) {
return { id: categoryById.id, matchType: "id", name: categoryById.name };
}
// Try to match against category names
const categoryByName = categories.find(cat => cat.name === categoryToMatch);

// Normalize the category to match for case-insensitive comparison
const normalizedCategoryToMatch = categoryToMatch.toLowerCase();

// Try to match against category names (case-insensitive)
const categoryByName = categories.find(cat => cat.name.toLowerCase() === normalizedCategoryToMatch);
if (categoryByName) {
return { id: categoryByName.id, matchType: "name", name: categoryByName.name };
}
// Try to match against category slugs (routes)
const categoryBySlug = categories.find(cat => cat.slug === categoryToMatch);
// Try to match against category slugs (routes, case-insensitive)
const categoryBySlug = categories.find(cat => cat.slug.toLowerCase() === normalizedCategoryToMatch);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

resolveCategoryId now calls categoryToMatch.toLowerCase(), which will throw a TypeError if item.category (or config.category) is not a string (agent output can be non-string). Consider coercing to string (e.g., String(categoryToMatch)) or guarding with typeof categoryToMatch === "string" before lowercasing so invalid types fall back gracefully instead of crashing the handler.

See below for a potential fix:

    if (typeof categoryToMatch === "string") {
      // Normalize the category to match for case-insensitive comparison
      const normalizedCategoryToMatch = categoryToMatch.toLowerCase();

      // Try to match against category names (case-insensitive)
      const categoryByName = categories.find(cat => cat.name.toLowerCase() === normalizedCategoryToMatch);
      if (categoryByName) {
        return { id: categoryByName.id, matchType: "name", name: categoryByName.name };
      }
      // Try to match against category slugs (routes, case-insensitive)
      const categoryBySlug = categories.find(cat => cat.slug.toLowerCase() === normalizedCategoryToMatch);
      if (categoryBySlug) {
        return { id: categoryBySlug.id, matchType: "slug", name: categoryBySlug.name };
      }
    }

Copilot uses AI. Check for mistakes.
if validateDiscussionCategory(config.Category, discussionLog, c.markdownPath) {
return nil // Invalid configuration, return nil to cause validation error
}
// Normalize and validate category naming convention
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The comment says "Normalize and validate category naming convention", but normalizeDiscussionCategory no longer validates/rejects categories (it always returns a string). Update the comment to avoid implying that invalid categories are still rejected at compile time.

Suggested change
// Normalize and validate category naming convention
// Normalize category naming convention for consistent handling and logging

Copilot uses AI. Check for mistakes.
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.

2 participants