pull-request-fixer 0.1.7__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/.gitignore +1 -1
  2. pull_request_fixer-0.1.8/PKG-INFO +454 -0
  3. pull_request_fixer-0.1.8/README.md +412 -0
  4. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/pyproject.toml +4 -4
  5. pull_request_fixer-0.1.8/scripts/README.md +87 -0
  6. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/__init__.py +1 -1
  7. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/_version.py +2 -2
  8. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/cli.py +14 -12
  9. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/exceptions.py +13 -9
  10. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/models.py +1 -32
  11. pull_request_fixer-0.1.7/.pre-commit-hooks.yaml +0 -12
  12. pull_request_fixer-0.1.7/PKG-INFO +0 -686
  13. pull_request_fixer-0.1.7/README.md +0 -644
  14. pull_request_fixer-0.1.7/scripts/README.md +0 -120
  15. pull_request_fixer-0.1.7/src/pull_request_fixer/pr_fixer.py +0 -37
  16. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/LICENSE +0 -0
  17. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/LICENSES/Apache-2.0.txt +0 -0
  18. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/blocked_pr_scanner.py +0 -0
  19. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/file_fixer.py +0 -0
  20. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/git_config.py +0 -0
  21. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/github_client.py +0 -0
  22. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/graphql_queries.py +0 -0
  23. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/pr_file_fixer.py +0 -0
  24. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/pr_scanner.py +0 -0
  25. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/progress_tracker.py +0 -0
  26. {pull_request_fixer-0.1.7 → pull_request_fixer-0.1.8}/src/pull_request_fixer/py.typed +0 -0
@@ -60,7 +60,7 @@ MANIFEST
60
60
  node_modules/*
61
61
 
62
62
  # Auto-generated version file (generated by setuptools-scm/hatch)
63
- src/markdown_table_fixer/_version.py
63
+ src/pull_request_fixer/_version.py
64
64
 
65
65
  # Test output directory (created by integration tests)
66
66
  test_output/
@@ -0,0 +1,454 @@
1
+ Metadata-Version: 2.5
2
+ Name: pull-request-fixer
3
+ Version: 0.1.8
4
+ Summary: Fix GitHub pull request titles, descriptions and files, for one pull request or across an organization
5
+ Project-URL: Homepage, https://github.com/lfreleng-actions/pull-request-fixer
6
+ Project-URL: Repository, https://github.com/lfreleng-actions/pull-request-fixer.git
7
+ Project-URL: Bug Tracker, https://github.com/lfreleng-actions/pull-request-fixer/issues
8
+ Author-email: The Linux Foundation <releng@linuxfoundation.org>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: automation,commit-message,github,pr,pull-request,regex
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Quality Assurance
24
+ Classifier: Topic :: Software Development :: Version Control :: Git
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: aiolimiter>=1.2.1
27
+ Requires-Dist: dependamerge>=0.9.1
28
+ Requires-Dist: httpx[http2]>=0.28.1
29
+ Requires-Dist: pydantic>=2.12.5
30
+ Requires-Dist: rich>=14.2.0
31
+ Requires-Dist: tenacity>=9.1.2
32
+ Requires-Dist: typer>=0.20.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: mypy>=1.19.0; extra == 'dev'
35
+ Requires-Dist: pre-commit>=4.5.0; extra == 'dev'
36
+ Requires-Dist: pytest-asyncio>=1.3.0; extra == 'dev'
37
+ Requires-Dist: pytest-cov>=7.0.0; extra == 'dev'
38
+ Requires-Dist: pytest-mock>=3.15.1; extra == 'dev'
39
+ Requires-Dist: pytest>=9.0.2; extra == 'dev'
40
+ Requires-Dist: ruff>=0.14.8; extra == 'dev'
41
+ Description-Content-Type: text/markdown
42
+
43
+ <!--
44
+ SPDX-License-Identifier: Apache-2.0
45
+ SPDX-FileCopyrightText: 2025 The Linux Foundation
46
+ -->
47
+
48
+ # 🛠️ Pull Request Fixer
49
+
50
+ A Python command-line tool that repairs GitHub pull requests in place. It
51
+ can work on one pull request or scan a whole GitHub organization, and it
52
+ can:
53
+
54
+ - set a pull request's **title** to the subject line of its first commit
55
+ - set a pull request's **description** to the body of its first commit,
56
+ minus Git trailers such as `Signed-off-by:`
57
+ - apply regex **search/replace or line removal to files** on the pull
58
+ request's branch, then push the result back to the pull request
59
+
60
+ A common use is unblocking automated pull requests (Dependabot,
61
+ pre-commit.ci and similar) that fail a semantic title check or carry a
62
+ small, mechanical defect across a whole organization.
63
+
64
+ By default the tool only touches **blocked** pull requests: those with
65
+ merge conflicts, those behind their base branch, or those with failing
66
+ checks.
67
+
68
+ ## Contents
69
+
70
+ - [Installation](#installation)
71
+ - [Quick start](#quick-start)
72
+ - [Targets](#targets)
73
+ - [Which pull requests get processed](#which-pull-requests-get-processed)
74
+ - [Fixing titles and descriptions](#fixing-titles-and-descriptions)
75
+ - [Fixing files](#fixing-files)
76
+ - [Pull request comments](#pull-request-comments)
77
+ - [Options](#options)
78
+ - [Authentication](#authentication)
79
+ - [Exit status](#exit-status)
80
+ - [Troubleshooting](#troubleshooting)
81
+ - [Development](#development)
82
+
83
+ ## Installation
84
+
85
+ The tool needs Python 3.10 or newer. File fixing also needs `git` on
86
+ `PATH`, except with `--update-method api --pr-content-only`.
87
+
88
+ ```bash
89
+ pip install pull-request-fixer
90
+ ```
91
+
92
+ Or with uv:
93
+
94
+ ```bash
95
+ uv tool install pull-request-fixer
96
+ ```
97
+
98
+ ## Quick start
99
+
100
+ ```bash
101
+ export GITHUB_TOKEN=ghp_xxxxxxxxxxxxx
102
+
103
+ # Preview title fixes for blocked pull requests across an organization
104
+ pull-request-fixer myorg --fix-title --dry-run
105
+
106
+ # Fix titles and descriptions for real
107
+ pull-request-fixer myorg --fix-title --fix-body
108
+
109
+ # Fix the title of one pull request
110
+ pull-request-fixer https://github.com/owner/repo/pull/123 --fix-title
111
+
112
+ # Remove 'type:' lines from the inputs section of a root action.yaml
113
+ pull-request-fixer https://github.com/owner/repo/pull/123 \
114
+ --fix-files \
115
+ --file-pattern '^\./action\.yaml$' \
116
+ --search-pattern '^\s+type:\s+\S' \
117
+ --remove-lines \
118
+ --context-start '^inputs:' \
119
+ --context-end '^runs:' \
120
+ --dry-run --show-diff
121
+ ```
122
+
123
+ The tool needs at least one of `--fix-title`, `--fix-body` or
124
+ `--fix-files`; without one it prints a warning and exits.
125
+
126
+ ## Targets
127
+
128
+ `TARGET` is the only positional argument. It can be:
129
+
130
+ | Form | Example | Mode |
131
+ | ----------------- | ---------------------------------------- | ------------ |
132
+ | Organization name | `myorg` | Organization |
133
+ | Organization URL | `https://github.com/myorg` | Organization |
134
+ | Pull request URL | `https://github.com/owner/repo/pull/123` | Single PR |
135
+
136
+ The tool works with GitHub.com; it does not support GitHub Enterprise
137
+ Server hosts.
138
+
139
+ In **organization mode** the tool validates the token, scans every
140
+ repository in the organization for open pull requests, then processes the
141
+ matching pull requests in parallel.
142
+
143
+ In **single PR mode** the tool processes the one pull request. Unless you
144
+ pass `--no-blocked-only`, it reports a closed or merged pull request and
145
+ exits without changing it; `--fix-files` always refuses closed pull
146
+ requests.
147
+
148
+ ## Which pull requests get processed
149
+
150
+ Both modes process only blocked pull requests unless you pass
151
+ `--no-blocked-only`. The tool reuses the blocking logic from
152
+ [dependamerge][dependamerge], so both tools agree on which pull requests
153
+ count as blocked. A pull request counts as blocked when it has:
154
+
155
+ - merge conflicts (`mergeable: CONFLICTING` or merge state `dirty`)
156
+ - a head branch behind its base branch (merge state `behind`)
157
+ - one or more failing status checks or check runs
158
+
159
+ The organization scan skips draft pull requests unless you pass
160
+ `--include-drafts`.
161
+
162
+ In single PR mode, if the pull request is not blocked, the tool prints
163
+ `pull request is NOT in a blocked state` and exits with status 1. Add
164
+ `--no-blocked-only` to process it anyway.
165
+
166
+ ## Fixing titles and descriptions
167
+
168
+ Both fixes read the **first** (oldest) commit on the pull request.
169
+
170
+ ### `--fix-title`
171
+
172
+ Sets the pull request title to the first commit's subject line, when the
173
+ two differ.
174
+
175
+ ### `--fix-body`
176
+
177
+ Sets the pull request description to the first commit's message body,
178
+ when the commit has a body. The tool strips trailing Git trailers from
179
+ the body. It recognizes these trailers, case-insensitively:
180
+
181
+ `Signed-off-by:`, `Co-authored-by:`, `Reviewed-by:`, `Tested-by:`,
182
+ `Acked-by:`, `Cc:`, `Reported-by:`, `Suggested-by:`, `Fixes:`,
183
+ `See-also:`, `Link:`, `Bug:`, `Change-Id:`
184
+
185
+ For example, given this first commit:
186
+
187
+ ```text
188
+ Fix: Correct race condition in calendar refresh
189
+
190
+ Serialize refreshes so concurrent updates cannot interleave.
191
+
192
+ Signed-off-by: Jane Doe <jane@example.com>
193
+ ```
194
+
195
+ `--fix-title` sets the title to
196
+ `Fix: Correct race condition in calendar refresh`, and `--fix-body` sets
197
+ the description to
198
+ `Serialize refreshes so concurrent updates cannot interleave.`
199
+
200
+ After updating a title or description, the tool asks GitHub to re-run any
201
+ of the pull request's check runs that ended as failed, cancelled, timed
202
+ out or action required. This lets checks such as a semantic pull request
203
+ title check pick up the change. Re-running checks is best-effort; the
204
+ tool ignores checks that GitHub refuses to re-run.
205
+
206
+ ## Fixing files
207
+
208
+ `--fix-files` edits files on the pull request's head branch. When you
209
+ pass `--fix-files`, the tool **ignores** `--fix-title` and `--fix-body`;
210
+ run the tool twice to do both.
211
+
212
+ `--fix-files` needs:
213
+
214
+ - `--file-pattern`: a Python regular expression for the files to edit
215
+ - `--search-pattern`: a Python regular expression for the content to
216
+ change
217
+ - one action: `--replacement TEXT` or `--remove-lines`
218
+
219
+ ### Selecting files
220
+
221
+ The tool tests `--file-pattern` with `re.search` against each file's
222
+ repository-relative path, both as `path/to/file` and as
223
+ `./path/to/file`. The pattern can match anywhere in the path, and `.`
224
+ matches any character, so `./action.yaml` also matches
225
+ `sub/dir/action.yaml`. Anchor and escape the pattern to match one file:
226
+
227
+ <!-- markdownlint-disable MD013 -->
228
+
229
+ | Pattern | Matches |
230
+ | ---------------------- | ------------------------------------------- |
231
+ | `^\./action\.yaml$` | `action.yaml` at the repository root only |
232
+ | `(^\|/)action\.ya?ml$` | `action.yaml` or `action.yml` in any folder |
233
+ | `\.github/workflows/` | every file under `.github/workflows/` |
234
+
235
+ <!-- markdownlint-enable MD013 -->
236
+
237
+ By default the tool considers every matching file in the repository at
238
+ the pull request's head commit. Add `--pr-content-only` to restrict it to
239
+ files the pull request already changes.
240
+
241
+ ### Search and replace
242
+
243
+ With `--replacement`, the tool runs `re.sub` over each file's whole
244
+ content with `re.MULTILINE` set, so `^` and `$` match at line boundaries.
245
+ The replacement supports back-references such as `\1`. An empty
246
+ replacement (`--replacement ''`) deletes the matched text.
247
+
248
+ ```bash
249
+ pull-request-fixer https://github.com/owner/repo/pull/456 \
250
+ --fix-files \
251
+ --file-pattern '\.py$' \
252
+ --search-pattern '\bold_function_name\b' \
253
+ --replacement 'new_function_name'
254
+ ```
255
+
256
+ ### Line removal
257
+
258
+ With `--remove-lines`, the tool deletes every line that matches
259
+ `--search-pattern`. Two optional patterns limit where removal applies:
260
+
261
+ - `--context-start`: removal begins after a line matching this pattern
262
+ - `--context-end`: removal stops at a line matching this pattern
263
+
264
+ The tool always keeps the marker lines themselves. Without
265
+ `--context-start`, removal applies from the top of the file. After a
266
+ `--context-end` match, removal stays off until the next
267
+ `--context-start` match.
268
+
269
+ ### Update methods
270
+
271
+ `--update-method` chooses how the tool writes file changes back:
272
+
273
+ <!-- markdownlint-disable MD013 -->
274
+
275
+ | Behaviour | `git` (default) | `api` |
276
+ | ------------------------ | --------------------------------------- | ----------------------------------------- |
277
+ | How | Clone, amend, `--force-with-lease` push | GitHub Git Data API |
278
+ | Commit | Amends the branch's **last** commit | Adds a **new** commit |
279
+ | Commit message | Unchanged | `Fix N file(s) in PR #N` with no sign-off |
280
+ | Signing | Your local Git signing setup | No signature from your keys |
281
+ | Pull requests from forks | Supported, with push access to the fork | Not supported |
282
+ | File modes | Preserved | Rewritten as `100644` |
283
+ | Needs `git` | Yes | Unless `--pr-content-only` set |
284
+
285
+ <!-- markdownlint-enable MD013 -->
286
+
287
+ Because the `git` method amends the existing commit, it keeps that
288
+ commit's message, author and any `Signed-off-by:` trailer, which suits
289
+ repositories that enforce DCO sign-off or signed commits.
290
+
291
+ The `api` method reads and writes the head branch in the pull request's
292
+ **base** repository, so it only works when the branch lives there, as it
293
+ does for Dependabot and pre-commit.ci pull requests. Its commits carry no
294
+ DCO sign-off. It normally writes all changes in one commit; if that
295
+ batch commit fails, it falls back to one `Fix <path>` commit per file.
296
+
297
+ ### Git identity and signing
298
+
299
+ These flags apply to the `git` method only:
300
+
301
+ - default: copy `user.name`, `user.email` and the commit signing settings
302
+ (`commit.gpgsign`, `gpg.format`, `user.signingkey` and related keys)
303
+ from your global Git configuration
304
+ - `--disable-signing`: use your identity but turn signing off
305
+ - `--bot-identity`: commit as `pull-request-fixer
306
+ <noreply@linuxfoundation.org>` without signing
307
+
308
+ If your global Git configuration has no `user.name` or `user.email`, the
309
+ tool falls back to the bot identity. You cannot combine `--bot-identity`
310
+ with `--disable-signing`.
311
+
312
+ ### Previewing changes
313
+
314
+ `--dry-run` makes no changes. `--show-diff` prints a unified diff for each
315
+ changed file; organization dry runs always print diffs.
316
+
317
+ ## Pull request comments
318
+
319
+ When the tool changes a pull request (not in dry-run mode), it posts a
320
+ comment describing the change. For title and description fixes:
321
+
322
+ ```markdown
323
+ ## 🛠️ Pull Request Fixer
324
+
325
+ Automatically fixed pull request metadata:
326
+ - Updated pull request title to match commit
327
+ - Updated pull request description to match commit body message
328
+
329
+ ---
330
+ *This fix was automatically applied by [pull-request-fixer](https://github.com/lfreleng-actions/pull-request-fixer)*
331
+ ```
332
+
333
+ For file fixes, the comment shows the command options used and the diff
334
+ for each file. When the diffs total more than 40 lines, it lists the
335
+ changed files instead.
336
+
337
+ ## Options
338
+
339
+ <!-- markdownlint-disable MD013 -->
340
+
341
+ | Option | Short | Default | Description |
342
+ | ------------------- | ----- | --------------- | ----------------------------------------------------------------- |
343
+ | `--token` | `-t` | `$GITHUB_TOKEN` | GitHub token |
344
+ | `--fix-title` | | off | Set the title to the first commit's subject |
345
+ | `--fix-body` | | off | Set the description to the first commit's body, minus trailers |
346
+ | `--fix-files` | | off | Edit files with regex; overrides `--fix-title` and `--fix-body` |
347
+ | `--file-pattern` | | | Regex for file paths (required with `--fix-files`) |
348
+ | `--search-pattern` | | | Regex for file content (required with `--fix-files`) |
349
+ | `--replacement` | | | Replacement text; supports back-references |
350
+ | `--remove-lines` | | off | Delete matching lines instead of replacing |
351
+ | `--context-start` | | | Regex for the line after which removal begins |
352
+ | `--context-end` | | | Regex for the line at which removal stops |
353
+ | `--pr-content-only` | | off | Only edit files the pull request already changes |
354
+ | `--show-diff` | | off | Print a unified diff for each changed file |
355
+ | `--update-method` | | `git` | `git` (clone, amend, push) or `api` (new commit through the API) |
356
+ | `--disable-signing` | | off | `git` method: use your identity without signing |
357
+ | `--bot-identity` | | off | `git` method: commit as the bot identity without signing |
358
+ | `--include-drafts` | | off | Include draft pull requests |
359
+ | `--no-blocked-only` | | off | Process pull requests regardless of blocked state |
360
+ | `--dry-run` | | off | Preview changes without applying them |
361
+ | `--workers` | `-j` | CPU cores | Parallel workers, 1-32; defaults to the performance core count |
362
+ | `--verbose` | `-v` | off | Debug logging |
363
+ | `--quiet` | `-q` | off | Errors only |
364
+ | `--log-level` | | `INFO` | Logging level |
365
+ | `--version` | | | Print the version and exit |
366
+ | `--help` | `-h` | | Print the version and help, then exit |
367
+
368
+ <!-- markdownlint-enable MD013 -->
369
+
370
+ ## Authentication
371
+
372
+ Pass a GitHub token with `--token` or the `GITHUB_TOKEN` environment
373
+ variable. The token needs:
374
+
375
+ - read access to the repositories you scan, and `read:org` to list an
376
+ organization's repositories and read check status
377
+ - write access to pull requests to change titles, descriptions and
378
+ comments
379
+ - push access to the pull request's head repository for `--fix-files`;
380
+ with the `git` method on a pull request from a fork, that means the fork
381
+
382
+ With a classic personal access token, grant `repo` (or `public_repo` for
383
+ public repositories only) and `read:org`. In organization mode the tool
384
+ validates the token first and warns when it cannot see those scopes.
385
+ Tokens issued to GitHub Actions do not report scopes, so the tool skips
386
+ that check for them.
387
+
388
+ ## Exit status
389
+
390
+ | Status | Meaning |
391
+ | ------ | ------------------------------------------------------------------- |
392
+ | `0` | Run completed; also when single PR mode finds a closed or merged PR |
393
+ | `1` | Missing target, fix option or token; API error; PR not blocked |
394
+ | `2` | Unknown option or out-of-range value, such as `--workers 33` |
395
+
396
+ An organization run exits `0` even when updating some pull requests
397
+ fails. Check the `❌ Failed updates:` line in its summary.
398
+
399
+ ## Troubleshooting
400
+
401
+ **`✅ No blocked PRs found!`** — the organization has no open pull
402
+ requests that count as blocked. Use `--no-blocked-only` to process all
403
+ open pull requests, or `--include-drafts` to include drafts.
404
+
405
+ **`pull request is NOT in a blocked state`** — single PR mode only
406
+ processes blocked pull requests by default. Add `--no-blocked-only`.
407
+
408
+ **Token validation failed or scope warnings** — check that the token has
409
+ not expired and has the access listed under
410
+ [Authentication](#authentication).
411
+
412
+ **`Push rejected` errors** — someone pushed to the pull request branch
413
+ while the tool worked on it; run the tool again.
414
+
415
+ **Rate limiting** — reduce `--workers`, or wait for the limit to reset.
416
+
417
+ **Unexpected files changed** — anchor `--file-pattern` as shown in
418
+ [Selecting files](#selecting-files), and preview with
419
+ `--dry-run --show-diff`.
420
+
421
+ Use `--verbose` for debug logging. The `scripts/` directory holds
422
+ diagnostic scripts for GraphQL and organization access problems; see
423
+ [scripts/README.md](scripts/README.md).
424
+
425
+ ## Development
426
+
427
+ ```bash
428
+ git clone https://github.com/lfreleng-actions/pull-request-fixer.git
429
+ cd pull-request-fixer
430
+ uv sync --extra dev
431
+ prek install -t pre-commit -t commit-msg
432
+ uv run pytest
433
+ uv run bash scripts/integration-test.sh
434
+ ```
435
+
436
+ The test dependencies live in the `dev` extra, so plain `uv sync` leaves
437
+ `pytest` missing. See [CONTRIBUTING.md](CONTRIBUTING.md) for the
438
+ contribution workflow, [SETUP.md](SETUP.md) for installation and CI use,
439
+ [IMPLEMENTATION.md](IMPLEMENTATION.md) for the internals, and
440
+ [TESTING.md](TESTING.md) for testing against live pull requests.
441
+
442
+ ## License
443
+
444
+ Apache-2.0
445
+
446
+ ## Related projects
447
+
448
+ - [dependamerge][dependamerge]: bulk pull request management for GitHub
449
+ organizations; this tool uses its blocked pull request detection
450
+ - [markdown-table-fixer][mtf]: fixes markdown table formatting; this
451
+ project began as a fork of its codebase
452
+
453
+ [dependamerge]: https://github.com/lfreleng-actions/dependamerge
454
+ [mtf]: https://github.com/lfreleng-actions/markdown-table-fixer