This is a script that does various maintenance chores for go-gitea/gitea.
First, the script will fetch Gitea's current development versions from GitHub's API.
The script will look for pull requests that have the label
backport/v{gitea_version} but do not have the label backport/done. It will
clone your fork of gitea. It will then attempt to cherry-pick the pull request
merged commit into the release branch release/v{gitea_version}, where
{gitea_version} is major.minor for 1.x (1.27) and major for later
versions (28). If the cherry-pick is successful, it will push the branch to
the remote and create a pull request with the labels from the original pull
request.
Once a backport pull request is merged, the backport_branches check deletes
its branch from the bot's fork. GitHub only does this automatically when the
person merging can write to the fork.
The backport_conflict_free check labels open pull requests targeting main
that have a backport/v* label with backport/conflict-free when their changes
would cleanly cherry-pick onto the latest release branch. It checks a pull
request when it is opened or updated or a backport/v* label changes, and all
of them on pushes to release branches and on scheduled runs.
The script will also look for merged pull requests that have the label
pr/last-call and remove it.
It will also search for pull requests that target release branches and remove
any backport/* labels from them.
It will also make sure any pull requests that have ## :warning: BREAKING in
their description have the pr/breaking label.
When a pull request is created, the script will assign it a milestone based on
its target branch (except pull requests targeting main, we'll assign those on
merge). The script makes sure that unmerged closed pull requests are not
included in any milestone.
main gets the next major version's milestone (e.g. 30.0.0). Release branches
collect their next release in a line milestone (e.g. 29.x), which is renamed
to the version once it is tagged, as patch or minor is only decided then.
The script will maintain each pull request's LGTM count. It will add the
appropriate label (one of lgtm/need 2, lgtm/need 1, lgtm/done, or
lgtm/blocked) based on the number of approvals (or change requests) the pull
request has. It will also set the commit status to success if the pull request
has 2 or more approvals without changes requested (pending if not or failure
if changes are requested). Only reviews from users with at least triage access
count.
GitHub's merge queue only checks the status when a pull request enters it, so a pull request that loses its approval is taken out of the queue and its auto-merge is disabled.
The script will also comment if a pull request is opened with non-English translation files changed, directing the user to the crowdin project.
The script will also lock issues and pull requests that have been closed for 3 months. If the issue was commented on in the last two weeks, a comment will be posted suggesting opening a new issue to continue the discussion.
The script will close issues with the label issue/needs-feedback if a month
has passed since they were updated.
The script can execute some actions like updating a PR's branch if requested by
a maintainer through a giteabot/* label.
The script will close PRs with the label pr/last-call if two weeks have passed
since they were updated. If one week has passed since they were updated, it will
remind the TOC to review the PR.
-
Create a GitHub personal access token with access to
go-gitea/giteaand your fork. -
Store the following secrets in the target repository:
BACKPORTER_GITHUB_TOKEN= # GitHub personal access token BACKPORTER_GITEA_FORK= # Fork of go-gitea/gitea (e.g. yardenshoham/gitea), only needed for the backport check -
Add a workflow that invokes this action. A minimal example:
name: Gitea Backporter on: push: branches: - main - release/v* pull_request_target: types: [ opened, synchronize, labeled, unlabeled, closed, review_requested, review_request_removed, ] workflow_run: workflows: [Gitea Backporter Review] types: [requested] schedule: - cron: "15 3 * * *" workflow_dispatch: jobs: backporter: runs-on: ubuntu-latest steps: - uses: giteabot/gitea-backporter@v1 with: github_token: ${{ secrets.BACKPORTER_GITHUB_TOKEN }} gitea_fork: ${{ secrets.BACKPORTER_GITEA_FORK }} checks: all
-
pull_request_reviewruns get a read-only token and no secrets on pull requests from forks, so add a second workflow that only relays reviews to the first one throughworkflow_run. Its job never runs, the requested run alone triggers the relay. It must exist on every branch pull requests target, because review runs use the workflow from the pull request's merge ref.name: Gitea Backporter Review on: pull_request_review: types: [submitted, edited, dismissed] permissions: {} jobs: relay: if: false runs-on: ubuntu-latest steps: - run: "true"
For a more complete example with permissions, see examples/workflows.
The optional checks input controls which bot checks run in a workflow. It
accepts all, none, or a comma-separated list from:
backportbackport_branchesbackport_conflict_freelabelslockfeedbacklast_callmilestoneslgtmtranslation_commentpr_actions
For example, to run only label cleanup and milestone maintenance:
- uses: giteabot/gitea-backporter@v1
with:
github_token: ${{ secrets.BACKPORTER_GITHUB_TOKEN }}
gitea_fork: ${{ secrets.BACKPORTER_GITEA_FORK }}
checks: labels,milestonesRequires Node.js 22.18 or newer, which runs the TypeScript sources directly, and pnpm 12 or newer.
make lintruns the linter and checks typesmake lint-fixfixes lint issues where possiblemake testruns the tests
Contributions are welcome!