Skip to content

Conversation

github-actions[bot]
Copy link

Closes #519

Applied changes based on Issue #519.

I’ve patched the two title‐prefix blocks in runAction.ts so that they no longer assume an .issue object always exists. Now we detect whether the event is an issue or a PR and use the appropriate .issue.number/.issue.title or .pull_request.number/.pull_request.title (falling back to an empty string) before updating the title. This prevents the “Cannot read properties of undefined (reading 'number')” crash on review‑comment events.

Changes in brief

  • In the “[WIP]” block, compute number/title via a 'issue' in agentEvent.github check instead of unconditionally reading agentEvent.github.issue.
  • Ditto for the final “[Done]” block at action completion.
  • Retained existing regex to strip any prior [WIP]/[Done] tags.
--- a/src/github/runAction.ts
+++ b/src/github/runAction.ts
@@ -49,14 +49,19 @@ export async function runAction(
   core.info('[perf] addEyeReaction start');
   const startAddEyeReaction = Date.now();
   await addEyeReaction(octokit, repo, agentEvent.github);
   core.info(
     `[perf] addEyeReaction end - ${Date.now() - startAddEyeReaction}ms`,
   );
-  // Prefix issue/PR title with [WIP] when work starts
-  {
-    const issueNumber = agentEvent.github.issue.number;
-    const originalTitle = agentEvent.github.issue.title;
-    const strippedTitle = originalTitle.replace(/^\[(?:WIP|Done)\]\s*/, '');
-    const newTitle = `[WIP] ${strippedTitle}`;
-    core.info(`Updating issue/PR #${issueNumber} title to '${newTitle}'`);
-    await octokit.rest.issues.update({ ...repo, issue_number: issueNumber, title: newTitle });
-  }
+  // Prefix issue/PR title with [WIP] when work starts
+  {
+    const isIssue = 'issue' in agentEvent.github;
+    const number = isIssue
+      ? agentEvent.github.issue.number
+      : agentEvent.github.pull_request.number;
+    const title = isIssue
+      ? agentEvent.github.issue.title
+      : agentEvent.github.pull_request.title ?? '';
+    const stripped = title.replace(/^\[(?:WIP|Done)\]\s*/, '');
+    const newTitle = `[WIP] ${stripped}`;
+    core.info(`Updating issue/PR #${number} title to '${newTitle}'`);
+    await octokit.rest.issues.update({
+      ...repo,
+      issue_number: number,
+      title: newTitle,
+    });
+  }
@@ -287,14 +292,19 @@ export async function runAction(
   core.info('Action completed successfully.');
   try {
     await removeEyeReaction(octokit, repo, agentEvent.github);
     await addThumbUpReaction(octokit, repo, agentEvent.github);
   } catch (reactionError) {
     core.warning(
       `Failed to update reaction on the original event: ${
         reactionError instanceof Error ? reactionError.message : reactionError
       }`,
     );
   }
-  // Prefix issue/PR title with [Done] when work completes
-  {
-    const issueNumber = agentEvent.github.issue.number;
-    const originalTitle = agentEvent.github.issue.title;
-    const strippedTitle = originalTitle.replace(/^\[(?:WIP|Done)\]\s*/, '');
-    const newTitle = `[Done] ${strippedTitle}`;
-    core.info(`Updating issue/PR #${issueNumber} title to '${newTitle}'`);
-    await octokit.rest.issues.update({ ...repo, issue_number: issueNumber, title: newTitle });
-  }
+  // Prefix issue/PR title with [Done] when work completes
+  {
+    const isIssue = 'issue' in agentEvent.github;
+    const number = isIssue
+      ? agentEvent.github.issue.number
+      : agentEvent.github.pull_request.number;
+    const title = isIssue
+      ? agentEvent.github.issue.title
+      : agentEvent.github.pull_request.title ?? '';
+    const stripped = title.replace(/^\[(?:WIP|Done)\]\s*/, '');
+    const newTitle = `[Done] ${stripped}`;
+    core.info(`Updating issue/PR #${number} title to '${newTitle}'`);
+    await octokit.rest.issues.update({
+      ...repo,
+      issue_number: number,
+      title: newTitle,
+    });
+  }

【F:src/github/runAction.ts†L49-L67】【F:src/github/runAction.ts†L292-L310】


I ran Prettier on the updated file (no formatting changes needed). The existing test suite and lint setup were already broken/unrelated, so I left them untouched. Let me know if there’s anything else!

@YiweiShen YiweiShen merged commit 9e46193 into main Jul 26, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-fix-519-runaction-guard-against-undefined-pull-request-number branch July 26, 2025 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Done] Fix the Error in code

1 participant