MCPcopy Create free account
hub / github.com/github/gh-aw / main

Function main

actions/setup/js/comment_memory.cjs:128–265  ·  view source on GitHub ↗
(config = {})

Source from the content-addressed store, hash-verified

126}
127
128async function main(config = {}) {
129 const parsedMaxCount = parseInt(String(config.max ?? "1"), 10);
130 const maxCount = Number.isInteger(parsedMaxCount) && parsedMaxCount > 0 ? parsedMaxCount : 1;
131 const defaultMemoryID = sanitizeMemoryID(config.memory_id || "default") || "default";
132 const includeFooter = String(config.footer ?? "true") !== "false";
133 const target = config.target || "triggering";
134 const githubClient = await createAuthenticatedGitHubClient(config);
135 const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig(config);
136 const staged = isStagedMode(config);
137 core.info(`comment_memory: initialized with max=${maxCount}, defaultMemoryID='${defaultMemoryID}', target='${target}', footer=${includeFooter}, staged=${staged}`);
138
139 let processedCount = 0;
140
141 return async message => {
142 if (!message || message.type !== "comment_memory") {
143 return null;
144 }
145
146 processedCount += 1;
147 if (processedCount > maxCount) {
148 core.info(`comment_memory: skipping item because max count reached (${maxCount})`);
149 return { success: true, skipped: true, warning: `Skipped comment_memory item: max ${maxCount} reached` };
150 }
151 core.info(`comment_memory: processing item ${processedCount}/${maxCount}`);
152
153 const targetResult = resolveTarget({
154 targetConfig: target,
155 item: message,
156 context,
157 itemType: "comment memory",
158 // supportsPR=true means both issues and PRs in resolveTarget().
159 supportsPR: true,
160 });
161 if (!targetResult.success) {
162 core.warning(`comment_memory: target resolution failed: ${targetResult.error}`);
163 if (!targetResult.shouldFail) {
164 // No triggering context (e.g. schedule/workflow_dispatch run) — skip rather than fail
165 return { success: false, skipped: true, error: targetResult.error };
166 }
167 return { success: false, error: targetResult.error };
168 }
169 core.info(`comment_memory: resolved target item_number=${targetResult.number}`);
170
171 const repoResolution = resolveAndValidateRepo(message, defaultTargetRepo, allowedRepos, "comment memory");
172 if (!repoResolution.success) {
173 core.warning(`comment_memory: repo resolution failed: ${repoResolution.error}`);
174 return { success: false, error: repoResolution.error };
175 }
176 core.info(`comment_memory: resolved target repo=${repoResolution.repo}`);
177
178 const memoryID = sanitizeMemoryID(message.memory_id || defaultMemoryID);
179 if (!memoryID) {
180 return { success: false, error: "memory_id must contain only alphanumeric characters, hyphens, and underscores" };
181 }
182 core.info(`comment_memory: using memory_id='${memoryID}'`);
183
184 const runUrl = buildWorkflowRunUrl(context, context.repo);
185 const workflowName = process.env.GH_AW_WORKFLOW_NAME || "Workflow";

Callers

nothing calls this directly

Calls 12

sanitizeMemoryIDFunction · 0.85
resolveTargetRepoConfigFunction · 0.85
isStagedModeFunction · 0.85
resolveAndValidateRepoFunction · 0.85
buildWorkflowRunUrlFunction · 0.85
generateHistoryUrlFunction · 0.85
buildManagedMemoryBodyFunction · 0.85
enforceCommentLimitsFunction · 0.85
findManagedCommentFunction · 0.85
resolveTargetFunction · 0.70
getErrorMessageFunction · 0.70

Tested by

no test coverage detected