Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/sync-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: task-wait-merge-label
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow name 'task-wait-merge-label' is inconsistent with the file name 'sync-prs.yml'. Based on other workflows in this repository (e.g., 'cron-licenses' in cron-licenses.yml, 'labeler' in pull-labeler.yml), the name should match the file name more closely. Consider renaming the workflow to 'sync-prs' to match the file name, or rename the file to 'task-wait-merge-label.yml' to match the workflow name.

Suggested change
name: task-wait-merge-label
name: sync-prs

Copilot uses AI. Check for mistakes.

on:
push:
branches:
- main
workflow_dispatch:
Comment on lines +3 to +7
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow triggers on every push to main, which could result in frequent executions when there are multiple commits pushed to main in quick succession. Other workflows in this repository that perform scheduled maintenance tasks (like cron-licenses.yml and cron-translations.yml) use a schedule trigger with workflow_dispatch as a fallback. Consider using a schedule trigger instead (e.g., running every few hours or daily) to reduce unnecessary workflow executions, while keeping workflow_dispatch for manual runs.

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the release-nightly.yml workflow which also triggers on push to main, this workflow should include a concurrency configuration to prevent multiple instances from running simultaneously. This is especially important to avoid race conditions when updating PRs or removing labels. Add a concurrency section with group and cancel-in-progress settings.

Suggested change
concurrency:
group: task-wait-merge-label-${{ github.ref }}
cancel-in-progress: true

Copilot uses AI. Check for mistakes.
jobs:
update-prs:
if: github.repository == 'go-gitea/gitea'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Update all PRs with reviewed/wait-merge label
env:
GH_TOKEN: ${{ secrets.PR_UPDATE_TOKEN }}
run: |
gh auth status || exit 1
prs=$(gh pr list --repo ${{ github.repository }} --label "reviewed/wait-merge" --state open --json number --jq '.[].number')
if [ -z "$prs" ]; then
echo "No PRs found with 'reviewed/wait-merge' label"
exit 0
fi
failed=0
for pr_number in $prs; do
if gh api --method PUT \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/pulls/$pr_number/update-branch"; then
echo "#$pr_number PR succeeded"
else
echo "#$pr_number PR failed"
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo ""
echo "One or more PRs failed to update. Possible reasons:"
echo "- Merge conflicts with main"
echo "- PR is from a fork and 'Allow edits from maintainers' is disabled"
echo "- Branch belongs to an organization that disallows maintainer edits"
echo "- Required status checks or branch protections blocked the update"
fi
exit $failed
cleanup-labels:
if: github.repository == 'go-gitea/gitea'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Remove label from closed PRs
env:
GH_TOKEN: ${{ secrets.PR_UPDATE_TOKEN }}
run: |
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup-labels job does not verify authentication status before attempting to remove labels, unlike the update-prs job which checks 'gh auth status' on line 20. For consistency and to catch authentication issues early, consider adding the same authentication check at the beginning of this job's script.

Suggested change
run: |
run: |
gh auth status || exit 1

Copilot uses AI. Check for mistakes.
closed_prs=$(gh pr list --repo ${{ github.repository }} --label "reviewed/wait-merge" --state closed --json number --jq '.[].number')
if [ -z "$closed_prs" ]; then
echo "No closed PRs found with 'reviewed/wait-merge' label"
exit 0
fi
for pr_number in $closed_prs; do
if gh pr edit "$pr_number" --repo ${{ github.repository }} --remove-label "reviewed/wait-merge"; then
echo "#$pr_number label removed"
else
echo "#$pr_number failed to remove label"
fi
done
Comment on lines +69 to +76
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup-labels job should include error handling similar to the update-prs job. Currently, if removing a label fails, the error is only logged but doesn't affect the exit code. Consider tracking failures and exiting with a non-zero code if any labels fail to be removed, similar to how the update-prs job handles failures.

Suggested change
for pr_number in $closed_prs; do
if gh pr edit "$pr_number" --repo ${{ github.repository }} --remove-label "reviewed/wait-merge"; then
echo "#$pr_number label removed"
else
echo "#$pr_number failed to remove label"
fi
done
failed=0
for pr_number in $closed_prs; do
if gh pr edit "$pr_number" --repo ${{ github.repository }} --remove-label "reviewed/wait-merge"; then
echo "#$pr_number label removed"
else
echo "#$pr_number failed to remove label"
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo ""
echo "One or more labels failed to be removed from closed PRs."
fi
exit $failed

Copilot uses AI. Check for mistakes.