Skip to content

Conversation

github-actions[bot]
Copy link

Closes #434

Applied changes based on Issue #434.

I’ve added logic to the top‑level run() in src/main.ts so that when the OpenAI key check fails, we not only core.setFailed(...) but also try to post that same error message as a GitHub comment on the triggering issue/PR. Any failures to post the comment are caught and logged as errors, so they won’t mask the original failure. Specifically:

  • Imported postComment alongside processEvent.
  • In the API‑key‑validation catch, captured the formatted failure message, called postComment(config.octokit, config.repo, processedEvent.agentEvent.github, failureMessage), and wrapped that in its own try/catch.
--- a/src/main.ts
+++ b/src/main.ts
@@
 import { processEvent } from './github/event.js';
+import { postComment } from './github/github.js';
@@
     } catch (error) {
-      core.setFailed(
-        `OPENAI_API_KEY invalid or no access to model \"${config.openaiModel}\": ${error instanceof Error ? error.message : String(error)}`,
-      );
-      return;
+      const errMsg = error instanceof Error ? error.message : String(error);
+      const failureMessage =
+        `OPENAI_API_KEY invalid or no access to model \"${config.openaiModel}\": ${errMsg}`;
+      core.setFailed(failureMessage);
+      try {
+        const processedEvent = await processEvent(config);
+        if (processedEvent) {
+          await postComment(
+            config.octokit,
+            config.repo,
+            processedEvent.agentEvent.github,
+            failureMessage,
+          );
+        }
+      } catch (commentError) {
+        core.error(
+          `Failed to post API key error comment: ${
+            commentError instanceof Error ? commentError.message : String(commentError)
+          }`,
+        );
+      }
+      return;
     }

【F:src/main.ts†L34-L53】

These minimal changes ensure that an invalid OPENAI_API_KEY not only fails the Action but also surfaces the error back into the GitHub conversation.

@YiweiShen YiweiShen merged commit 766ee20 into main Jul 14, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-434-feat-comment-update-issue-or-pr-comment-with-api-key-error branch July 14, 2025 04:14
import { runAction } from './github/action.js';

import { processEvent } from './github/event.js';
import { postComment } from './github/github.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/codex invalid key test

Copy link
Author

@github-actions github-actions bot Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENAI_API_KEY invalid or no access to model "o4-mini": 401 Incorrect API key provided: ***. You can find your API key at https://platform.openai.com/account/api-keys.

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.

When OPENAI_API_KEY is invalid and the process exits, please also update the issue or PR comment with the error message.

1 participant