diff --git a/.github/workflows/review-sdk.yml b/.github/workflows/review-sdk.yml new file mode 100644 index 0000000000..2bdef89dcc --- /dev/null +++ b/.github/workflows/review-sdk.yml @@ -0,0 +1,52 @@ +name: Review automatic pull requests +on: + pull_request_target: + types: [opened, ready_for_review] +permissions: + issues: write + pull-requests: write +jobs: + auto_review: + runs-on: ubuntu-latest + if: ${{ github.repository == 'dotnet/roslyn-analyzers' && (github.event.pull_request.user.login == 'dotnet-bot' || github.event.pull_request.user.login == 'dotnet-maestro[bot]') }} + steps: + - name: Create review + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PULL_REQUEST_ID: ${{ github.event.pull_request.node_id }} + run: | + gh api graphql -f query=' + mutation($pull: ID!) { + addPullRequestReview(input: {pullRequestId: $pull}) { + pullRequestReview { + id + } + } + }' -f pull=$PULL_REQUEST_ID > data.json + + cat data.json + echo 'REVIEW_ID='$(jq -r '.data.addPullRequestReview.pullRequestReview.id' data.json) >> $GITHUB_ENV + + - name: Submit approval + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: ${{ env.REVIEW_ID != '' && env.REVIEW_ID != 'null' && !contains(github.event.pull_request.body, 'Updates sdk.version') }} + run: | + gh api graphql -f query=' + mutation($review: ID!) { + submitPullRequestReview(input: {pullRequestReviewId: $review, event: APPROVE, body: "Auto-approve"}) { + clientMutationId + } + }' -f review=$REVIEW_ID + + - name: Submit change request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: ${{ env.REVIEW_ID != '' && env.REVIEW_ID != 'null' && contains(github.event.pull_request.body, 'Updates sdk.version') }} + run: | + gh api graphql -f query=' + mutation($review: ID!) { + submitPullRequestReview(input: {pullRequestReviewId: $review, event: REQUEST_CHANGES, body: "This PR changes the .NET SDK version. Review required from @dotnet/roslyn-infrastructure before merging."}) { + clientMutationId + } + }' -f review=$REVIEW_ID