()
| 1771 | } |
| 1772 | |
| 1773 | function 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 | |
| 1797 | interface GitHubEventPayload { |
| 1798 | pull_request?: { |
no test coverage detected
searching dependent graphs…