name: Milestone tracking
on:
  pull_request:
    types: [closed]
jobs:
  add_milestone:
    runs-on: ubuntu-latest
    if: ${{ github.repository == 'dotnet/roslyn' && github.event.pull_request.merged_at != null && github.event.pull_request.milestone == null && github.event.pull_request.base.ref == 'main' }}
    steps:
    - name: Get milestone data
      env:
        ORGANIZATION: dotnet
        REPOSITORY: roslyn-analyzers
        MILESTONE_NAME: vNext
      run: |
        gh api graphql -f query='
          query($org: String!, $repo: String!, $milestone: String!) {
            repository(name: $repo, owner: $org) {
              milestones(query: $milestone, first: 2) {
                nodes {
                  id
                  title
                }
              }
            }
          }' -f org=$ORGANIZATION -f repo=$REPOSITORY -f milestone="$MILESTONE_NAME" > milestone_data.json

        cat milestone_data.json
        echo 'MILESTONE_ID='$(jq 'if (((.data.repository.milestones.nodes | length) == 1) and .data.repository.milestones.nodes[0].title == "$MILESTONE_NAME") then .data.repository.milestones.nodes[0].id else null end' label_data.json) >> $GITHUB_ENV

    - name: Assign milestone
      env:
        PULL_REQUEST_ID: ${{ github.event.pull_request.node_id }}
      run: |
        echo $MILESTONE_ID

        #gh api graphql -f query='
        #  mutation($pull: ID!, $milestone: ID!) {
        #    updatePullRequest(input: {pullRequestId: $pull, milestoneId: $milestone}) {
        #      clientMutationId
        #    }
        #  }' -f pull=$PULL_REQUEST_ID -f milestone=$MILESTONE_ID

Add milestone tracking automation (mutation disabled)
Add milestone tracking automation (mutation disabled)
