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