mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
Update AI_to_merge_conflict.yml
Signed-off-by: jeet041 <mahorjitendra@gmail.com>
This commit is contained in:
parent
b1a61e5b9f
commit
07d1634c69
1 changed files with 65 additions and 41 deletions
104
.github/workflows/AI_to_merge_conflict.yml
vendored
104
.github/workflows/AI_to_merge_conflict.yml
vendored
|
@ -1,4 +1,4 @@
|
||||||
name: Auto Resolve Conflicts
|
name: AI Merge Conflict Resolver
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
|
@ -16,55 +16,79 @@ jobs:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout PR branch
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.ref }}
|
ref: ${{ github.head_ref }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0 # Needed for merge-base
|
||||||
|
|
||||||
- name: Set up Git
|
- name: Set up Git
|
||||||
run: |
|
run: |
|
||||||
git config user.name "github-actions"
|
git config user.name "github-actions"
|
||||||
git config user.email "github-actions@github.com"
|
git config user.email "actions@github.com"
|
||||||
|
|
||||||
- name: Check for merge conflicts
|
- name: Detect Merge Conflicts
|
||||||
id: check_conflicts
|
id: detect_conflicts
|
||||||
run: |
|
run: |
|
||||||
git fetch origin ${{ github.event.pull_request.base.ref }}
|
git fetch origin ${{ github.base_ref }}
|
||||||
git merge --no-commit --no-ff origin/${{ github.event.pull_request.base.ref }} || true
|
git merge --no-commit --no-ff origin/${{ github.base_ref }} || true
|
||||||
git status --porcelain | grep 'UU' || echo "NO_CONFLICTS"
|
git diff --name-only --diff-filter=U > conflict_files.txt
|
||||||
continue-on-error: true
|
CONFLICT_FILES=$(cat conflict_files.txt | xargs)
|
||||||
|
echo "conflict_files=$CONFLICT_FILES" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Extract conflicted files
|
# - name: Exit if no conflicts
|
||||||
id: conflicted_files
|
# if: steps.detect_conflicts.outputs.conflict_files == ''
|
||||||
if: steps.check_conflicts.outcome == 'success'
|
# run: echo "No merge conflicts detected. Skipping AI resolution."
|
||||||
|
|
||||||
|
- name: Resolve conflicts with AI (Bedrock)
|
||||||
|
if: steps.detect_conflicts.outputs.conflict_files != ''
|
||||||
|
id: ai_resolve
|
||||||
run: |
|
run: |
|
||||||
conflict_files=$(git status --porcelain | grep '^UU' | awk '{print $2}')
|
files="${{ steps.detect_conflicts.outputs.conflict_files }}"
|
||||||
echo "conflicted: $conflict_files"
|
result_json="{}"
|
||||||
echo "files=$conflict_files" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
# - name: Call Lambda to resolve conflicts
|
for file in $files; do
|
||||||
# if: steps.conflicted_files.outputs.files != ''
|
conflict_content=$(cat "$file")
|
||||||
# env:
|
|
||||||
# LAMBDA_URL: ${{ secrets.LAMBDA_URL }}
|
|
||||||
# run: |
|
|
||||||
# for file in ${{ steps.conflicted_files.outputs.files }}; do
|
|
||||||
# payload=$(jq -n \
|
|
||||||
# --arg file "$file" \
|
|
||||||
# --arg content "$(cat $file | base64)" \
|
|
||||||
# --arg repo "${{ github.event.repository.name }}" \
|
|
||||||
# --arg owner "${{ github.repository_owner }}" \
|
|
||||||
# --arg pr_number "${{ github.event.pull_request.number }}" \
|
|
||||||
# '{file: $file, content: $content, repo: $repo, owner: $owner, pr_number: $pr_number}')
|
|
||||||
|
|
||||||
# resolved=$(curl -s -X POST "$LAMBDA_URL" -H "Content-Type: application/json" -d "$payload")
|
# Send to Bedrock API via curl
|
||||||
|
response=$(bash -c "curl -s -X POST https://5xwi3ji63jx6n2c46rn6l7olky0himwz.lambda-url.us-east-1.on.aws \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d @- <<'EOF'
|
||||||
|
{
|
||||||
|
\"repo\": \"${{ github.repository }}\",
|
||||||
|
\"owner\": \"${{ github.repository_owner }}\",
|
||||||
|
\"repo_name\": \"${{ github.event.repository.name }}\",
|
||||||
|
\"file_path\": \"$file\",
|
||||||
|
\"conflict_content\": $(jq -Rs <<< \"$conflict_content\"),
|
||||||
|
\"pr_number\": \"${{ github.event.pull_request.number }}\",
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
")
|
||||||
|
|
||||||
# echo "$resolved" | base64 -d > "$file"
|
echo "$response" > response.json
|
||||||
# git add "$file"
|
|
||||||
# done
|
|
||||||
|
|
||||||
# - name: Commit resolved files
|
resolved_content=$(jq -r '.resolved_file_content' response.json)
|
||||||
# if: steps.conflicted_files.outputs.files != ''
|
confidence_score=$(jq -r '.confidence_score' response.json)
|
||||||
# run: |
|
|
||||||
# git commit -m "Auto-resolved conflicts via Lambda"
|
echo "$resolved_content" > "$file"
|
||||||
# git push origin HEAD:${{ github.event.pull_request.head.ref }}
|
git add "$file"
|
||||||
|
|
||||||
|
echo "::set-output name=confidence_score::$confidence_score"
|
||||||
|
echo "::set-output name=resolved_file::$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Commit and Push Resolved Files
|
||||||
|
if: steps.detect_conflicts.outputs.conflict_files != ''
|
||||||
|
run: |
|
||||||
|
git commit -m "Auto-resolved merge conflicts using AI 🤖"
|
||||||
|
git push origin HEAD:${{ github.head_ref }}
|
||||||
|
|
||||||
|
- name: Comment on PR with Confidence Score
|
||||||
|
if: steps.detect_conflicts.outputs.conflict_files != ''
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PAT_TOKEN }}
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
✅ Conflicts in `${{ steps.ai_resolve.outputs.resolved_file }}` were resolved using AI.
|
||||||
|
**Confidence Score:** `${{ steps.ai_resolve.outputs.confidence_score }}`
|
||||||
|
|
Loading…
Reference in a new issue