name: Move labelled issues to correct boards and columns

on:
  issues:
    types: [labeled]

jobs:
  apply_Z-Labs_label:
    name: Add Z-Labs label for features behind labs flags
    runs-on: ubuntu-latest
    if: >
      contains(github.event.issue.labels.*.name, 'A-Maths') || 
      contains(github.event.issue.labels.*.name, 'A-Message-Pinning') ||
      contains(github.event.issue.labels.*.name, 'A-Polls') ||
      contains(github.event.issue.labels.*.name, 'A-Location-Sharing') ||
      contains(github.event.issue.labels.*.name, 'A-Message-Bubbles') ||
      contains(github.event.issue.labels.*.name, 'Z-IA') ||
      contains(github.event.issue.labels.*.name, 'A-Themes-Custom') ||
      contains(github.event.issue.labels.*.name, 'A-E2EE-Dehydration') ||
      contains(github.event.issue.labels.*.name, 'A-Tags') ||
      contains(github.event.issue.labels.*.name, 'A-Rich-Text-Editor')
    steps:
      - uses: actions/github-script@v5
        with:
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['Z-Labs']
            })

  add_priority_design_issues_to_project:
    name: P1 X-Needs-Design to Design project board
    runs-on: ubuntu-latest
    if: >
      contains(github.event.issue.labels.*.name, 'X-Needs-Design') &&
      (contains(github.event.issue.labels.*.name, 'S-Critical') &&
       (contains(github.event.issue.labels.*.name, 'O-Frequent') ||
        contains(github.event.issue.labels.*.name, 'O-Occasional')) ||
       (contains(github.event.issue.labels.*.name, 'S-Major') &&
       contains(github.event.issue.labels.*.name, 'O-Frequent')) ||
       contains(github.event.issue.labels.*.name, 'A11y'))
    steps:
      - uses: actions/add-to-project@main
        with:
          project-url: https://github.com/orgs/element-hq/projects/18
          github-token: ${{ secrets.ELEMENT_BOT_TOKEN }}

  add_product_issues_to_project:
    name: X-Needs-Product to Design project board
    runs-on: ubuntu-latest
    if: >
      contains(github.event.issue.labels.*.name, 'X-Needs-Product')
    steps:
      - uses: actions/add-to-project@main
        with:
          project-url: https://github.com/orgs/element-hq/projects/28
          github-token: ${{ secrets.ELEMENT_BOT_TOKEN }}
