github-app.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. export const PR_TITLE = 'Add Claude Code GitHub Workflow'
  2. export const GITHUB_ACTION_SETUP_DOCS_URL =
  3. 'https://github.com/anthropics/claude-code-action/blob/main/docs/setup.md'
  4. export const WORKFLOW_CONTENT = `name: Claude Code
  5. on:
  6. issue_comment:
  7. types: [created]
  8. pull_request_review_comment:
  9. types: [created]
  10. issues:
  11. types: [opened, assigned]
  12. pull_request_review:
  13. types: [submitted]
  14. jobs:
  15. claude:
  16. if: |
  17. (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
  18. (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
  19. (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
  20. (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
  21. runs-on: ubuntu-latest
  22. permissions:
  23. contents: read
  24. pull-requests: read
  25. issues: read
  26. id-token: write
  27. actions: read # Required for Claude to read CI results on PRs
  28. steps:
  29. - name: Checkout repository
  30. uses: actions/checkout@v4
  31. with:
  32. fetch-depth: 1
  33. - name: Run Claude Code
  34. id: claude
  35. uses: anthropics/claude-code-action@v1
  36. with:
  37. anthropic_api_key: \${{ secrets.ANTHROPIC_API_KEY }}
  38. # This is an optional setting that allows Claude to read CI results on PRs
  39. additional_permissions: |
  40. actions: read
  41. # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
  42. # prompt: 'Update the pull request description to include a summary of changes.'
  43. # Optional: Add claude_args to customize behavior and configuration
  44. # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
  45. # or https://code.claude.com/docs/en/cli-reference for available options
  46. # claude_args: '--allowed-tools Bash(gh pr:*)'
  47. `
  48. export const PR_BODY = `## 🤖 Installing Claude Code GitHub App
  49. This PR adds a GitHub Actions workflow that enables Claude Code integration in our repository.
  50. ### What is Claude Code?
  51. [Claude Code](https://claude.com/claude-code) is an AI coding agent that can help with:
  52. - Bug fixes and improvements
  53. - Documentation updates
  54. - Implementing new features
  55. - Code reviews and suggestions
  56. - Writing tests
  57. - And more!
  58. ### How it works
  59. Once this PR is merged, we'll be able to interact with Claude by mentioning @claude in a pull request or issue comment.
  60. Once the workflow is triggered, Claude will analyze the comment and surrounding context, and execute on the request in a GitHub action.
  61. ### Important Notes
  62. - **This workflow won't take effect until this PR is merged**
  63. - **@claude mentions won't work until after the merge is complete**
  64. - The workflow runs automatically whenever Claude is mentioned in PR or issue comments
  65. - Claude gets access to the entire PR or issue context including files, diffs, and previous comments
  66. ### Security
  67. - Our Anthropic API key is securely stored as a GitHub Actions secret
  68. - Only users with write access to the repository can trigger the workflow
  69. - All Claude runs are stored in the GitHub Actions run history
  70. - Claude's default tools are limited to reading/writing files and interacting with our repo by creating comments, branches, and commits.
  71. - We can add more allowed tools by adding them to the workflow file like:
  72. \`\`\`
  73. allowed_tools: Bash(npm install),Bash(npm run build),Bash(npm run lint),Bash(npm run test)
  74. \`\`\`
  75. There's more information in the [Claude Code action repo](https://github.com/anthropics/claude-code-action).
  76. After merging this PR, let's try mentioning @claude in a comment on any PR to get started!`
  77. export const CODE_REVIEW_PLUGIN_WORKFLOW_CONTENT = `name: Claude Code Review
  78. on:
  79. pull_request:
  80. types: [opened, synchronize, ready_for_review, reopened]
  81. # Optional: Only run on specific file changes
  82. # paths:
  83. # - "src/**/*.ts"
  84. # - "src/**/*.tsx"
  85. # - "src/**/*.js"
  86. # - "src/**/*.jsx"
  87. jobs:
  88. claude-review:
  89. # Optional: Filter by PR author
  90. # if: |
  91. # github.event.pull_request.user.login == 'external-contributor' ||
  92. # github.event.pull_request.user.login == 'new-developer' ||
  93. # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
  94. runs-on: ubuntu-latest
  95. permissions:
  96. contents: read
  97. pull-requests: read
  98. issues: read
  99. id-token: write
  100. steps:
  101. - name: Checkout repository
  102. uses: actions/checkout@v4
  103. with:
  104. fetch-depth: 1
  105. - name: Run Claude Code Review
  106. id: claude-review
  107. uses: anthropics/claude-code-action@v1
  108. with:
  109. anthropic_api_key: \${{ secrets.ANTHROPIC_API_KEY }}
  110. plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
  111. plugins: 'code-review@claude-code-plugins'
  112. prompt: '/code-review:code-review \${{ github.repository }}/pull/\${{ github.event.pull_request.number }}'
  113. # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
  114. # or https://code.claude.com/docs/en/cli-reference for available options
  115. `