name: "Pull Request auto-label"

on:
  # Including 'on push' trigger, so that PRs touching the same files as push are checked for conflicts.
  # PR can be rebased (against main brnach) to resolve conflicts.
  push:
    branches: [ main ]
  pull_request_target:
    types: [ opened, synchronize ]

jobs:
  conflicts:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Update PRs with conflict labels
        uses: eps1lon/actions-label-merge-conflict@fd1f295ee7443d13745804bc49fe158e240f6c6e # releases/2.1.0
        with:
          dirtyLabel: "conflicts"
          #removeOnDirtyLabel: "PR: ready to ship"
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          commentOnDirty: "This pull request has conflicts with the base branch, please resolve those so that we can review the pull request."
          commentOnClean: "Conflicts have been resolved! 🎉 A maintainer will soon review the pull request."

  size:
    if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
    permissions:
      issues: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - uses: codelytv/pr-size-labeler@54ef36785e9f4cb5ecf1949cfc9b00dbb621d761 # v1.8.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          xs_label: 'size/xs'
          xs_max_size: 35
          s_label: 'size/s'
          s_max_size: 75
          m_label: 'size/m'
          m_max_size: 150
          l_label: 'size/l'
          l_max_size: 300
          xl_label: 'size/xl'
          message_if_xl: >
            This PR exceeds the recommended size of 300 lines (counting both additions & deletions).
            Kindly ensure that you are NOT addressing multiple issues in one PR.
            We recommend you to create atomic PRs which focus on a single change.
