name: TAKT Action

on:
  issue_comment:
    types: [created]

jobs:
  takt:
    # Uncomment to allow organization members or collaborators:
    # || github.event.comment.author_association == 'MEMBER'
    # || github.event.comment.author_association == 'COLLABORATOR'
    if: |
      contains(github.event.comment.body, '@takt') &&
      github.event.comment.author_association == 'OWNER'
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v4

      - uses: nrslib/takt-action@main
        with:
          anthropic_api_key: ${{ secrets.TAKT_ANTHROPIC_API_KEY }}
          model: ${{ vars.TAKT_MODEL }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
          log_output: ${{ vars.TAKT_LOG_OUTPUT || 'false' }}

      - name: Notify Slack
        if: always()
        uses: slackapi/slack-github-action@v2.0.0
        with:
          webhook-type: incoming-webhook
          webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
          payload: |
            {
              "text": "${{ job.status == 'success' && '✅' || '⚠️' }} TAKT Action ${{ job.status }}",
              "blocks": [
                {
                  "type": "section",
                  "text": {
                    "type": "mrkdwn",
                    "text": "*${{ job.status == 'success' && '✅' || '⚠️' }} TAKT Action ${{ job.status }}*\n<${{ github.event.issue.html_url }}|Issue #${{ github.event.issue.number }}>: ${{ github.event.issue.title }}\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>"
                  }
                },
                {
                  "type": "context",
                  "elements": [
                    {
                      "type": "mrkdwn",
                      "text": "Triggered by @${{ github.event.comment.user.login }}"
                    }
                  ]
                }
              ]
            }