-
Notifications
You must be signed in to change notification settings - Fork 352
feat: group-by-day for create-issue to prevent same-day duplicate reports
#22725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ba9635
137f26b
4911a61
877520a
cc4c5c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ const { ERR_VALIDATION } = require("./error_codes.cjs"); | |
| const { renderTemplateFromFile } = require("./messages_core.cjs"); | ||
| const { createExpirationLine, addExpirationToFooter } = require("./ephemerals.cjs"); | ||
| const { MAX_SUB_ISSUES, getSubIssueCount } = require("./sub_issue_helpers.cjs"); | ||
| const { closeOlderIssues } = require("./close_older_issues.cjs"); | ||
| const { closeOlderIssues, searchOlderIssues, addIssueComment } = require("./close_older_issues.cjs"); | ||
| const { parseBoolTemplatable } = require("./templatable.cjs"); | ||
| const { tryEnforceArrayLimit } = require("./limit_enforcement_helpers.cjs"); | ||
| const { logStagedPreviewInfo } = require("./staged_preview.cjs"); | ||
|
|
@@ -205,6 +205,7 @@ async function main(config = {}) { | |
| const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig(config); | ||
| const groupEnabled = parseBoolTemplatable(config.group, false); | ||
| const closeOlderIssuesEnabled = parseBoolTemplatable(config.close_older_issues, false); | ||
| const groupByDayEnabled = parseBoolTemplatable(config.group_by_day, false); | ||
| const rawCloseOlderKey = config.close_older_key ? String(config.close_older_key) : ""; | ||
| const closeOlderKey = rawCloseOlderKey ? normalizeCloseOlderKey(rawCloseOlderKey) : ""; | ||
| if (rawCloseOlderKey && !closeOlderKey) { | ||
|
|
@@ -248,6 +249,12 @@ async function main(config = {}) { | |
| core.info(` Using explicit close-older-key: "${closeOlderKey}"`); | ||
| } | ||
| } | ||
| if (groupByDayEnabled) { | ||
| core.info(`Group-by-day mode enabled: if an open issue was already created today, new content will be posted as a comment`); | ||
| if (!closeOlderKey && !process.env.GH_AW_WORKFLOW_ID) { | ||
| core.warning(`Group-by-day mode has no effect: neither close-older-key nor GH_AW_WORKFLOW_ID is set — issues cannot be searched`); | ||
| } | ||
| } | ||
|
|
||
| // Track how many items we've processed for max limit | ||
| let processedCount = 0; | ||
|
|
@@ -283,8 +290,6 @@ async function main(config = {}) { | |
| }; | ||
| } | ||
|
|
||
| processedCount++; | ||
|
|
||
| // Merge external resolved temp IDs with our local map | ||
| if (resolvedTemporaryIds) { | ||
| for (const [tempId, resolved] of Object.entries(resolvedTemporaryIds)) { | ||
|
|
@@ -480,6 +485,49 @@ async function main(config = {}) { | |
| bodyLines.push(""); | ||
| const body = bodyLines.join("\n").trim(); | ||
|
|
||
| // Group-by-day check: if enabled, search for an existing open issue created today. | ||
| // When found, post the new content as a comment on the existing issue instead of | ||
| // creating a duplicate. This groups multiple same-day runs into a single issue. | ||
| // The max-count slot is NOT consumed when posting as a comment (processedCount is | ||
| // only incremented below, just before actual issue creation). | ||
| if (groupByDayEnabled && (closeOlderKey || workflowId)) { | ||
| const today = new Date().toISOString().split("T")[0]; // YYYY-MM-DD (UTC) | ||
| try { | ||
| const existingIssues = await searchOlderIssues( | ||
| githubClient, | ||
| repoParts.owner, | ||
| repoParts.repo, | ||
| workflowId, | ||
| 0, // no issue to exclude — this is a pre-creation check | ||
| callerWorkflowId, | ||
| closeOlderKey | ||
| ); | ||
| const todayIssue = existingIssues.find(issue => { | ||
| const createdDate = issue.created_at ? String(issue.created_at).split("T")[0] : ""; | ||
| return createdDate === today; | ||
| }); | ||
| if (todayIssue) { | ||
| core.info(`Group-by-day: found open issue #${todayIssue.number} created today (${today}) — posting new content as a comment`); | ||
| const comment = await addIssueComment(githubClient, repoParts.owner, repoParts.repo, todayIssue.number, body); | ||
| core.info(`Posted content as comment ${comment.html_url} on issue #${todayIssue.number}`); | ||
|
Comment on lines
+496
to
+512
|
||
| return { | ||
| success: true, | ||
| grouped: true, | ||
| existingIssueNumber: todayIssue.number, | ||
| existingIssueUrl: todayIssue.html_url, | ||
| commentUrl: comment.html_url, | ||
| }; | ||
| } | ||
| } catch (error) { | ||
| // Log but do not abort — fall through to normal creation | ||
| core.warning(`Group-by-day pre-check failed: ${getErrorMessage(error)} — proceeding with issue creation`); | ||
| } | ||
| } | ||
|
|
||
| // Increment processed count only when we are about to create an issue | ||
| // (group-by-day comment paths return above without consuming a slot) | ||
| processedCount++; | ||
|
|
||
| core.info(`Creating issue in ${qualifiedItemRepo} with title: ${title}`); | ||
| core.info(`Labels: ${labels.join(", ")}`); | ||
| if (assignees.length > 0) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The max-count guard runs before the group-by-day pre-check. If
processedCount >= maxCount(e.g.,max: 1and one issue was already created earlier in the same run), the handler returns early and never attempts group-by-day, even though grouping is intended not to consume a max slot. Consider moving the group-by-day lookup before the max-count check/increment, or only increment/apply max when an issue is actually created (not when grouping as a comment).