- Go 97.4%
- Shell 2.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Forgejo drops a REQUEST_REVIEW entry once its reviewer reviews, so the rule reads requested_reviewers and REQUEST_REVIEW entries, then each reviewer's latest verdict. Team requests are not resolved to members; any pending one blocks. Reviewed-on: #5 |
||
| .forgejo/workflows | ||
| assets/scripts | ||
| bin | ||
| cmd | ||
| doctor/build | ||
| internal | ||
| orders | ||
| .gitignore | ||
| CHANGELOG.md | ||
| go.mod | ||
| pack.toml | ||
| README.md | ||
gascity-forgejo-pack
A Gas City pack that merges approved Forgejo pull requests and sends pull
requests with feedback back to their beads. The merge-ready and rework
commands act on the repository named by the origin remote of their working
directory.
Installation
The merge-ready and rework commands are built from the pack's source on
first use and by gc doctor --fix; the build doctor check reports whether
they are built. The
machine that runs the city's orders and runtime needs go and access to the
Go module proxy. The binary is cached per version of the pack's Go code under
${GC_PACK_BUILD_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/gascity-packs}/forgejo/.
Import the pack for each rig in city.toml:
[[rigs]]
name = "my-rig"
path = "../my-rig"
[rigs.imports.forgejo]
source = "https://sarak.sh/mikluko/gascity-forgejo-pack.git"
version = "^0.1"
Each rig import registers that rig's orders. The city orders are promoted once from the rig imports, so no separate city-level import is needed.
Each order runs its command from bin/ every minute after a cooldown:
| Order | Command | Scope | Working directory |
|---|---|---|---|
merge-ready |
merge-ready |
One per importing rig | Rig root |
merge-ready-city |
merge-ready |
City | City root |
rework |
rework |
One per importing rig | Rig root |
rework-city |
rework |
City | City root |
The city orders are for a city whose own repository is not one of its rigs. Each
working directory must have an HTTPS or SSH origin naming its Forgejo
repository.
Credentials
Set FORGEJO_TOKEN to supply a bearer token directly. Otherwise the command
runs git credential fill for the origin's HTTPS URL on every run, with
terminal and askpass prompts disabled. Git's credential.useHttpPath setting
is honoured. Configure any credential helper through git; the pack does not
select or configure one.
merge-ready needs a token with push permission on the repository; rework
only reads, so read access is enough. Credentials are never cached or logged.
Merge gates
Every open pull request is read again before any gate is evaluated. It is squash-merged only when:
- The repository reports
permissions.push. - The pull request is open, unmerged and mergeable.
- Its base branch is protected, requires at least one approval and reports
user_can_merge. - Its exact head has a successful combined status. If the base does not require status checks, a head with no statuses passes; a head with statuses must still be successful.
- A review approves that exact head and is official, current, non-stale and non-dismissed.
- Every requested reviewer's latest undismissed
APPROVEDorREQUEST_CHANGESreview approves that exact head and is non-stale; it need not be official. A requested reviewer is a user in the pull request'srequested_reviewersor with a review in theREQUEST_REVIEWstate. One who has not reviewed, or whose latest verdict requests changes or approves an older commit, holds the merge. A pending team review request holds it too; team members are not resolved.
The merge request pins the checked head. HTTP 409 leaves a moved head for the
next run. A 200 response is confirmed by reading the pull request again and
requiring merged. Errors and missing fields leave the pull request open.
The command writes one decision line per pull request. It exits non-zero only when the repository or its open pull request list cannot be read.
Rework
rework hands a pull request's feedback back to the bead it was opened for.
A pull request is tied to a bead when its head branch name is the id of a bead
in the beads store of the working directory; bd runs there, from PATH. For
each open pull request:
bd show <branch> --jsonreads the bead. A pull request whose branch names no bead is skipped, and so is one whose bead is not closed: it is already being worked or parked.- Feedback is collected for the current head commit only. It is the failed
statuses (context, description and target URL) when the head's combined
status is
failureorerror, and each officialREQUEST_CHANGESreview of that exact head that is current, non-stale and non-dismissed, with its body and inline comments. A review or status on an older commit counts for nothing: a new push answers it. - When there is feedback,
bd reopenreopens the bead andbd updateclears its assignee and appends notes. The notes start with the pull request's URL and the head commit, then list the failed checks and the review.
The bead is open after that, so later runs leave it alone until it is closed
again. The command writes one decision line per pull request and exits
non-zero only when the repository or its open pull request list cannot be
read; a failing bd or API call is reported on that pull request's line. It
never writes to Forgejo.
Development
go vet ./...
go test -race ./...
GOMAXPROCS=1 go test -count=20 ./...
gc lint .
The tests use a local fake Forgejo API and temporary git credential helpers; they do not need a live server.
Releases
Record a notable pull request change under [Unreleased] in
CHANGELOG.md.
A release pull request turns those notes into a dated semantic version
section. After it merges, the release workflow runs CI, tags the commit
vX.Y.Z and creates the Forgejo release.