name: Auto Close Issue
on:
  issues:
    types: [labeled]

jobs:
  auto-close:
    runs-on: ubuntu-latest
    steps:
      - name: Close Outdate issue
        if: ${{ github.event.label.name == 'Outdate' || github.event.label.name == 'stale' }}
        uses: peter-evans/close-issue@v1
        with:
          comment: |
            This issue has been closed because **it has been outdate for a long time**.
            Please open a new issue if you still need help.

            这个 issue 已经被关闭，因为 **它已经过期很久了**。
            如果你仍然需要帮助，请创建一个新的 issue。
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Close Duplicate issue
        if: ${{ github.event.label.name == 'Duplicate' }}
        uses: peter-evans/close-issue@v1
        with:
          comment: |
            This issue has been closed because **it is duplicated**.

            这个 issue 已经被关闭，因为 **它是一个重复的 issue**。
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Close Invalid issue
        if: ${{ github.event.label.name == 'Invalid' }}
        uses: peter-evans/close-issue@v1
        with:
          comment: |
            This issue has been closed because **it is invalid**.

            这个 issue 已经被关闭，因为 **它是无效的**。
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Warning Bad Issue
        if: ${{ github.event.label.name == 'Need Improvement' }}
        run: gh issue comment "$NUMBER" --body "$BODY"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_REPO: ${{ github.repository }}
          NUMBER: ${{ github.event.issue.number }}
          BODY: >
            Please provide more information, or use the standard format, otherwise we will not process this issue.

            Reference document: 
            
              - [Creating an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/creating-an-issue)
              - [Basic writing and formatting syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
            
            ---
            
            请提供更多信息，或者使用规范的格式，否则我们不会处理这个 issue。

            参考文档：

              - [创建议题](https://docs.github.com/zh/issues/tracking-your-work-with-issues/using-issues/creating-an-issue)
              - [基本撰写和格式语法](https://docs.github.com/zh/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)

