@@ -1020,22 +1020,24 @@ async function fetchRepoReleases(owner, repoName, repoLabel) {
10201020 }
10211021}
10221022
1023- async function processProduct ( product ) {
1024- const productName = product . displayName ;
1025- const changelogPath = path . join (
1026- REPO_ROOT ,
1027- `v2/solutions/${ product . key } /changelog.mdx`
1028- ) ;
1029-
1030- const hasGitHub = product . github && product . github . releasesActive ;
1031- const hasGitLab = product . gitlab && product . gitlab . releasesActive ;
1032- const gitlabIsPrimary = hasGitLab && product . gitlab . primary ;
1023+ /**
1024+ * Process a single changelog target. Branches on target.mode:
1025+ * "releases" → existing GitHub/GitLab release fetching (default behaviour)
1026+ * "commits" → fetchCommitEntries() + optional verifyContractChanges()
1027+ *
1028+ * @param {object } target - Resolved changelog target from loadChangelogTargets()
1029+ */
1030+ async function processTarget ( target ) {
1031+ const displayName = target . displayName || target . key ;
1032+ // Use outputPath from config — no longer hardcoded to v2/solutions/
1033+ const changelogPath = path . join ( REPO_ROOT , target . outputPath ) ;
1034+ const mode = target . mode || "releases" ;
10331035
10341036 // Build source description for logging
10351037 const sources = [ ] ;
1036- if ( hasGitHub ) sources . push ( `GitHub: ${ product . github . org } /${ product . github . mainRepo } ` ) ;
1037- if ( hasGitLab ) sources . push ( `GitLab: ${ product . gitlab . projectPath } ` ) ;
1038- console . log ( `\n═══ ${ productName } (${ sources . join ( " + " ) } ) ═══` ) ;
1038+ if ( target . github ) sources . push ( `GitHub: ${ target . github . org } /${ target . github . repo || target . github . mainRepo } ` ) ;
1039+ if ( target . gitlab ) sources . push ( `GitLab: ${ target . gitlab . projectPath } ` ) ;
1040+ console . log ( `\n═══ ${ displayName } [ ${ mode } ] (${ sources . join ( " + " ) } ) ═══` ) ;
10391041
10401042 if ( ! fs . existsSync ( changelogPath ) ) {
10411043 console . log ( ` Changelog file not found: ${ changelogPath } — skipping.` ) ;
@@ -1045,10 +1047,10 @@ async function processProduct(product) {
10451047 // --regenerate: wipe all entries, keep the template header up to the automation zone marker
10461048 if ( REGENERATE ) {
10471049 const marker = "────────────────────────────────────────────── */}" ;
1048- const content = fs . readFileSync ( changelogPath , "utf8" ) ;
1049- const markerIdx = content . indexOf ( marker ) ;
1050+ const existingContent = fs . readFileSync ( changelogPath , "utf8" ) ;
1051+ const markerIdx = existingContent . indexOf ( marker ) ;
10501052 if ( markerIdx !== - 1 ) {
1051- const truncated = content . slice ( 0 , markerIdx + marker . length ) + "\n" ;
1053+ const truncated = existingContent . slice ( 0 , markerIdx + marker . length ) + "\n" ;
10521054 if ( ! DRY_RUN ) {
10531055 fs . writeFileSync ( changelogPath , truncated ) ;
10541056 console . log ( ` --regenerate: wiped existing entries, kept template header.` ) ;
@@ -1058,12 +1060,75 @@ async function processProduct(product) {
10581060 }
10591061 }
10601062
1063+ // ── Mode: commits ────────────────────────────────────────────────────────────────
1064+ if ( mode === "commits" ) {
1065+ if ( ! target . github ) {
1066+ console . error ( ` ERROR: mode:commits requires github config in changelogs.${ target . key } ` ) ;
1067+ return ;
1068+ }
1069+
1070+ const commits = await fetchCommitEntries ( target ) ;
1071+ console . log ( ` Fetched ${ commits . length } commit(s)` ) ;
1072+
1073+ if ( commits . length === 0 ) {
1074+ console . log ( " No commits found." ) ;
1075+ return ;
1076+ }
1077+
1078+ const existing = fs . readFileSync ( changelogPath , "utf8" ) ;
1079+ const newCommits = commits . filter ( ( c ) => ! existing . includes ( `## ${ c . tag_name } ` ) ) ;
1080+
1081+ if ( newCommits . length === 0 ) {
1082+ console . log ( " All commits already in changelog. Nothing to do." ) ;
1083+ return ;
1084+ }
1085+
1086+ console . log ( ` ${ newCommits . length } new commit(s) to add.` ) ;
1087+
1088+ const blocks = [ ] ;
1089+ for ( const commit of newCommits ) {
1090+ let verifications = [ ] ;
1091+ if ( target . contract || CONTRACT ) {
1092+ verifications = await verifyContractChanges ( commit , target ) ;
1093+ }
1094+ blocks . push ( buildCommitUpdateBlock ( commit , verifications , target ) ) ;
1095+ }
1096+
1097+ const output = blocks . join ( "\n" ) ;
1098+ const marker = "────────────────────────────────────────────── */}" ;
1099+ const markerIdx = existing . indexOf ( marker ) ;
1100+
1101+ if ( markerIdx === - 1 ) {
1102+ console . error ( ` ERROR: Could not find automation zone marker in ${ changelogPath } ` ) ;
1103+ return ;
1104+ }
1105+
1106+ const insertAt = markerIdx + marker . length ;
1107+ const updated = existing . slice ( 0 , insertAt ) + "\n\n" + output + "\n" + existing . slice ( insertAt ) ;
1108+
1109+ if ( DRY_RUN ) {
1110+ console . log ( `\n ── DRY RUN ── Would write to ${ changelogPath } :\n` ) ;
1111+ console . log ( output ) ;
1112+ console . log ( `\n ── ${ newCommits . length } block(s) would be added.` ) ;
1113+ return ;
1114+ }
1115+
1116+ fs . writeFileSync ( changelogPath , updated ) ;
1117+ console . log ( ` Written ${ newCommits . length } new commit(s) to ${ changelogPath } ` ) ;
1118+ return ;
1119+ }
1120+
1121+ // ── Mode: releases (default) ─────────────────────────────────────────────────────────────────────────
1122+ const hasGitHub = target . github && ( target . github . releasesActive || target . github . mainRepo || target . github . repo ) ;
1123+ const hasGitLab = target . gitlab && target . gitlab . releasesActive ;
1124+ const gitlabIsPrimary = hasGitLab && target . gitlab . primary ;
1125+
10611126 // Fetch releases from GitHub
10621127 let githubReleases = [ ] ;
10631128 if ( hasGitHub ) {
1064- const owner = product . github . org ;
1065- const changelogRepos = product . github . changelogRepos || [
1066- { repo : product . github . mainRepo , label : product . github . mainRepo } ,
1129+ const owner = target . github . org ;
1130+ const changelogRepos = target . github . changelogRepos || [
1131+ { repo : target . github . mainRepo || target . github . repo , label : target . github . mainRepo || target . github . repo } ,
10671132 ] ;
10681133 for ( const { repo, label } of changelogRepos ) {
10691134 const releases = await fetchRepoReleases ( owner , repo , label ) ;
@@ -1075,12 +1140,12 @@ async function processProduct(product) {
10751140 // Fetch releases from GitLab
10761141 let gitlabReleases = [ ] ;
10771142 if ( hasGitLab ) {
1078- const changelogRepos = product . gitlab . changelogRepos || [
1079- { projectId : product . gitlab . projectId , projectPath : product . gitlab . projectPath , label : productName } ,
1143+ const changelogRepos = target . gitlab . changelogRepos || [
1144+ { projectId : target . gitlab . projectId , projectPath : target . gitlab . projectPath , label : displayName } ,
10801145 ] ;
10811146 for ( const { projectId, label } of changelogRepos ) {
10821147 const releases = await fetchGitLabRepoReleases (
1083- product . gitlab . instanceUrl ,
1148+ target . gitlab . instanceUrl ,
10841149 projectId ,
10851150 label
10861151 ) ;
@@ -1126,18 +1191,18 @@ async function processProduct(product) {
11261191 console . log ( ` ${ newReleases . length } new release(s) to add.` ) ;
11271192
11281193 // Determine if this is a multi-repo product (GitHub side)
1129- const githubChangelogRepos = ( hasGitHub && product . github . changelogRepos ) || [ ] ;
1194+ const githubChangelogRepos = ( hasGitHub && target . github . changelogRepos ) || [ ] ;
11301195 const isMultiRepo = githubChangelogRepos . length > 1 ;
1131- const owner = hasGitHub ? product . github . org : "" ;
1196+ const owner = hasGitHub ? target . github . org : "" ;
11321197
11331198 // Generate Update blocks
11341199 const blocks = [ ] ;
11351200 for ( const release of newReleases ) {
11361201 const repo = release . _repo ;
11371202 const repoLabel = release . _repoLabel ;
1138- const displayName = isMultiRepo
1139- ? `${ productName } ${ repoLabel } `
1140- : productName ;
1203+ const releaseDisplayName = isMultiRepo
1204+ ? `${ displayName } ${ repoLabel } `
1205+ : displayName ;
11411206 const labelForBlock = isMultiRepo ? repoLabel : null ;
11421207
11431208 // Find previous tag within the same source for commit comparison
@@ -1151,7 +1216,7 @@ async function processProduct(product) {
11511216 : null ;
11521217
11531218 // Pass GitLab config for commit fetching when source is GitLab
1154- const gitlabConfig = release . _source === "gitlab" ? product . gitlab : null ;
1219+ const gitlabConfig = release . _source === "gitlab" ? target . gitlab : null ;
11551220
11561221 if ( ENHANCE ) {
11571222 blocks . push (
@@ -1160,13 +1225,13 @@ async function processProduct(product) {
11601225 prevTag ,
11611226 owner ,
11621227 repo ,
1163- displayName ,
1228+ releaseDisplayName ,
11641229 labelForBlock ,
11651230 gitlabConfig
11661231 )
11671232 ) ;
11681233 } else {
1169- blocks . push ( generateUpdateBlockRaw ( release , displayName , labelForBlock ) ) ;
1234+ blocks . push ( generateUpdateBlockRaw ( release , releaseDisplayName , labelForBlock ) ) ;
11701235 }
11711236 }
11721237
@@ -1202,18 +1267,22 @@ async function processProduct(product) {
12021267 ) ;
12031268}
12041269
1270+
12051271async function main ( ) {
1206- const products = loadProductConfig ( PRODUCT_KEY ) ;
1272+ const targets = loadChangelogTargets ( CHANGELOG_KEY , CHANGELOG_CATEGORY ) ;
12071273
12081274 console . log (
1209- `Processing ${ products . length } product (s) (limit: ${ LIMIT } releases each)`
1275+ `Processing ${ targets . length } changelog target (s) (limit: ${ LIMIT } entries each)`
12101276 ) ;
12111277 if ( ENHANCE ) {
12121278 console . log ( `LLM enhancement enabled (provider: ${ LLM_PROVIDER } )` ) ;
12131279 }
1280+ if ( CONTRACT ) {
1281+ console . log ( `Contract mode: on-chain verification enabled` ) ;
1282+ }
12141283
1215- for ( const product of products ) {
1216- await processProduct ( product ) ;
1284+ for ( const target of targets ) {
1285+ await processTarget ( target ) ;
12171286 }
12181287
12191288 console . log ( "\nDone." ) ;
0 commit comments