|
| 1 | +name: Generate Changelog for PR |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: |
| 6 | + - created |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + changelog: |
| 13 | + name: Generate Changelog for PR |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + pull-requests: write |
| 18 | + if: > |
| 19 | + github.event.issue.pull_request && |
| 20 | + github.event.comment.body == '/changelog' |
| 21 | + steps: |
| 22 | + - name: Verify OpenAI API Key is available |
| 23 | + run: | |
| 24 | + if [ -z "${OPENAI_API_KEY}" ]; then |
| 25 | + echo "OPENAI_API_KEY is not set." |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | + env: |
| 29 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 30 | + |
| 31 | + - name: Check if user has write access |
| 32 | + id: check_access |
| 33 | + uses: actions/github-script@v7.0.1 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { data: membership } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + username: context.payload.comment.user.login |
| 40 | + }); |
| 41 | + if (membership.permission !== 'write' && membership.permission !== 'admin' && membership.permission !== 'maintain') { |
| 42 | + core.setFailed(`User ${context.payload.comment.user.login} does not have write access.`); |
| 43 | + } else { |
| 44 | + core.setOutput("authorized", 'true'); |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Generate Changelog Entry |
| 48 | + if: steps.check_access.outputs.authorized == 'true' |
| 49 | + id: changelog |
| 50 | + uses: Automattic/vip-actions/ai-changelog@429a448961152b194fd94df2ce9c82fc293e3ec7 # trunk |
| 51 | + with: |
| 52 | + pr_number: ${{ github.event.issue.number }} |
| 53 | + openai_api_key: ${{ secrets.OPENAI_API_KEY }} |
| 54 | + |
| 55 | + - name: Find Comment |
| 56 | + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 |
| 57 | + if: steps.check_access.outputs.authorized == 'true' |
| 58 | + id: fc |
| 59 | + with: |
| 60 | + issue-number: ${{ github.event.issue.number }} |
| 61 | + comment-author: 'github-actions[bot]' |
| 62 | + body-includes: '## AI-Generated Changelog Entry' |
| 63 | + |
| 64 | + - name: Post Changelog Comment |
| 65 | + if: > |
| 66 | + steps.check_access.outputs.authorized == 'true' && |
| 67 | + steps.changelog.outputs.changelog-entry |
| 68 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 69 | + with: |
| 70 | + issue-number: ${{ github.event.issue.number }} |
| 71 | + body: | |
| 72 | + ## AI-Generated Changelog Entry |
| 73 | +
|
| 74 | + ${{ steps.changelog.outputs.changelog-entry }} |
| 75 | +
|
| 76 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 77 | + edit-mode: replace |
0 commit comments