Skip to content

Commit b204b96

Browse files
zgliczclaude
andauthored
JS-1446 Fix: compare ruling against PR base branch, not latest master (#6580)
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 85d5bc9 commit b204b96

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,10 @@ jobs:
10811081
GH_TOKEN: ${{ github.token }}
10821082
PR_NUMBER: ${{ github.event.pull_request.number }}
10831083
HEAD_REF: ${{ github.head_ref }}
1084+
BASE_REF: ${{ github.base_ref }}
10841085
RULING_FAILED: ${{ steps.ruling.outcome == 'failure' }}
10851086
run: |
1086-
git fetch origin master
1087+
git fetch origin "$BASE_REF"
10871088
10881089
# If ruling failed, sync the actual results first to get the differences
10891090
if [ "$RULING_FAILED" = "true" ]; then
@@ -1098,7 +1099,7 @@ jobs:
10981099
npm run ruling-sync
10991100
fi
11001101
1101-
# Generate report comparing against master (after sync if ruling failed)
1102+
# Generate report comparing against base branch (after sync if ruling failed)
11021103
node tools/ruling-report.js > ruling-report.md
11031104
11041105
# Check if there are ruling differences

tools/ruling-report.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
*
2121
* Usage: node tools/ruling-report.js
2222
*
23-
* Compares ruling JSON files against origin/master and generates a report
24-
* showing all changes introduced by the current branch.
23+
* Compares ruling JSON files against the PR base branch (via BASE_REF env var,
24+
* defaults to master) and generates a report showing all changes introduced by
25+
* the current branch.
2526
*/
2627

2728
import { execSync } from 'child_process';
@@ -32,13 +33,13 @@ import { fileURLToPath } from 'url';
3233
const __dirname = dirname(fileURLToPath(import.meta.url));
3334
const ROOT_DIR = join(__dirname, '..');
3435
const SOURCES_DIR = join(ROOT_DIR, 'its/sources');
35-
const BASE_REF = 'origin/master';
36+
const BASE_REF = `origin/${process.env.BASE_REF ?? 'master'}`;
3637
const SOURCES_REPO_URL = 'https://github.com/SonarSource/jsts-test-sources/blob/master';
3738
const RSPEC_URL = 'https://musical-adventure-r9qk65j.pages.github.io/rspec/#';
3839

3940
function getChangedRulingFiles() {
4041
try {
41-
// Compare against master to show all changes introduced by this branch
42+
// Compare against base branch to show all changes introduced by this branch
4243
const output = execSync(`git diff ${BASE_REF} --name-only its/ruling/src/test/expected/`, {
4344
cwd: ROOT_DIR,
4445
encoding: 'utf-8',
@@ -72,27 +73,27 @@ function getRulingChanges(filePath) {
7273
// Get current (staged/working) version
7374
const currentData = parseRulingJson(fullPath);
7475

75-
// Get master version (suppress stderr for new files)
76-
let masterData = {};
76+
// Get base branch version (suppress stderr for new files)
77+
let baseData = {};
7778
try {
78-
const masterContent = execSync(`git show ${BASE_REF}:${filePath} 2>/dev/null`, {
79+
const baseContent = execSync(`git show ${BASE_REF}:${filePath} 2>/dev/null`, {
7980
cwd: ROOT_DIR,
8081
encoding: 'utf-8',
8182
stdio: ['pipe', 'pipe', 'pipe'],
8283
});
83-
masterData = JSON.parse(masterContent);
84+
baseData = JSON.parse(baseContent);
8485
} catch {
8586
// File might be new
8687
}
8788

88-
// Find added lines (in current but not in master)
89+
// Find added lines (in current but not in base branch)
8990
for (const [fileKey, lines] of Object.entries(currentData)) {
90-
const masterLines = new Set(masterData[fileKey] || []);
91+
const baseLines = new Set(baseData[fileKey] || []);
9192
// Extract relative path from "project:path" format
9293
const relativePath = fileKey.includes(':') ? fileKey.split(':')[1] : fileKey;
9394

9495
for (const line of lines) {
95-
if (!masterLines.has(line)) {
96+
if (!baseLines.has(line)) {
9697
changes.push({
9798
type: 'added',
9899
project,
@@ -105,8 +106,8 @@ function getRulingChanges(filePath) {
105106
}
106107
}
107108

108-
// Find removed lines (in master but not in current)
109-
for (const [fileKey, lines] of Object.entries(masterData)) {
109+
// Find removed lines (in base branch but not in current)
110+
for (const [fileKey, lines] of Object.entries(baseData)) {
110111
const currentLines = new Set(currentData[fileKey] || []);
111112
const relativePath = fileKey.includes(':') ? fileKey.split(':')[1] : fileKey;
112113

0 commit comments

Comments
 (0)