Created
April 3, 2025 18:05
-
-
Save syarihu/86d4f0486692cad23327c17df97d4e2e to your computer and use it in GitHub Desktop.
GitHub Actions workflow to generate a list of merged pull requests and update pull requests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update merged pr diff | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
update-merged-pr-diff: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Replace release diff | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const baseBranch = context.payload.pull_request.base.ref; | |
const branchName = context.payload.pull_request.head.ref; | |
const { execSync } = require('child_process'); | |
const logOutput = execSync(`git log --merges --pretty="%s" origin/${baseBranch}..origin/${branchName} | grep -oE \'#[0-9]+\' | sed \'s/#/- #/\'`).toString(); | |
const mergedPrsOutput = logOutput.replace(/\r\n/g, '\n'); | |
const body = context.payload.pull_request.body; | |
const replacedBody = body.replace(/<!--pr_diff_start-->.*<!--pr_diff_end-->/s, `<!--pr_diff_start-->\n\n${mergedPrsOutput}\n<!--pr_diff_end-->`); | |
github.rest.pulls.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
body: replacedBody | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment