name: PullRequest Checker

on:
  pull_request:
    types:
      - closed
    paths-ignore:
      - 'docs/**'

jobs:
  read-file:
    runs-on: ubuntu-latest
    outputs:
      require-result: ${{ steps.contributors.outputs.content }}
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Read contributors.json
        id: contributors
        uses: juliangruber/read-file-action@v1
        with:
          path: ./contributors.json

  output-log:
    runs-on: ubuntu-latest
    needs: read-file
    steps:
      - name: contributors.json
        run: echo "${{ needs.read-file.outputs.require-result }}"
      - name: creator
        run: echo "${{ github.event.pull_request.user.login }}"
      - name: contains
        run: echo "${{ contains(fromJSON(needs.read-file.outputs.require-result), github.event.pull_request.user.login) }}"
      - name: merged
        run: echo "${{ github.event.pull_request.merged }}"

  check-merged:
    runs-on: ubuntu-latest
    needs: read-file
    permissions:
      issues: write
      pull-requests: write
    if: contains(fromJSON(needs.read-file.outputs.require-result), github.event.pull_request.user.login) == false && github.event.pull_request.merged == true
    steps:
      - uses: actions-cool/maintain-one-comment@v3
        with:
          body: 感谢 PR!如果有兴趣一起参与维护 Umi,可加入我们的 Umi Contributor 群。加入方式是先用钉钉扫下方二维码加我钉钉,记得注明 github id,然后我会拉你到群里。<br /><img src="https://img.alicdn.com/imgextra/i2/O1CN01DLiPrU1WsbDdnwRr9_!!6000000002844-2-tps-340-336.png" width="20%"/>