@@ -162,26 +162,63 @@ jobs:
162162 run : |
163163 git push origin automated-translations
164164
165- - name : Create Pull Request
165+ - name : Create or Update Pull Request
166166 if : env.has_changes == 'true'
167- uses : peter-evans/create-pull-request@v7
167+ uses : actions/github-script@v8
168168 with :
169- title : " Automated translation updates"
170- base : " main"
171- branch : " automated-translations"
172- delete-branch : false
173- labels : |
174- content/other
175- add-paths : |
176- website/i18n/**/*.md
177- body : |
178- ## Automated Translation Updates
179-
180- This PR contains automated translation updates generated from the latest changes in `main`.
169+ script : |
170+ const owner = context.repo.owner;
171+ const repo = context.repo.repo;
172+ const head = 'automated-translations';
173+ const base = 'main';
174+
175+ const body = `## Automated Translation Updates
176+
177+ This PR contains automated translation updates generated from the latest changes in \`main\`.
181178
182179 ### Changes
183- - Branch was rebased on latest `main` before translation
180+ - Branch was rebased on latest \ `main\ ` before translation
184181 - Translations generated from latest content
185182 - Previous translation work preserved through rebase
186-
187- Please review the translations before merging.
183+ - Generated from commit: ${context.sha}
184+ - Workflow run: ${context.runId}
185+
186+ Please review the translations before merging.`;
187+
188+ // Check for existing open PR
189+ const { data: pulls } = await github.rest.pulls.list({
190+ owner,
191+ repo,
192+ head: `${owner}:${head}`,
193+ base,
194+ state: 'open',
195+ });
196+
197+ if (pulls.length > 0) {
198+ const prNumber = pulls[0].number;
199+ console.log(`PR #${prNumber} already exists, updating body`);
200+ await github.rest.pulls.update({
201+ owner,
202+ repo,
203+ pull_number: prNumber,
204+ body,
205+ });
206+ } else {
207+ console.log('Creating new PR');
208+ const { data: pr } = await github.rest.pulls.create({
209+ owner,
210+ repo,
211+ title: 'Automated translation updates',
212+ head,
213+ base,
214+ body,
215+ });
216+ // Add label after creation
217+ await github.rest.issues.addLabels({
218+ owner,
219+ repo,
220+ issue_number: pr.number,
221+ labels: ['content/other'],
222+ });
223+ console.log(`Created PR #${pr.number}`);
224+ }
0 commit comments