|
| 1 | +name: Auto-accept CLA for bot PRs |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + cla-accept: |
| 9 | + name: Accept CLA |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: | |
| 12 | + github.repository == 'microsoft/fluentui-react-native' && |
| 13 | + github.event.issue.pull_request != null && |
| 14 | + contains(github.event.comment.user.login, 'microsoft-github-policy-service') |
| 15 | +
|
| 16 | + steps: |
| 17 | + - name: Generate token |
| 18 | + uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 |
| 19 | + id: app-token |
| 20 | + with: |
| 21 | + app-id: ${{ vars.APP_ID }} |
| 22 | + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} |
| 23 | + permission-pull-requests: read |
| 24 | + permission-issues: write |
| 25 | + |
| 26 | + - name: Accept CLA if bot-authored PR |
| 27 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 |
| 28 | + with: |
| 29 | + github-token: ${{ steps.app-token.outputs.token }} |
| 30 | + script: | |
| 31 | + const pr = await github.rest.pulls.get({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + pull_number: context.issue.number, |
| 35 | + }); |
| 36 | +
|
| 37 | + if (pr.data.user.login !== 'microsoft-react-native-sdk[bot]') { |
| 38 | + console.log(`PR author ${pr.data.user.login} is not the release bot — skipping`); |
| 39 | + return; |
| 40 | + } |
| 41 | +
|
| 42 | + const { data: comments } = await github.rest.issues.listComments({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + issue_number: context.issue.number, |
| 46 | + }); |
| 47 | +
|
| 48 | + const alreadyAgreed = comments.some(c => |
| 49 | + c.body.includes('@microsoft-github-policy-service agree') |
| 50 | + ); |
| 51 | +
|
| 52 | + if (alreadyAgreed) { |
| 53 | + console.log('CLA already accepted — skipping'); |
| 54 | + return; |
| 55 | + } |
| 56 | +
|
| 57 | + await github.rest.issues.createComment({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + issue_number: context.issue.number, |
| 61 | + body: '@microsoft-github-policy-service agree company="Microsoft"', |
| 62 | + }); |
| 63 | + console.log('CLA accepted'); |
0 commit comments