Skip to content

Commit 77d5849

Browse files
committed
tools: fix api-diff to get more precise PR base commit
1 parent f8c05f2 commit 77d5849

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tools/deno/api-diff.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,28 @@ async function getCommitRange(
6666
// if there are no args or the arg is a number, we're talking about a PR
6767
if (args.length === 0 || typeof args[0] === 'number') {
6868
const prNum = args[0] || (await pickPr())
69+
// This commits and parents thing is absurd, but the idea is to use the
70+
// parent of the first commit as the base. If we just use the base ref
71+
// directly, hwe get the current state of main, which means the diff will
72+
// reflect both the current PR and any changes made on main since it branch
73+
// edoff.
6974
const query = `{
7075
repository(owner: "oxidecomputer", name: "omicron") {
7176
pullRequest(number: ${prNum}) {
72-
baseRefOid
7377
headRefOid
78+
commits(first: 1) {
79+
nodes {
80+
commit {
81+
parents(first: 1) { nodes { oid } }
82+
}
83+
}
84+
}
7485
}
7586
}
7687
}`
7788
const pr = await $`gh api graphql -f query=${query}`.json()
78-
const { baseRefOid: base, headRefOid: head } = pr.data.repository.pullRequest
89+
const head = pr.data.repository.pullRequest.headRefOid
90+
const base = pr.data.repository.pullRequest.commits.nodes[0].commit.parents.nodes[0].oid
7991
return { base, head }
8092
}
8193

0 commit comments

Comments
 (0)