This is an automated email from the ASF dual-hosted git repository.

yuqi1129 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 37ec5b2975 [Cherry-pick to branch-2.0] [MINOR] fix(ci): Break ties 
when selecting a pre-PR Fork CI base (#15068) (#15072)
37ec5b2975 is described below

commit 37ec5b29750651d01dad6a3b0d6fc31714b08493
Author: Qi Yu <[email protected]>
AuthorDate: Wed Nov 18 19:32:24 2026 +0800

    [Cherry-pick to branch-2.0] [MINOR] fix(ci): Break ties when selecting a 
pre-PR Fork CI base (#15068) (#15072)
    
    **Cherry-pick Information:**
    - Original commit: 82f27aee5d1a2cb3d982773e8b7c6a1636a6dfac
    - Target branch: `branch-2.0`
    - Status: ✅ Clean cherry-pick (no conflicts)
    - Fork CI: runs in `yuqi1129/gravitino`; re-run it there or push to this
    PR branch
---
 .github/scripts/resolve-fork-ci.cjs    | 12 ++++++++++--
 .github/scripts/tests/fork-ci.test.cjs | 19 ++++++++++++++-----
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/.github/scripts/resolve-fork-ci.cjs 
b/.github/scripts/resolve-fork-ci.cjs
index 305f2de7a1..a1057bf600 100644
--- a/.github/scripts/resolve-fork-ci.cjs
+++ b/.github/scripts/resolve-fork-ci.cjs
@@ -65,13 +65,21 @@ async function resolve({ github, context, core }) {
         const releases = branches.map(b => b.name).filter(n => 
/^branch-\d+\.\d+$/.test(n))
           .sort((a, b) => a.localeCompare(b, 'en', { numeric: true 
})).slice(-3);
         const candidates = [...new Set([upstream.default_branch, 
...releases])];
-        let fewest = Infinity;
+        let fewestAhead = Infinity;
+        let fewestBehind = Infinity;
         for (const candidate of candidates) {
           const { data: comparison } = await 
github.rest.repos.compareCommitsWithBasehead({
             owner: 'apache', repo: 'gravitino',
             basehead: `${candidate}...${context.repo.owner}:${headSha}`, 
per_page: 1
           });
-          if (comparison.ahead_by < fewest) { fewest = comparison.ahead_by; 
baseRef = candidate; }
+          // Branches sharing a fork point can have the same head-only commits.
+          // Prefer the candidate with fewer commits since that fork point.
+          if (comparison.ahead_by < fewestAhead ||
+              (comparison.ahead_by === fewestAhead && comparison.behind_by < 
fewestBehind)) {
+            fewestAhead = comparison.ahead_by;
+            fewestBehind = comparison.behind_by;
+            baseRef = candidate;
+          }
         }
         core.notice(`No open PR: testing against ${baseRef}; results require a 
matching PR base.`);
       }
diff --git a/.github/scripts/tests/fork-ci.test.cjs 
b/.github/scripts/tests/fork-ci.test.cjs
index a9ebe44ab7..ec3182c40f 100644
--- a/.github/scripts/tests/fork-ci.test.cjs
+++ b/.github/scripts/tests/fork-ci.test.cjs
@@ -190,17 +190,26 @@ test('fork pushes resolve the PR base once', async () => {
       getBranch: async () => ({ data: { commit: { sha: B } } }) } }, paginate: 
async () => [pr()] } });
   assert.equal(output['base-sha'], B); assert.equal(output['base-ref'], 
'main'); assert.equal(output.sync, 'true');
 });
-test('pre-PR base discovery paginates branches, including later release 
branches', async () => {
-  const output = {}; let paginated = false;
+async function discoverBase(main, release) {
+  const output = {};
   const listBranches = () => {};
   await resolve({ context: context('fork/repo', true), core: coreFor(output), 
github: {
     rest: { pulls: { list() {} }, repos: { listBranches,
       get: async args => ({ data: args.owner === 'fork' ? { fork: true, 
source: { full_name: 'apache/gravitino' } } : { default_branch: 'main' } }),
-      compareCommitsWithBasehead: async args => ({ data: { ahead_by: 
args.basehead.startsWith('branch-9.9...') ? 1 : 99 } }),
+      compareCommitsWithBasehead: async args => ({ data: 
args.basehead.startsWith('branch-2.0...') ? release : main }),
       getBranch: async () => ({ data: { commit: { sha: B } } }) } },
-    paginate: async endpoint => { if (endpoint === listBranches) { paginated = 
true; return [{ name: 'branch-9.9' }]; } return []; }
+    paginate: async endpoint => endpoint === listBranches ? [{ name: 
'branch-2.0' }] : []
   } });
-  assert.equal(paginated, true); assert.equal(output['base-ref'], 
'branch-9.9');
+  return output['base-ref'];
+}
+test('pre-PR base discovery prefers fewer head-only commits among paginated 
branches', async () => {
+  assert.equal(await discoverBase({ ahead_by: 2, behind_by: 0 }, { ahead_by: 
1, behind_by: 5 }), 'branch-2.0');
+});
+test('pre-PR backports prefer the closer base when both have the same 
head-only commits', async () => {
+  assert.equal(await discoverBase({ ahead_by: 1, behind_by: 13 }, { ahead_by: 
1, behind_by: 0 }), 'branch-2.0');
+});
+test('pre-PR base discovery keeps the default branch when both distances tie', 
async () => {
+  assert.equal(await discoverBase({ ahead_by: 1, behind_by: 0 }, { ahead_by: 
1, behind_by: 0 }), 'main');
 });
 test('trusted dispatch rejects an arbitrary ref or a non-upstream repository', 
async () => {
   const ctx = context('fork/repo');ctx.eventName = 
'workflow_dispatch';ctx.payload.inputs = { 'pull-request': '7' };

Reply via email to