@@ -5,6 +5,19 @@ interface PR { |
5 | 5 | title: string |
6 | 6 | } |
7 | 7 |
|
| 8 | +interface Repo { |
| 9 | + nameWithOwner: string |
| 10 | +} |
| 11 | + |
| 12 | +interface HeadRepo { |
| 13 | + nameWithOwner: string |
| 14 | +} |
| 15 | + |
| 16 | +interface PRHead { |
| 17 | + headRefName: string |
| 18 | + headRepository: HeadRepo |
| 19 | +} |
| 20 | + |
8 | 21 | async function main() { |
9 | 22 | console.log("Fetching open contributor PRs...") |
10 | 23 |
|
@@ -16,6 +29,12 @@ async function main() { |
16 | 29 | const prs: PR[] = JSON.parse(prsResult.stdout) |
17 | 30 | console.log(`Found ${prs.length} open contributor PRs`) |
18 | 31 |
|
| 32 | + const repoResult = await $`gh repo view --json nameWithOwner`.nothrow() |
| 33 | + if (repoResult.exitCode !== 0) { |
| 34 | + throw new Error(`Failed to fetch repo info: ${repoResult.stderr}`) |
| 35 | + } |
| 36 | + const repo: Repo = JSON.parse(repoResult.stdout) |
| 37 | + |
19 | 38 | console.log("Fetching latest dev branch...") |
20 | 39 | const fetchDev = await $`git fetch origin dev`.nothrow() |
21 | 40 | if (fetchDev.exitCode !== 0) { |
@@ -34,9 +53,18 @@ async function main() { |
34 | 53 | for (const pr of prs) { |
35 | 54 | console.log(`\nProcessing PR #${pr.number}: ${pr.title}`) |
36 | 55 |
|
37 | | - // Get the diff from GitHub |
| 56 | + const headResult = await $`gh pr view ${pr.number} --json headRefName,headRepository`.nothrow() |
| 57 | + if (headResult.exitCode !== 0) { |
| 58 | + console.log(` Failed to get head info`) |
| 59 | + skipped.push({ number: pr.number, reason: `Failed to get head info: ${headResult.stderr}` }) |
| 60 | + continue |
| 61 | + } |
| 62 | + const head: PRHead = JSON.parse(headResult.stdout) |
| 63 | + |
| 64 | + // Get the diff from GitHub compare API |
38 | 65 | console.log(` Getting diff...`) |
39 | | - const diffResult = await $`gh pr diff ${pr.number}`.nothrow() |
| 66 | + const compare = `${repo.nameWithOwner}/compare/dev...${head.headRepository.nameWithOwner}:${head.headRefName}` |
| 67 | + const diffResult = await $`gh api -H Accept:application/vnd.github.v3.diff repos/${compare}`.nothrow() |
40 | 68 | if (diffResult.exitCode !== 0) { |
41 | 69 | console.log(` Failed to get diff`) |
42 | 70 | skipped.push({ number: pr.number, reason: `Failed to get diff: ${diffResult.stderr}` }) |
@@ -80,7 +108,7 @@ async function main() { |
80 | 108 | const commitMsg = `Apply PR #${pr.number}: ${pr.title}` |
81 | 109 | const commit = await $`git commit -m ${commitMsg}`.nothrow() |
82 | 110 | if (commit.exitCode !== 0) { |
83 | | - console.log(` Failed to commit`) |
| 111 | + console.log(` Failed to commit: ${commit.stderr}`) |
84 | 112 | await $`git checkout -- .`.nothrow() |
85 | 113 | await $`git clean -fd`.nothrow() |
86 | 114 | skipped.push({ number: pr.number, reason: `Commit failed: ${commit.stderr}` }) |
|