name: Issue Triage
on:
  issues:
    types: [labeled]

jobs:
  needs-repro:
    runs-on: ubuntu-20.04
    if: "${{ contains(github.event.label.name, 'incomplete issue: missing or invalid repro') }}"
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Hi there! It looks like your issue requires a minimal reproducible example, but it is invalid or absent. Please prepare such an example and share it in a new issue.

              **The best way to get attention to your issue is to provide a clean and easy way for a developer to reproduce the issue on their own machine.** Please do not provide your entire project, or a project with more code than is necessary to reproduce the issue.

              A side benefit of going through the process of narrowing down the minimal amount of code needed to reproduce the issue is that you may get lucky and discover that the bug is due to a mistake in your application code that you can quickly fix on your own.

              ### Resources

              - ["How to create a Minimal, Reproducible Example"](https://stackoverflow.com/help/minimal-reproducible-example)
              - ["How to narrow down the source of an error"](https://expo.fyi/manual-debugging)

              ### Common concerns

              #### "I've only been able to reproduce it in private, proprietary code"

              You may not have spent enough time narrowing down the root cause of the issue. Try out the techniques discussed in this [manual debugging guide](https://expo.fyi/manual-debugging) to learn how to isolate the problem from the rest of your codebase.

              #### "I didn't have time to create one"

              That's understandable, it can take some time to prepare. We ask that you hold off on filing an issue until you are able to fully complete the required fields in the issue template.

              #### "You can reproduce it by yourself by creating a project and following these steps"

              This is useful knowledge, but it's still valuable to have the resulting project that is produced from running the steps, where you have verified you can reproduce the issue.
            `})
            github.issues.update({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'closed'
            })

  needs-info:
    runs-on: ubuntu-20.04
    if: "${{ contains(github.event.label.name, 'incomplete issue: missing info') }}"
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Hello! There isn't enough information provided in your issue description for us to be able to help you. The best way to get help is to provide information to enable other developers to understand the issue and reproduce it on their own machines.

              Please create a new issue and fill out the entire issue template to the best of your ability. Refer to the following resources for more information on how to create a good issue report.

              ### Resources

              - ["How do I ask a good question?"](https://stackoverflow.com/help/how-to-ask)
              - ["How to create a Minimal, Reproducible Example"](https://stackoverflow.com/help/minimal-reproducible-example)
              - ["How to narrow down the source of an error"](https://expo.fyi/manual-debugging)
            `})
            github.issues.update({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'closed'
            })

  issue-accepted:
    runs-on: ubuntu-20.04
    if: github.event.label.name == 'issue accepted'
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Thank you for filing this issue!
              This comment acknowledges we believe this may be a bug and there’s enough information to investigate it.
              However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.
            `})

  question:
    runs-on: ubuntu-20.04
    if: "${{ contains(github.event.label.name, 'invalid issue: question') }}"
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Hello! Our GitHub issues are reserved for bug reports.

              If you have a question about Expo or related tools, please post on our forums at https://forums.expo.dev/ or join our Discord at https://chat.expo.dev/.

              ### Resources

              - ["How do I ask a good question?"](https://stackoverflow.com/help/how-to-ask)
              - ["Join the community"](https://docs.expo.dev/next-steps/community/)
            `})
            github.issues.update({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'closed'
            })

  feature-request:
    runs-on: ubuntu-20.04
    if: "${{ contains(github.event.label.name, 'invalid issue: feature request') }}"
    steps:
      - uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: `Hello! Our GitHub issues are reserved for bug reports.

              If you would like to request a feature, please post to https://expo.canny.io/feature-requests.
            `})
            github.issues.update({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'closed'
            })