Skip to content

Commit 8cfb18b

Browse files
Feat: Enhance pull request close/reconciliation handling
- Add GitHub PR close handling after Gerrit change is merged - Add CLI ability to accept Gerrit change as input, close PRs - New --force flag will close GitHub PRs for Abandoned changes - Add code to extract GitHub ORG from Gerrit change content - Only display relevant output in GitHub2Gerrit Configuration - Bypass uvx when testing/developing against branches in forks - Improve isolation to address failing pre-commit pytest hook Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
1 parent 406fc75 commit 8cfb18b

12 files changed

Lines changed: 2184 additions & 171 deletions

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,52 @@ Gerrit `Change-Id` trailers to create or update changes.
3434
- Comment on the GitHub PR with the Gerrit change URL(s).
3535
- Optionally close the PR (mirrors the shell action policy).
3636

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+
49+
**Key characteristics:**
50+
51+
- **Enabled by default** via `CLOSE_MERGED_PRS=true`
52+
- **Non-fatal operation** - the tool logs missing or already-closed PRs as
53+
info, not errors
54+
- Works on `push` events when Gerrit syncs changes to GitHub mirrors
55+
- **Safety checks**: When a Gerrit change URL is available, the tool verifies
56+
that the change has MERGED status (not ABANDONED) before closing the PR
57+
- **Force option**: Use `--force` to close PRs regardless of Gerrit change status
58+
59+
**Gerrit change status handling:**
60+
61+
| Scenario | Default Behavior | With `--force` |
62+
|----------|------------------|----------------|
63+
| Change has MERGED status | ✅ Closes PR | ✅ Closes PR |
64+
| Change has ABANDONED status | ❌ Refuses to close PR | ✅ Closes PR anyway |
65+
| Change is NEW/OPEN | ⚠️ Closes PR with a warning | ✅ Closes PR |
66+
| Status UNKNOWN | ⚠️ Closes PR with a warning | ✅ Closes PR |
67+
68+
**Status reporting examples:**
69+
70+
```text
71+
No GitHub PR URL found in commit abc123de - skipping
72+
GitHub PR #42 is already closed - nothing to do
73+
Gerrit change confirmed as MERGED
74+
SUCCESS: Closed GitHub PR #42
75+
```
76+
77+
**Safety example (refused closure):**
78+
79+
```text
80+
ERROR: Gerrit change has ABANDONED status, not closing GitHub PR. Use --force to close anyway.
81+
```
82+
3783
## Requirements
3884

3985
- Repository contains a `.gitreview` file. If you cannot provide it,

action.yaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,22 @@ inputs:
6565
description: "Enable CI testing mode; overrides .gitreview, creates orphan commits"
6666
required: false
6767
default: "false"
68+
CLOSE_MERGED_PRS:
69+
description: "Close GitHub PRs when corresponding Gerrit changes are merged"
70+
required: false
71+
default: "true"
72+
FORCE:
73+
description: "Force PR closure regardless of Gerrit change status (abandoned, etc)"
74+
required: false
75+
default: "false"
6876
ISSUE_ID:
6977
description: "Issue ID to include (e.g., ABC-123)"
7078
required: false
7179
default: ""
80+
USE_LOCAL_ACTION:
81+
description: "Use local action code instead of PyPI (for testing branches/forks)"
82+
required: false
83+
default: "false"
7284
G2G_USE_SSH_AGENT:
7385
description: "Use SSH agent for authentication instead of file-based keys (recommended)"
7486
required: false
@@ -157,7 +169,8 @@ runs:
157169
set -euo pipefail
158170
uv --version
159171
# Install locally for self-testing, use uvx for external repos
160-
if [[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
172+
if [[ "${{ inputs.USE_LOCAL_ACTION }}" == "true" ]] || \
173+
[[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
161174
echo "Installing with: uv pip install --system ${{ github.action_path }}"
162175
uv pip install --system ${{ github.action_path }}
163176
else
@@ -199,6 +212,13 @@ runs:
199212
run: |
200213
# Extract PR number, validate context
201214
set -euo pipefail
215+
216+
# Push events don't need PR_NUMBER (used for closing merged PRs)
217+
if [[ "${{ github.event_name }}" == "push" ]]; then
218+
echo "Push event detected - will process merged commits for PR closure"
219+
exit 0
220+
fi
221+
202222
# Honor PR_NUMBER or SYNC_ALL_OPEN_PRS set by workflow_dispatch
203223
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
204224
if [[ -n "${SYNC_ALL_OPEN_PRS:-}" ]]; then
@@ -249,6 +269,8 @@ runs:
249269
ISSUE_ID: ${{ inputs.ISSUE_ID }}
250270
ISSUE_ID_LOOKUP_JSON: ${{ inputs.ISSUE_ID_LOOKUP_JSON }}
251271
CI_TESTING: ${{ inputs.CI_TESTING }}
272+
CLOSE_MERGED_PRS: ${{ inputs.CLOSE_MERGED_PRS }}
273+
FORCE: ${{ inputs.FORCE }}
252274
DUPLICATE_TYPES: ${{ inputs.DUPLICATE_TYPES }}
253275
NORMALISE_COMMIT: ${{ inputs.NORMALISE_COMMIT }}
254276
G2G_USE_SSH_AGENT: ${{ inputs.G2G_USE_SSH_AGENT }}
@@ -280,8 +302,9 @@ runs:
280302
run: |
281303
# Run github2gerrit Python CLI
282304
set -euo pipefail
283-
# Use different invocation methods based on repository
284-
if [[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
305+
# Use different invocation methods based on repository or USE_LOCAL_ACTION flag
306+
if [[ "${{ inputs.USE_LOCAL_ACTION }}" == "true" ]] || \
307+
[[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
285308
echo "Running:python -m github2gerrit.cli"
286309
python -m github2gerrit.cli
287310
else

src/github2gerrit/__pycache__/config.cpython-311.pyc.4492107024

Whitespace-only changes.

0 commit comments

Comments
 (0)