11name : Update Changelog
22
33on :
4- pull_request :
5- types : [opened, edited ]
4+ issue_comment :
5+ types : [created ]
66
77jobs :
88 update-changelog :
9- # Only run if this is not a PR from a fork to avoid permission issues
10- # and not a commit made by GitHub Action to avoid infinite loops
11- if : github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'github-actions[bot]'
9+ # Only run if this is a comment on a PR containing "@actions-user changelog"
10+ # and not a comment made by GitHub Action to avoid infinite loops
11+ if : github.event.issue. pull_request && contains(github.event.comment.body, '@actions-user changelog') && github.actor != 'github-actions[bot]'
1212 runs-on : ubuntu-latest
1313 permissions :
1414 contents : write
1515 pull-requests : write
1616
1717 steps :
18+ - name : Get PR details
19+ id : pr-details
20+ uses : actions/github-script@v7
21+ with :
22+ script : |
23+ const { data: pullRequest } = await github.rest.pulls.get({
24+ owner: context.repo.owner,
25+ repo: context.repo.repo,
26+ pull_number: context.issue.number
27+ });
28+ core.setOutput('number', pullRequest.number);
29+ core.setOutput('title', pullRequest.title);
30+ core.setOutput('head_ref', pullRequest.head.ref);
31+
1832 - name : Checkout repository
1933 uses : actions/checkout@v4
2034 with :
2135 # Checkout the PR head ref
22- ref : ${{ github.event.pull_request.head.ref }}
36+ ref : ${{ steps.pr-details.outputs.head_ref }}
2337 token : ${{ secrets.GITHUB_TOKEN }}
2438
2539 - name : Set up Python
3044 - name : Update changelog
3145 run : |
3246 python modify_changelog.py update_changelog \
33- "${{ github.event.pull_request .number }}" \
34- " ${{ github.event.pull_request .title }}"
47+ "${{ steps.pr-details.outputs .number }}" \
48+ ' ${{ steps.pr-details.outputs .title }}'
3549
3650 - name : Check for changes
3751 id : changes
4862 git config --local user.email "[email protected] " 4963 git config --local user.name "GitHub Action"
5064 git add docs/changelog.md
51- git commit -m "Add changelog entry for PR #${{ github.event.pull_request .number }}"
65+ git commit -m "Add changelog entry for PR #${{ steps.pr-details.outputs .number }}"
5266 git push
0 commit comments