A command-line tool that validates backport pull requests by comparing their diffs against the original source PRs.
- Automatic source PR detection: Extracts source PR numbers from backport PR body or commit messages
- Diff normalization: Filters out:
- License boilerplate (Apache 2.0, AGPL 3.0 headers)
- Protobuf-generated files (
.pb.go,.pb.ts, etc.) - File rename chains across multiple source PRs
- Pure file copies and mode-only diffs
- Reindentation and whitespace-only changes
- Trivial word-only changes in comments
- Clear diff reporting: Shows exactly what was added or removed in the backport vs. source
- Multi-source support: Handles backports that combine multiple source PRs
./backportdiffbot -pr 12345./backportdiffbot [options]
Options:
-pr int
Backport pull request number (required)
-repo string
GitHub repository in owner/repo format (default "gravitational/teleport")
-api-base string
GitHub API base URL (default "https://api.github.com")
-timeout duration
HTTP timeout (default 30s)
-fail-on-diff
Exit with code 3 when differences are found (useful for CI)Check a backport PR for a specific repository:
./backportdiffbot -repo myorg/myrepo -pr 456Use with GitHub Enterprise:
./backportdiffbot -api-base https://github.enterprise.com/api/v3 -pr 789Fail CI build if backport has differences:
./backportdiffbot -pr 456 -fail-on-diffThe tool resolves a GitHub token in this order:
GH_TOKENenvironment variableGITHUB_TOKENenvironment variablegh auth token(if theghCLI is installed and logged in)
If none of these are available, requests are made unauthenticated (subject to GitHub's rate limits). To authenticate via the gh CLI, run gh auth login.
The token needs read access to the repository's pull requests.
- Fetch the backport PR and parse it to find source PR references
- Resolve source PRs using one of these methods:
- Body markers:
Backport #123 to branch/...orBackport: #123 - Commit messages:
Fix something (#123)patterns in cherry-picked commits
- Body markers:
- Fetch and normalize diffs from all source PRs and the backport PR
- Compare normalized diffs and report discrepancies
- Generate report showing:
- PR URLs and metadata
- Files with differences
- Added/removed lines that shouldn't be there
Example output when backport differs from source:
Backport PR: https://github.com/acme/myrepo/pull/200 -- Fix authentication bug
Source PRs: https://github.com/acme/myrepo/pull/100 (resolved via body markers)
diff -- lib/auth/server.go
source removed, backport kept:
- if s.legacyMode {
- return s.startLegacy()
- }
When the backport matches perfectly:
Backport PR: https://github.com/acme/myrepo/pull/200 -- Fix authentication bug
Source PRs: https://github.com/acme/myrepo/pull/100 (resolved via body markers)
No differences found.
- Maximum 250 commits per PR (GitHub API limit)
- Requires source PRs to be explicitly referenced in the backport PR body or commit messages