name: Danger

on:
  pull_request_target:
    types: [opened, synchronize]

permissions:
  pull-requests: write
  statuses: write

jobs:
  danger:
    runs-on: ubuntu-22.04
    steps:
      - name: Check out code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Setup ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.1
          rubygems: 3.4.10
          bundler-cache: true
      - name: Create base branch
        run: |
          git fetch ${{ github.event.pull_request.base.repo.clone_url }} ${{ github.event.pull_request.base.sha }}:danger_base
      - name: Create head branch
        run: |
          git fetch ${{ github.event.pull_request.head.repo.clone_url }} ${{ github.event.pull_request.head.sha }}:danger_head
      - name: Danger
        env:
          DANGER_GITHUB_BEARER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          bundle exec danger --verbose
