@@ -32,7 +32,106 @@ Gerrit `Change-Id` trailers to create or update changes.
3232- Query Gerrit for the resulting URL, change number, and patchset SHA.
3333- Add a back‑reference comment in Gerrit to the GitHub PR and run URL.
3434- Comment on the GitHub PR with the Gerrit change URL(s).
35- - Optionally close the PR (mirrors the shell action policy).
35+ - By default, the tool preserves PRs after submission; set ` PRESERVE_GITHUB_PRS=false ` to close them.
36+
37+ ## Close Merged PRs Feature
38+
39+ GitHub2Gerrit now includes ** automatic PR closure** when Gerrit merges changes
40+ and syncs them back to GitHub. This completes the lifecycle for automation PRs
41+ (like Dependabot).
42+
43+ ** How it works:**
44+
45+ 1 . A bot (e.g., Dependabot) creates a GitHub PR
46+ 2 . GitHub2Gerrit converts it to a Gerrit change with tracking information
47+ 3 . When the Gerrit change is ** merged** and synced to GitHub, the original PR is automatically closed
48+ 4 . When the Gerrit change is ** abandoned** , the tool handles the PR based on ` CLOSE_MERGED_PRS ` :
49+ - If ` CLOSE_MERGED_PRS=true ` (default): The tool closes the PR with an abandoned comment ⛔️
50+ - If ` CLOSE_MERGED_PRS=false ` : PR remains open, but receives an abandoned notification comment ⛔️
51+
52+ ** Key characteristics:**
53+
54+ - ** Enabled by default** via ` CLOSE_MERGED_PRS=true `
55+ - ** Non-fatal operation** - the tool logs missing or already-closed PRs as
56+ info, not errors
57+ - Works on ` push ` events when Gerrit syncs changes to GitHub mirrors
58+ - ** Abandoned change handling** : The tool closes PRs or adds comments based on the ` CLOSE_MERGED_PRS ` setting
59+
60+ ** Gerrit change status handling:**
61+
62+ | Scenario | ` CLOSE_MERGED_PRS=true ` (default) | ` CLOSE_MERGED_PRS=false ` |
63+ | ----------| -----------------------------------| --------------------------|
64+ | Change has MERGED status | ✅ Closes PR with merged comment | ⏭️ No action |
65+ | Change has ABANDONED status | ✅ Closes PR with abandoned comment ⛔️ | 💬 Adds abandoned notification comment (PR stays open) |
66+ | Change is NEW/OPEN | ⚠️ Closes PR with a warning | ⏭️ No action |
67+ | Status UNKNOWN | ⚠️ Closes PR with a warning | ⏭️ No action |
68+
69+ ** Status reporting examples:**
70+
71+ ``` text
72+ No GitHub PR URL found in commit abc123de - skipping
73+ GitHub PR #42 is already closed - nothing to do
74+ Gerrit change confirmed as MERGED
75+ SUCCESS: Closed GitHub PR #42
76+ ```
77+
78+ ** Abandoned change examples:**
79+
80+ With ` CLOSE_MERGED_PRS=true ` :
81+
82+ ``` text
83+ Gerrit change ABANDONED; will close PR with abandoned comment
84+ SUCCESS: Closed GitHub PR #42
85+ ```
86+
87+ With ` CLOSE_MERGED_PRS=false ` :
88+
89+ ``` text
90+ Gerrit change ABANDONED; will add comment (CLOSE_MERGED_PRS=false)
91+ SUCCESS: Added comment to PR #42 (PR remains open)
92+ ```
93+
94+ ## Restrict PRs to Automation Tools
95+
96+ GitHub2Gerrit can restrict pull request processing to known automation tools.
97+ Use this for GitHub mirrors where you want contributors to submit changes via
98+ Gerrit, while still accepting automated dependency updates from tools like
99+ Dependabot.
100+
101+ ** Configuration:**
102+
103+ Set ` AUTOMATION_ONLY=true ` (default) to enable, or ` AUTOMATION_ONLY=false `
104+ to accept all PRs.
105+
106+ ** Recognized automation tools:**
107+
108+ | Tool | GitHub Username(s) |
109+ | ------| -------------------|
110+ | Dependabot | ` dependabot[bot] ` , ` dependabot ` |
111+ | Pre-commit.ci | ` pre-commit-ci[bot] ` , ` pre-commit-ci ` |
112+
113+ ** What happens when enabled:**
114+
115+ The tool rejects PRs from non-automation users by:
116+
117+ 1 . Logging a warning message
118+ 2 . Closing the PR with this comment:
119+
120+ ``` text
121+ This GitHub mirror does not accept pull requests.
122+ Please submit changes to the project's Gerrit server.
123+ ```
124+
125+ 3 . Exiting with code 1
126+
127+ ** Example:**
128+
129+ ``` yaml
130+ - uses : lfit/github2gerrit-action@main
131+ with :
132+ AUTOMATION_ONLY : " true" # default, accepts automation PRs
133+ GERRIT_SSH_PRIVKEY_G2G : ${{ secrets.GERRIT_SSH_PRIVKEY }}
134+ ` ` `
36135
37136## Requirements
38137
@@ -664,7 +763,7 @@ alignment between action inputs, environment variables, and CLI flags:
664763| `ORGANIZATION` | `ORGANIZATION` | `--organization` | No | `${{ github.repository_owner }}` | GitHub organization/owner |
665764| `REVIEWERS_EMAIL` | `REVIEWERS_EMAIL` | `--reviewers-email` | No | `""` | Comma-separated reviewer emails |
666765| `ALLOW_GHE_URLS` | `ALLOW_GHE_URLS` | `--allow-ghe-urls` | No | `"false"` | Allow GitHub Enterprise URLs in direct URL mode |
667- | `PRESERVE_GITHUB_PRS` | `PRESERVE_GITHUB_PRS` | `--preserve-github-prs` | No | `"false "` | Do not close GitHub PRs after pushing to Gerrit |
766+ | `PRESERVE_GITHUB_PRS` | `PRESERVE_GITHUB_PRS` | `--preserve-github-prs` | No | `"true "` | Do not close GitHub PRs after pushing to Gerrit |
668767| `DRY_RUN` | `DRY_RUN` | `--dry-run` | No | `"false"` | Check settings/PR metadata; do not write to Gerrit |
669768| `ALLOW_DUPLICATES` | `ALLOW_DUPLICATES` | `--allow-duplicates` | No | `"false"` | Allow submitting duplicate changes without error |
670769| `CI_TESTING` | `CI_TESTING` | `--ci-testing` | No | `"false"` | Enable CI testing mode (overrides .gitreview) |
@@ -943,8 +1042,8 @@ requiring manual configuration per PR or user.
9431042 - Adds a back‑reference comment in Gerrit with the GitHub PR and run
9441043 URL. Adds a comment on the GitHub PR with the Gerrit change URL(s).
9451044- Closing PRs
946- - On `pull_request_target`, the workflow may close the PR after submission to
947- match the shell action’s behavior .
1045+ - By default, PRs are **preserved** after submission (`PRESERVE_GITHUB_PRS=true`).
1046+ - Set `PRESERVE_GITHUB_PRS=false` to close PRs after submission on `pull_request_target` events .
9481047
9491048# # Security notes
9501049
0 commit comments