|
| 1 | +name: AI On-Demand Assistant |
| 2 | +description: "Provides AI assistance when @efp-dev-ops is mentioned by authorized users" |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + pull_request_review_comment: |
| 7 | + types: [created] |
| 8 | + pull_request_review: |
| 9 | + types: [submitted] |
| 10 | + issues: |
| 11 | + types: [opened] |
| 12 | + |
| 13 | +jobs: |
| 14 | + ai-response: |
| 15 | + # Only run if the app is mentioned and it's not the app itself commenting |
| 16 | + if: | |
| 17 | + ( |
| 18 | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@efp-dev-ops')) || |
| 19 | + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@efp-dev-ops')) || |
| 20 | + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@efp-dev-ops')) || |
| 21 | + (github.event_name == 'issues' && contains(github.event.issue.body, '@efp-dev-ops')) |
| 22 | + ) && contains(fromJSON(vars.ALLOWED_USER_LIST), github.actor) |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + issues: write |
| 27 | + pull-requests: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout Code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 1 |
| 34 | + |
| 35 | + - name: Generate Custom App Token |
| 36 | + id: generate-token |
| 37 | + uses: actions/create-github-app-token@v1 |
| 38 | + with: |
| 39 | + app-id: ${{ secrets.APP_ID }} |
| 40 | + private-key: ${{ secrets.PRIVATE_KEY }} |
| 41 | + |
| 42 | + - name: Extract Instruction from Comment |
| 43 | + id: extract-instruction |
| 44 | + run: | |
| 45 | + # Get the comment body based on event type |
| 46 | + if [ "${{ github.event_name }}" = "issue_comment" ]; then |
| 47 | + COMMENT_BODY="${{ github.event.comment.body }}" |
| 48 | + elif [ "${{ github.event_name }}" = "pull_request_review_comment" ]; then |
| 49 | + COMMENT_BODY="${{ github.event.comment.body }}" |
| 50 | + elif [ "${{ github.event_name }}" = "pull_request_review" ]; then |
| 51 | + COMMENT_BODY="${{ github.event.review.body }}" |
| 52 | + elif [ "${{ github.event_name }}" = "issues" ]; then |
| 53 | + COMMENT_BODY="${{ github.event.issue.body }}" |
| 54 | + else |
| 55 | + COMMENT_BODY="" |
| 56 | + fi |
| 57 | + |
| 58 | + # Remove the @mention and get the instruction |
| 59 | + INSTRUCTION=$(echo "$COMMENT_BODY" | sed 's/@efp-dev-ops[[:space:]]*//' | sed 's/^[[:space:]]*//') |
| 60 | + |
| 61 | + # Add input validation |
| 62 | + if [ ${#INSTRUCTION} -gt 4000 ]; then |
| 63 | + echo "Instruction too long, truncating..." |
| 64 | + INSTRUCTION=$(echo "$INSTRUCTION" | head -c 4000) |
| 65 | + fi |
| 66 | + |
| 67 | + # Set as output for next step |
| 68 | + echo "instruction<<EOF" >> $GITHUB_OUTPUT |
| 69 | + echo "$INSTRUCTION" >> $GITHUB_OUTPUT |
| 70 | + echo "EOF" >> $GITHUB_OUTPUT |
| 71 | + |
| 72 | + echo "Extracted instruction: $INSTRUCTION" |
| 73 | + |
| 74 | + - name: AI Response |
| 75 | + uses: anthropics/claude-code-action@v0 |
| 76 | + continue-on-error: true |
| 77 | + timeout-minutes: 10 |
| 78 | + with: |
| 79 | + # anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 80 | + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |
| 81 | + github_token: ${{ steps.generate-token.outputs.token }} |
| 82 | + direct_prompt: | |
| 83 | + You are an AI assistant for our development team. A team member has requested help with the following: |
| 84 | + |
| 85 | + **User Request:** ${{ steps.extract-instruction.outputs.instruction }} |
| 86 | + |
| 87 | + Please provide a helpful, accurate response. If the request involves code analysis, focus on the current repository context. If it's a general question, provide clear and actionable guidance. |
| 88 | + |
| 89 | + Keep your response concise but thorough, and format it nicely for GitHub comments. |
0 commit comments