MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / detectPrNumber

Function detectPrNumber

packages/bumpy/src/commands/ci.ts:1773–1795  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1771}
1772
1773function detectPrNumber(): string | null {
1774 // GitHub Actions: read PR number from the event payload — same shape for
1775 // both `pull_request` and `pull_request_target` (under `pull_request_target`,
1776 // GITHUB_REF points at the base branch, not refs/pull/N/merge).
1777 const eventName = process.env.GITHUB_EVENT_NAME;
1778 if (eventName === 'pull_request' || eventName === 'pull_request_target') {
1779 const event = readGitHubEventPayload();
1780 const num = event?.pull_request?.number;
1781 if (typeof num === 'number') return String(num);
1782 // Fallback for `pull_request`: parse GITHUB_REF if payload wasn't readable.
1783 if (eventName === 'pull_request') {
1784 const match = process.env.GITHUB_REF?.match(/refs\/pull\/(\d+)\//);
1785 if (match) return match[1]!;
1786 }
1787 }
1788 // Also check for explicit env var — validate it's numeric
1789 const envPr = process.env.BUMPY_PR_NUMBER || process.env.PR_NUMBER || null;
1790 if (envPr && !/^\d+$/.test(envPr)) {
1791 log.warn(`Ignoring invalid PR number from environment: ${envPr}`);
1792 return null;
1793 }
1794 return envPr;
1795}
1796
1797interface GitHubEventPayload {
1798 pull_request?: {

Callers 3

ciCheckCommandFunction · 0.85
resolveTargetPrNumberFunction · 0.85
ciSnapshotReleaseFunction · 0.85

Calls 1

readGitHubEventPayloadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…