Make discussion categories case-insensitive#14820
Conversation
- 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 lint go |
🔍 PR Triage ResultsCategory: bug | Risk: high | Priority: 73/100 Scores Breakdown
📋 Recommended Action: fast_trackRationale: 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:
Triaged by PR Triage Agent on 2026-02-10T18:33:07Z
|
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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 };
}
}
| if validateDiscussionCategory(config.Category, discussionLog, c.markdownPath) { | ||
| return nil // Invalid configuration, return nil to cause validation error | ||
| } | ||
| // Normalize and validate category naming convention |
There was a problem hiding this comment.
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.
| // Normalize and validate category naming convention | |
| // Normalize category naming convention for consistent handling and logging |
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)DIC_*) unchangedRuntime matching (
actions/setup/js/create_discussion.cjs)Example
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.