Skip to content

Commit b1ecdb3

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 - Improve GitHub ORG enumeration to extract from Gerrit change - 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 b1ecdb3

File tree

11 files changed

+1507
-171
lines changed

11 files changed

+1507
-171
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ 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+
- Closes PRs when Gerrit **merges** changes (not abandons them)
56+
57+
**Status reporting examples:**
58+
59+
```text
60+
INFO: No GitHub PR URL found in commit abc123de - skipping
61+
INFO: GitHub PR #123 is already closed - nothing to do
62+
SUCCESS: Closed GitHub PR #456
63+
```
64+
3765
## Requirements
3866

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

action.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,18 @@ 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"
6872
ISSUE_ID:
6973
description: "Issue ID to include (e.g., ABC-123)"
7074
required: false
7175
default: ""
76+
USE_LOCAL_ACTION:
77+
description: "Use local action code instead of PyPI (for testing branches/forks)"
78+
required: false
79+
default: "false"
7280
G2G_USE_SSH_AGENT:
7381
description: "Use SSH agent for authentication instead of file-based keys (recommended)"
7482
required: false
@@ -157,7 +165,8 @@ runs:
157165
set -euo pipefail
158166
uv --version
159167
# Install locally for self-testing, use uvx for external repos
160-
if [[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
168+
if [[ "${{ inputs.USE_LOCAL_ACTION }}" == "true" ]] || \
169+
[[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
161170
echo "Installing with: uv pip install --system ${{ github.action_path }}"
162171
uv pip install --system ${{ github.action_path }}
163172
else
@@ -199,6 +208,13 @@ runs:
199208
run: |
200209
# Extract PR number, validate context
201210
set -euo pipefail
211+
212+
# Push events don't need PR_NUMBER (used for closing merged PRs)
213+
if [[ "${{ github.event_name }}" == "push" ]]; then
214+
echo "Push event detected - will process merged commits for PR closure"
215+
exit 0
216+
fi
217+
202218
# Honor PR_NUMBER or SYNC_ALL_OPEN_PRS set by workflow_dispatch
203219
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
204220
if [[ -n "${SYNC_ALL_OPEN_PRS:-}" ]]; then
@@ -249,6 +265,7 @@ runs:
249265
ISSUE_ID: ${{ inputs.ISSUE_ID }}
250266
ISSUE_ID_LOOKUP_JSON: ${{ inputs.ISSUE_ID_LOOKUP_JSON }}
251267
CI_TESTING: ${{ inputs.CI_TESTING }}
268+
CLOSE_MERGED_PRS: ${{ inputs.CLOSE_MERGED_PRS }}
252269
DUPLICATE_TYPES: ${{ inputs.DUPLICATE_TYPES }}
253270
NORMALISE_COMMIT: ${{ inputs.NORMALISE_COMMIT }}
254271
G2G_USE_SSH_AGENT: ${{ inputs.G2G_USE_SSH_AGENT }}
@@ -280,8 +297,9 @@ runs:
280297
run: |
281298
# Run github2gerrit Python CLI
282299
set -euo pipefail
283-
# Use different invocation methods based on repository
284-
if [[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
300+
# Use different invocation methods based on repository or USE_LOCAL_ACTION flag
301+
if [[ "${{ inputs.USE_LOCAL_ACTION }}" == "true" ]] || \
302+
[[ "${{ github.repository }}" =~ lfreleng-actions/github2gerrit-action ]]; then
285303
echo "Running:python -m github2gerrit.cli"
286304
python -m github2gerrit.cli
287305
else

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,14 @@ directory = "coverage_html_report"
215215
minversion = "8.0"
216216
addopts = "-ra -q --cov=github2gerrit --cov-report=term-missing --cov-report=html"
217217
testpaths = ["tests"]
218+
asyncio_mode = "strict"
219+
asyncio_default_fixture_loop_scope = "function"
218220
markers = [
219221
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
220222
]
223+
filterwarnings = [
224+
"ignore::pytest.PytestConfigWarning:_pytest.config",
225+
]
221226

222227
[tool.pyright]
223228
pythonVersion = "3.11"

0 commit comments

Comments
 (0)