Skip to content

Commit 39143c7

Browse files
chore: sync actions from [email protected] (#198)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 294c570 commit 39143c7

9 files changed

Lines changed: 64 additions & 22 deletions

‎setup/js/close_issue.cjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const { resolveTargetRepoConfig, resolveAndValidateRepo, validateRepo } = require("./repo_helpers.cjs");
99
const { createAuthenticatedGitHubClient } = require("./handler_auth.cjs");
1010
const { ERR_NOT_FOUND } = require("./error_codes.cjs");
11-
const { createCloseEntityHandler, ISSUE_CONFIG } = require("./close_entity_helpers.cjs");
11+
const { createCloseEntityHandler, buildCommentBody, ISSUE_CONFIG } = require("./close_entity_helpers.cjs");
1212
const { loadTemporaryIdMapFromResolved, resolveRepoIssueTarget } = require("./temporary_id.cjs");
1313
const { getErrorMessage } = require("./error_helpers.cjs");
1414
const { normalizeIssueIntentMetadata } = require("./issue_intents.cjs");
@@ -297,8 +297,9 @@ async function main(config = {}) {
297297
},
298298

299299
buildCommentBody(sanitizedBody) {
300-
// Issues post the sanitized body directly without a workflow footer
301-
return sanitizedBody;
300+
const triggeringIssueNumber = context.payload?.issue?.number;
301+
const triggeringPRNumber = context.payload?.pull_request?.number;
302+
return buildCommentBody(sanitizedBody, triggeringIssueNumber, triggeringPRNumber);
302303
},
303304

304305
addComment: addIssueComment,

‎setup/js/close_older_issues.cjs‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ const API_DELAY_MS = 500;
2929
* @param {string} [closeOlderKey] - Optional explicit deduplication key. When set, the
3030
* `gh-aw-close-key` marker is used as the primary search term and exact filter instead
3131
* of the workflow-id / workflow-call-id markers.
32+
* @param {Set<number>} [additionalExcludeNumbers] - Optional set of additional issue numbers
33+
* to exclude from the results (e.g. all issues created in the current run).
3234
* @returns {Promise<Array<{number: number, title: string, html_url: string, labels: Array<{name: string}>, created_at: string}>>} Matching issues
3335
*/
34-
async function searchOlderIssues(github, owner, repo, workflowId, excludeNumber, callerWorkflowId, closeOlderKey) {
36+
async function searchOlderIssues(github, owner, repo, workflowId, excludeNumber, callerWorkflowId, closeOlderKey, additionalExcludeNumbers) {
3537
core.info(`Starting search for older issues in ${owner}/${repo}`);
3638
core.info(` Workflow ID: ${workflowId || "(none)"}`);
3739
core.info(` Exclude issue number: ${excludeNumber}`);
@@ -68,6 +70,7 @@ async function searchOlderIssues(github, owner, repo, workflowId, excludeNumber,
6870
const { filtered: filteredItems, counters } = filterByMarker({
6971
items: result.data.items,
7072
excludeNumber,
73+
additionalExcludeNumbers,
7174
exactMarker,
7275
entityType: "issue",
7376
additionalFilter: (item, extra) => {
@@ -183,16 +186,19 @@ function getCloseOlderIssueMessage({ newIssueUrl, newIssueNumber, workflowName,
183186
* @param {string} runUrl - URL of the workflow run
184187
* @param {string} [callerWorkflowId] - Optional calling workflow identity for precise filtering
185188
* @param {string} [closeOlderKey] - Optional explicit deduplication key for close-older matching
189+
* @param {Set<number>} [currentRunIssueNumbers] - Optional set of issue numbers created in the
190+
* current run. When provided, these issues are excluded from the close-older search so that
191+
* issues created earlier in the same run are never incorrectly closed.
186192
* @returns {Promise<Array<{number: number, html_url: string}>>} List of closed issues
187193
*/
188-
async function closeOlderIssues(github, owner, repo, workflowId, newIssue, workflowName, runUrl, callerWorkflowId, closeOlderKey) {
194+
async function closeOlderIssues(github, owner, repo, workflowId, newIssue, workflowName, runUrl, callerWorkflowId, closeOlderKey, currentRunIssueNumbers) {
189195
const result = await closeOlderEntities(github, owner, repo, workflowId, newIssue, workflowName, runUrl, {
190196
entityType: "issue",
191197
entityTypePlural: "issues",
192-
// Use a closure so callerWorkflowId and closeOlderKey are forwarded to searchOlderIssues
193-
// without going through the closeOlderEntities extraArgs mechanism (which appends
194-
// excludeNumber last)
195-
searchOlderEntities: (gh, o, r, wid, excludeNumber) => searchOlderIssues(gh, o, r, wid, excludeNumber, callerWorkflowId, closeOlderKey),
198+
// Use a closure so callerWorkflowId, closeOlderKey, and currentRunIssueNumbers are
199+
// forwarded to searchOlderIssues without going through the closeOlderEntities
200+
// extraArgs mechanism (which appends excludeNumber last)
201+
searchOlderEntities: (gh, o, r, wid, excludeNumber) => searchOlderIssues(gh, o, r, wid, excludeNumber, callerWorkflowId, closeOlderKey, currentRunIssueNumbers),
196202
getCloseMessage: params =>
197203
getCloseOlderIssueMessage({
198204
newIssueUrl: params.newEntityUrl,

‎setup/js/close_older_search_helpers.cjs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ function buildMarkerSearchQuery({ owner, repo, workflowId, callerWorkflowId, clo
6262
* @param {object} params
6363
* @param {Array<any>} params.items - Raw search result items
6464
* @param {number} params.excludeNumber - Entity number to exclude (the newly created one)
65+
* @param {Set<number>} [params.additionalExcludeNumbers] - Optional set of additional entity
66+
* numbers to exclude (e.g. all issues created in the current run)
6567
* @param {string} params.exactMarker - Exact marker string that must appear in the body
6668
* @param {string} params.entityType - Entity type name for logging (e.g. "issue", "discussion")
6769
* @param {(item: any, counters: Record<string, number>) => boolean} [params.additionalFilter] -
6870
* Optional callback for entity-specific filtering. Return `true` to keep the item.
6971
* The `counters` object can be mutated to track extra exclusion reasons.
7072
* @returns {{ filtered: Array<any>, counters: FilterCounters & Record<string, number> }}
7173
*/
72-
function filterByMarker({ items, excludeNumber, exactMarker, entityType, additionalFilter }) {
74+
function filterByMarker({ items, excludeNumber, additionalExcludeNumbers, exactMarker, entityType, additionalFilter }) {
7375
let filteredCount = 0;
7476
let excludedCount = 0;
7577
let markerMismatchCount = 0;
@@ -81,13 +83,19 @@ function filterByMarker({ items, excludeNumber, exactMarker, entityType, additio
8183
return false;
8284
}
8385

84-
// Exclude the newly created entity before running any other filters so
85-
// counters/logs consistently attribute this item to the dedicated exclusion.
86+
// Exclude the newly created entity and any other entities created in the
87+
// same run before running any other filters, so counters/logs consistently
88+
// attribute these items to the dedicated exclusion.
8689
if (item.number === excludeNumber) {
8790
excludedCount++;
8891
core.info(` Excluding ${entityType} #${item.number} (the newly created ${entityType})`);
8992
return false;
9093
}
94+
if (additionalExcludeNumbers?.has(item.number)) {
95+
excludedCount++;
96+
core.info(` Excluding ${entityType} #${item.number} (created earlier in the same run)`);
97+
return false;
98+
}
9199

92100
// Run entity-specific filters next (e.g. pull_request, closed, category)
93101
if (additionalFilter && !additionalFilter(item, extraCounters)) {

‎setup/js/comment_memory_helpers.cjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const COMMENT_MEMORY_EXTENSION = ".md";
1010
const MAX_MEMORY_ID_LENGTH = 128;
1111
const COMMENT_MEMORY_MAX_SCAN_PAGES = 50;
1212
const COMMENT_MEMORY_MAX_SCAN_EMPTY_PAGES = 5;
13+
const COMMENT_MEMORY_MAX_FILE_BYTES = 16 * 1024;
14+
const COMMENT_MEMORY_MAX_TOTAL_BYTES = 48 * 1024;
1315
const COMMENT_MEMORY_PROMPT_START_MARKER = "<!-- gh-aw-comment-memory-prompt:start -->";
1416
const COMMENT_MEMORY_PROMPT_END_MARKER = "<!-- gh-aw-comment-memory-prompt:end -->";
1517
const COMMENT_MEMORY_CODE_FENCE = "``````";
@@ -147,6 +149,8 @@ module.exports = {
147149
COMMENT_MEMORY_EXTENSION,
148150
COMMENT_MEMORY_MAX_SCAN_PAGES,
149151
COMMENT_MEMORY_MAX_SCAN_EMPTY_PAGES,
152+
COMMENT_MEMORY_MAX_FILE_BYTES,
153+
COMMENT_MEMORY_MAX_TOTAL_BYTES,
150154
COMMENT_MEMORY_PROMPT_START_MARKER,
151155
COMMENT_MEMORY_PROMPT_END_MARKER,
152156
COMMENT_MEMORY_CODE_FENCE,

‎setup/js/create_issue.cjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,10 @@ async function main(config = {}) {
11141114
const searchKey = closeOlderKey ? `close-older-key: ${closeOlderKey}` : `workflow-id: ${workflowId}`;
11151115
core.info(`Attempting to close older issues for ${qualifiedItemRepo}#${issue.number} using ${searchKey}`);
11161116
try {
1117-
const closedIssues = await closeOlderIssues(github, repoParts.owner, repoParts.repo, workflowId, { number: issue.number, html_url: issue.html_url }, workflowName, runUrl, callerWorkflowId, closeOlderKey);
1117+
// Build the set of all issue numbers created in this run (including the current
1118+
// one) so that previously-created issues are not incorrectly closed.
1119+
const currentRunIssueNumbers = new Set(createdIssues.filter(i => i._repo === qualifiedItemRepo).map(i => i.number));
1120+
const closedIssues = await closeOlderIssues(github, repoParts.owner, repoParts.repo, workflowId, { number: issue.number, html_url: issue.html_url }, workflowName, runUrl, callerWorkflowId, closeOlderKey, currentRunIssueNumbers);
11181121
if (closedIssues.length > 0) {
11191122
core.info(`Closed ${closedIssues.length} older issue(s)`);
11201123
}

‎setup/js/handle_noop_message.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function buildAICSuffix() {
9595
if (totalAIC <= 0) {
9696
return "";
9797
}
98-
return ` · ${compressedModelName ? `${compressedModelName} ` : ""}${formatAIC(totalAIC)} AIC`;
98+
return ` · ${compressedModelName ? `${compressedModelName} · ` : ""}${formatAIC(totalAIC)} AIC`;
9999
}
100100

101101
/**

‎setup/js/messages_footer.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function buildAICEntry(label, value, modelAlias) {
8686
return {
8787
value,
8888
formatted,
89-
suffix: formatted ? ` · ${prefix ? `${prefix} ` : ""}${formatted} AIC` : "",
89+
suffix: formatted ? ` · ${prefix ? `${prefix}${modelAlias ? " · " : " "}` : ""}${formatted} AIC` : "",
9090
};
9191
}
9292

‎setup/js/setup_comment_memory_files.cjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const {
1111
COMMENT_MEMORY_DIR,
1212
COMMENT_MEMORY_MAX_SCAN_PAGES,
1313
COMMENT_MEMORY_MAX_SCAN_EMPTY_PAGES,
14+
COMMENT_MEMORY_MAX_FILE_BYTES,
15+
COMMENT_MEMORY_MAX_TOTAL_BYTES,
1416
COMMENT_MEMORY_PROMPT_START_MARKER,
1517
COMMENT_MEMORY_PROMPT_END_MARKER,
1618
extractCommentMemoryEntries,
@@ -144,6 +146,19 @@ async function collectCommentMemoryFiles(githubClient, commentMemoryConfig) {
144146
} catch (err) {
145147
throw new Error(`Failed to create directory ${COMMENT_MEMORY_DIR}: ${String(err)}`, { cause: err });
146148
}
149+
let totalBytes = 0;
150+
for (const [memoryId, content] of memoryMap.entries()) {
151+
const writtenContent = `${content}\n`;
152+
const contentBytes = Buffer.byteLength(writtenContent, "utf8");
153+
if (contentBytes > COMMENT_MEMORY_MAX_FILE_BYTES) {
154+
throw new Error(`${ERR_VALIDATION}: comment_memory file '${memoryId}.md' is ${contentBytes} bytes, exceeding max ${COMMENT_MEMORY_MAX_FILE_BYTES} bytes`);
155+
}
156+
totalBytes += contentBytes;
157+
if (totalBytes > COMMENT_MEMORY_MAX_TOTAL_BYTES) {
158+
throw new Error(`${ERR_VALIDATION}: comment_memory total size ${totalBytes} bytes exceeds max ${COMMENT_MEMORY_MAX_TOTAL_BYTES} bytes`);
159+
}
160+
}
161+
147162
const writtenFiles = [];
148163
for (const [memoryId, content] of memoryMap.entries()) {
149164
const filePath = path.join(COMMENT_MEMORY_DIR, `${memoryId}.md`);

‎setup/md/noop_runs_issue.md‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ This issue helps you:
2929

3030
</details>
3131

32-
> [!TIP]
33-
> To stop a workflow from posting here, set `report-as-issue: false` in its frontmatter:
34-
> ```yaml
35-
> safe-outputs:
36-
> noop:
37-
> report-as-issue: false
38-
> ```
32+
<details>
33+
<summary>How to disable no-op reporting for a workflow</summary>
34+
35+
To stop a workflow from posting here, set `report-as-issue: false` in its frontmatter:
36+
37+
```yaml
38+
safe-outputs:
39+
noop:
40+
report-as-issue: false
41+
```
42+
43+
</details>
3944
4045
---
4146

0 commit comments

Comments
 (0)