-
Notifications
You must be signed in to change notification settings - Fork 178
117 lines (101 loc) · 4.16 KB
/
Copy pathauto-fix.yml
File metadata and controls
117 lines (101 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Auto-Fix and PR Creator
on:
issues:
types: [labeled]
workflow_dispatch:
inputs:
number:
description: 'Issue number to fix'
required: true
title:
description: 'Issue Title'
required: true
body:
description: 'Issue Body'
required: true
jobs:
auto-fix:
if: "${{ github.event.label.name == 'agent: create-pr' || github.event_name == 'workflow_dispatch' }}"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO || secrets.GITHUB_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: Run Auto-Fix Script
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
ISSUE_TITLE: ${{ github.event.issue.title || github.event.inputs.title }}
ISSUE_BODY: ${{ github.event.issue.body || github.event.inputs.body }}
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.number }}
run: |
python .github/scripts/create_pr.py
- name: Verify Compilation
id: compile_check
run: |
# Try compiling to ensure the generated code is correct
./gradlew compileDebugKotlin --no-daemon || echo "failed" > compile_status.txt
- name: Report Compilation Failure
if: hashFiles('compile_status.txt') != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.number }}
run: |
gh issue comment "$ISSUE_NUMBER" --body "⚠️ The **Auto-Fix Agent** attempted to generate a patch for this issue, but the code failed to compile. Maintainers have been notified to inspect the changes manually."
exit 1
- name: Push Changes and Create Pull Request
env:
GH_TOKEN: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO || secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.number }}
run: |
# Read metadata generated by Python script
BRANCH_NAME=$(jq -r '.branch_name' pr_metadata.json)
COMMIT_MESSAGE=$(jq -r '.commit_message' pr_metadata.json)
PR_TITLE=$(jq -r '.pr_title' pr_metadata.json)
PR_BODY=$(jq -r '.pr_body' pr_metadata.json)
# Git configuration
git config --global user.name "googlemaps-bot"
git config --global user.email "googlemaps-bot@google.com"
# Create branch and commit
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "$COMMIT_MESSAGE"
# Push branch
git push origin "$BRANCH_NAME" --force
# Create Pull Request
gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--head "$BRANCH_NAME" \
--base main
# Add a comment to the issue
gh issue comment "$ISSUE_NUMBER" --body "🚀 The **Auto-Fix Agent** has successfully generated a patch and created a Pull Request to address this issue! Please review the proposed changes."
# Remove 'agent: create-pr' label
gh issue edit "$ISSUE_NUMBER" --remove-label "agent: create-pr" || true