name: Automated code review

on:
  pull_request:
  push:
    branches:
      - dev
  workflow_dispatch:

concurrency:
  group: automated-review-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  codeql:
    name: CodeQL
    runs-on: ubuntu-latest
    timeout-minutes: 20
    permissions:
      contents: read
      packages: read
      security-events: write
    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v4
        with:
          languages: javascript-typescript

      - name: Analyze JavaScript and TypeScript
        uses: github/codeql-action/analyze@v4
        with:
          category: /language:javascript-typescript

  dependency-review:
    name: Dependency review
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Review dependency changes
        uses: actions/dependency-review-action@v5
        with:
          fail-on-severity: high
