name: Assign issue
on:
  issues:
    types: [opened]
jobs:
  run-action:
    runs-on: ubuntu-latest
    steps:
    - name: Get current oncall
      id: oncall
      run: |
        echo "CURRENT=$(curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=P5VG2BX&earliest=true' --header 'Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Content-Type: application/json' | jq -r '.oncalls[].user.name')" >> $GITHUB_OUTPUT
    
    - name: add_assignees
      run: |
        curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/issues/${{ github.event.issue.number}}/assignees -d '{"assignees":["${{steps.oncall.outputs.CURRENT}}"]}'

    - uses: actions/add-to-project@v0.4.0
      name: Add to Project Board
      with:
        project-url: https://github.com/orgs/actions/projects/12                       
        github-token: ${{ secrets.CACHE_BOARD_TOKEN }}