@@ -411,17 +411,30 @@ export const GithubRunCommand = cmd({ |
411 | 411 | let exitCode = 0 |
412 | 412 | type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"] |
413 | 413 | const triggerCommentId = payload.comment.id |
| 414 | + const useGithubToken = normalizeUseGithubToken() |
414 | 415 |
|
415 | 416 | try { |
416 | | - const actionToken = isMock ? args.token! : await getOidcToken() |
417 | | - appToken = await exchangeForAppToken(actionToken) |
| 417 | + if (useGithubToken) { |
| 418 | + const githubToken = process.env["GITHUB_TOKEN"] |
| 419 | + if (!githubToken) { |
| 420 | + throw new Error( |
| 421 | + "GITHUB_TOKEN environment variable is not set. When using use_github_token, you must provide GITHUB_TOKEN.", |
| 422 | + ) |
| 423 | + } |
| 424 | + appToken = githubToken |
| 425 | + } else { |
| 426 | + const actionToken = isMock ? args.token! : await getOidcToken() |
| 427 | + appToken = await exchangeForAppToken(actionToken) |
| 428 | + } |
418 | 429 | octoRest = new Octokit({ auth: appToken }) |
419 | 430 | octoGraph = graphql.defaults({ |
420 | 431 | headers: { authorization: `token ${appToken}` }, |
421 | 432 | }) |
422 | 433 |
|
423 | 434 | const { userPrompt, promptFiles } = await getUserPrompt() |
424 | | - await configureGit(appToken) |
| 435 | + if (!useGithubToken) { |
| 436 | + await configureGit(appToken) |
| 437 | + } |
425 | 438 | await assertPermissions() |
426 | 439 |
|
427 | 440 | await addReaction() |
@@ -514,8 +527,10 @@ export const GithubRunCommand = cmd({ |
514 | 527 | // Also output the clean error message for the action to capture |
515 | 528 | //core.setOutput("prepare_error", e.message); |
516 | 529 | } finally { |
517 | | - await restoreGitConfig() |
518 | | - await revokeAppToken() |
| 530 | + if (!useGithubToken) { |
| 531 | + await restoreGitConfig() |
| 532 | + await revokeAppToken() |
| 533 | + } |
519 | 534 | } |
520 | 535 | process.exit(exitCode) |
521 | 536 |
|
@@ -544,6 +559,14 @@ export const GithubRunCommand = cmd({ |
544 | 559 | throw new Error(`Invalid share value: ${value}. Share must be a boolean.`) |
545 | 560 | } |
546 | 561 |
|
| 562 | + function normalizeUseGithubToken() { |
| 563 | + const value = process.env["USE_GITHUB_TOKEN"] |
| 564 | + if (!value) return false |
| 565 | + if (value === "true") return true |
| 566 | + if (value === "false") return false |
| 567 | + throw new Error(`Invalid use_github_token value: ${value}. Must be a boolean.`) |
| 568 | + } |
| 569 | + |
547 | 570 | function isIssueCommentEvent( |
548 | 571 | event: IssueCommentEvent | PullRequestReviewCommentEvent, |
549 | 572 | ): event is IssueCommentEvent { |
|