name: 自动加入慢速审核队列

on:
  issue_comment:
    types: [created]  # 监听评论创建事件

jobs:
  add-slowqueue-label:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        
      - name: Get repository collaborators
        id: get-collaborators
        run: |
          # 获取所有仓库协作者的 GitHub 用户名（包括管理员）
          collaborators=$(gh repo collaborators --json login -q '.[].login')
          echo "::set-output name=collaborators::$collaborators"

      - name: Add "Slow Queue" label if "!slowqueue" command is used
        if: contains(github.event.comment.body, '!slowqueue') && contains(steps.get-collaborators.outputs.collaborators, github.actor)
        run: |
          echo "Admin is adding 'Slow Queue' label to PR #${{ github.event.issue.number }}"
          gh pr edit ${{ github.event.issue.number }} --add-label "慢速审核队列"

      - name: Auto reply to PR with preset message
        if: contains(github.event.comment.body, '!slowqueue') && contains(steps.get-collaborators.outputs.collaborators, github.actor)
        run: |
          echo "Admin is replying to PR #${{ github.event.issue.number }} with preset message"
          # 使用 GitHub API 或 gh CLI 回复 PR 评论
          COMMENT_BODY="您好，我们发现您的投稿似乎存在一些瑕疵，需要一些时间进行额外确认，请耐心等待。感谢您对本项目的支持！"
          gh pr comment ${{ github.event.issue.number }} --body "$COMMENT_BODY"

env:
  GITHUB_TOKEN: ${ secrets.GITHUB_TOKEN }}
