name: Feature freeze check

on:
  pull_request_target:
    types:
      - opened
    branches:
      - master
    paths:
      - 'clippy_lints/src/declared_lints.rs'

jobs:
  auto-comment:
    runs-on: ubuntu-latest

    permissions:
      pull-requests: write

    # Do not in any case add code that runs anything coming from the content
    # of the pull request, as malicious code would be able to access the private
    # GitHub token.
    steps:
      - name: Add freeze warning comment
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPOSITORY: ${{ github.repository }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: |
          COMMENT=$(echo "**Seems that you are trying to add a new lint!**\n\
          \n\
          We are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to September 18 and [focusing on bugfixes](https://github.com/rust-lang/rust-clippy/issues/15086).\n\
          \n\
          Thanks a lot for your contribution, and sorry for the inconvenience.\n\
          \n\
          With ❤ from the Clippy team.\n\
          \n\
          @rustbot note Feature-freeze\n\
          @rustbot blocked\n\
          @rustbot label +A-lint"
          )
          curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
             -H "Content-Type: application/vnd.github.raw+json" \
             -X POST \
             --data "{\"body\":\"${COMMENT}\"}" \
             "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments"
