-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79cb830
commit bbf08c7
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: "PR Orphaned Diff Finder" | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
orphaned-diff: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Checkout the PR | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Generate Final PR Diff | ||
id: final_diff | ||
run: | | ||
git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > final_diff.patch | ||
echo "Final diff generated." | ||
- name: Identify Orphaned Changes | ||
id: orphaned_changes | ||
run: | | ||
echo "## Orphaned Changes" > orphaned_changes.md | ||
# Fetch the base and head refs | ||
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} | ||
git fetch origin ${{ github.event.pull_request.head.ref }}:${{ github.event.pull_request.head.ref }} | ||
git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > final_diff.patch | ||
echo "## Orphaned Changes" > orphaned_changes.md | ||
commits=$(git log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} --pretty=format:"%H" --reverse) | ||
any_orphaned=false | ||
for commit in $commits; do | ||
echo "Checking commit $commit..." | ||
git diff ${commit}^ $commit > commit_diff.patch || true | ||
# Compare commit diff with final diff | ||
ORPHANED=$(diff --unchanged-line-format='' --old-line-format='%L' --new-line-format='' commit_diff.patch final_diff.patch || true) | ||
if [[ ! -z "$ORPHANED" ]]; then | ||
echo "### Commit $commit" >> orphaned_changes.md | ||
echo '```diff' >> orphaned_changes.md | ||
echo "$ORPHANED" >> orphaned_changes.md | ||
echo '```' >> orphaned_changes.md | ||
echo "" >> orphaned_changes.md | ||
any_orphaned=true | ||
fi | ||
done | ||
if [[ "$any_orphaned" = false ]]; then | ||
echo "No orphaned changes found." | ||
echo "No orphaned changes found." > orphaned_changes.md | ||
fi | ||
- name: Comment on PR with Orphaned Changes | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
header: orphaned-diff | ||
path: orphaned_changes.md |