feat: prefer Announcements category by default for create-discussion#15513
feat: prefer Announcements category by default for create-discussion#15513
Conversation
…cussion Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot update create_discussion.cjs to choose announcements by default instead of general |
When no category is specified or a non-existent category is requested, create_discussion now intelligently falls back to an "Announcements" category (if available) instead of simply using the first category. This change ensures AI-generated discussions are created in announcement-capable categories by default, providing enhanced visibility and notification features. Added tests to verify: - Fallback to Announcements when no category specified - Fallback to Announcements when non-existent category specified - Existing behavior preserved when Announcements not available Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated in commit da99dba. The
The change ensures AI-generated discussions automatically use announcement-capable categories for better visibility. |
When create-discussion fails and falls back to creating an issue, the fallback message now includes a tip suggesting to use announcement-capable categories like "Announcements". This helps users understand that discussion creation may fail if the specified category is not announcement-capable, guiding them toward the correct configuration. Updated test to verify the new message content. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated in commit ec45bbe. The fallback message now includes a tip about announcement-capable categories: This message appears in the issue body when discussion creation fails and falls back to issue creation, helping users understand the category requirement and how to fix it. |
There was a problem hiding this comment.
Pull request overview
This PR updates create-discussion to prefer the repository’s “Announcements” discussion category by default (when present), and aligns surrounding documentation/tests to encourage announcement-capable categories for workflow-generated content.
Changes:
- Update category resolution to fall back to “Announcements” before the first available category, with a distinct match type.
- Enhance fallback-to-issue messaging with guidance about announcement-capable categories.
- Update docs/examples and add/extend tests covering the new behavior and messaging.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/src/content/docs/reference/safe-outputs.md | Updates create-discussion example to use announcements and adds guidance about announcement-capable categories. |
| docs/src/content/docs/reference/frontmatter-full.md | Adds best-practice guidance for using announcement-capable categories in create-discussion config docs. |
| actions/setup/js/create_discussion.cjs | Changes category fallback logic to prefer “Announcements” and expands fallback-to-issue note with troubleshooting tip. |
| actions/setup/js/create_discussion_category_normalization.test.cjs | Adds tests verifying Announcements is preferred when category is missing or non-existent. |
| actions/setup/js/create_discussion_fallback.test.cjs | Extends fallback test to assert the new tip text is included in the created issue body. |
Comments suppressed due to low confidence (1)
actions/setup/js/create_discussion.cjs:109
resolveCategoryId()now prefers the “Announcements” category when no match is found, but thecreate_discussiontool schema/description still states “If omitted, uses the first available category.” Please update the tool description (and any other user-facing docs) to reflect the new Announcements-preferred default so agents/users don’t make incorrect assumptions.
// Fall back to announcement-capable category if available, otherwise first category
if (categories.length > 0) {
// Try to find an "Announcements" category (case-insensitive)
const announcementCategory = categories.find(cat => cat.name.toLowerCase() === "announcements" || cat.slug.toLowerCase() === "announcements");
if (announcementCategory) {
return {
id: announcementCategory.id,
matchType: "fallback-announcement",
name: announcementCategory.name,
requestedCategory: categoryToMatch,
};
}
// Otherwise use first category
return {
id: categories[0].id,
matchType: "fallback",
name: categories[0].name,
requestedCategory: categoryToMatch,
};
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # available category. Matched first against category IDs, then against category | ||
| # names, then against category slugs. Numeric values are automatically converted | ||
| # to strings at runtime. | ||
| # |
There was a problem hiding this comment.
Line # introduces trailing whitespace in the YAML comment block. Please change it to # (no trailing space) or remove the blank comment line to avoid whitespace/lint issues.
| # | |
| # |
| # Best Practice: Use announcement-capable categories (such as "announcements") | ||
| # for AI-generated content to ensure proper visibility and notification features. |
There was a problem hiding this comment.
This section still says “If not specified, uses the first available category.” With the new behavior preferring the “Announcements” category when present, update the description above to match (e.g., prefer Announcements, else first available) so the frontmatter reference stays accurate.
See below for a potential fix:
# category name, or category slug/route. If not specified, prefers an
# announcement-capable category (such as "Announcements") when available;
# otherwise uses the first available category. Matched first against category
# IDs, then against category names, then against category slugs. Numeric values
# are automatically converted to strings at runtime.
#
# Best Practice: Use announcement-capable categories (such as "Announcements")
| // Fall back to announcement-capable category if available, otherwise first category | ||
| if (categories.length > 0) { | ||
| // Try to find an "Announcements" category (case-insensitive) | ||
| const announcementCategory = categories.find(cat => cat.name.toLowerCase() === "announcements" || cat.slug.toLowerCase() === "announcements"); | ||
|
|
There was a problem hiding this comment.
In this fallback path, requestedCategory comes from categoryToMatch, but categoryToMatch is never trim()’d before ID/name/slug comparisons. If an agent outputs category: "announcements " (trailing space), the match will fail and you’ll unexpectedly fall into this fallback logic. Consider normalizing category inputs with String(...).trim() before matching/fallback.
| title-prefix: "[ai] " # prefix for titles | ||
| category: "announcements" # category slug, name, or ID (use lowercase, prefer announcement-capable) | ||
| expires: 3 # auto-close after 3 days (or false to disable) |
There was a problem hiding this comment.
The create-discussion docs still describe the category as “defaults to first available”, but the implementation now prefers the “Announcements” category when present. Please update the surrounding description to reflect the new fallback order so the example/comment doesn’t contradict actual behavior.
GitHub Discussion categories have different capabilities. Announcement-capable categories (like "Announcements") provide enhanced visibility and notification features that are beneficial for AI-generated content.
Changes
Documentation
safe-outputs.mdexplaining announcement-capable categories and recommending their usecategory: "general"tocategory: "announcements"with inline guidancefrontmatter-full.mdcategory field documentationImplementation
resolveCategoryIdfunction increate_discussion.cjsto intelligently fall back to "Announcements" category when no category is specified or a non-existent category is requested"fallback-announcement"to distinguish intentional announcement fallback from generic fallbackFallback Message
When discussion creation fails and falls back to issue creation, the issue body now includes:
Example
Behavior
When creating discussions:
When fallback to issue creation occurs due to permissions errors, users receive guidance about using announcement-capable categories to prevent future failures.
This ensures that workflow-generated discussions automatically benefit from enhanced visibility and notification features without requiring explicit configuration, and provides helpful troubleshooting guidance when issues occur.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.