@@ -2,12 +2,19 @@ import { SIZE_PAGE } from './config';
22import { logRequest } from '@/util/logRequest' ;
33import { graphqlResults } from '@/services/gql' ;
44
5- export const getChangelog = async ( { page = 1 , vLts = "false" , singleVersion = "" , limit = SIZE_PAGE } ) => {
6- const assembleQuery = ( buildQuery :string , ltsQuery :string , ltsMajVersion :string , singleVersion :string ,
7- limit :number , page :number , sortBy :string ) => {
8- return `query ContentAPI {
5+ /** Escape a value for use inside Lucene quoted term (query_string). */
6+ function luceneQuotedTerm ( value : string ) : string {
7+ return value . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '\\"' ) ;
8+ }
9+
10+ /**
11+ * Embed full Lucene query in GraphQL string literal — inner " must be escaped.
12+ */
13+ function assembleQuery ( luceneQuery : string , limit : number , page : number , sortBy : string ) {
14+ const escaped = luceneQuery . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '\\"' ) ;
15+ return `query ContentAPI {
916 DotcmsbuildsCollection(
10- query: "${ buildQuery } ${ ltsQuery } ${ ltsMajVersion } ${ singleVersion } "
17+ query: "${ escaped } "
1118 limit: ${ limit }
1219 page: ${ page }
1320 sortBy: "${ sortBy } "
@@ -42,16 +49,17 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
4249 offset
4350 }
4451 }` ;
45- } ;
46-
52+ }
53+
54+ export const getChangelog = async ( { page = 1 , vLts = "false" , singleVersion = "" , limit = SIZE_PAGE } ) => {
4755 //Basic type info for querying any changelogs at all
4856 const buildQuery =
4957 '+contentType:Dotcmsbuilds +Dotcmsbuilds.released:true +Dotcmsbuilds.showInChangeLog:true +live:true' ;
5058
5159 //Build query components to grab one of each of the LTS major versions, for reference
5260 const ltsQueryMaj = '+Dotcmsbuilds.lts:1' ;
5361 const sortByEol = 'Dotcmsbuilds.eolDate desc' ;
54- const ltsMajorQuery = assembleQuery ( buildQuery , ltsQueryMaj , "" , "" , limit , page , sortByEol ) ;
62+ const ltsMajorQuery = assembleQuery ( ` ${ buildQuery } ${ ltsQueryMaj } ` , limit , page , sortByEol ) ;
5563 const ltsMajorResults = await logRequest ( async ( ) => graphqlResults ( ltsMajorQuery ) , 'getLTSMajorVersions' ) ;
5664 const ltsMajorResult = ltsMajorResults ?. data ;
5765
@@ -61,9 +69,11 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
6169 throw new Error ( ltsMajorResults . errors [ 0 ] . message ) ;
6270 }
6371
64- //if singleVersion is provided, check if it's an LTS patch version
72+ // If singleVersion is provided while already scoped to LTS (lts=…), detect patch lines
73+ // (e.g. 23.1.2 under tag 23.1). Skip when v is used alone on "current" — otherwise short
74+ // tags like "26" match calver minors such as 26.03.23-01 and we drop the minor filter.
6575 let ltsPatchVersion = "" ;
66- if ( singleVersion ) {
76+ if ( singleVersion && vLts && vLts !== "false" ) {
6777 for ( const item of ltsMajorResult . DotcmsbuildsCollection ) {
6878 for ( const vTag of item . tags ) {
6979 if ( singleVersion . startsWith ( vTag ) && singleVersion !== vTag ) {
@@ -95,7 +105,13 @@ export const getChangelog = async ({ page = 1, vLts = "false", singleVersion = "
95105 const ltsMajVersion = sussOutLatestMajor ( ltsMajorResult . DotcmsbuildsCollection [ 0 ] , vLts ) ;
96106 //console.log("sussed as:", ltsMajVersion);
97107 const sortBy = 'Dotcmsbuilds.releasedDate desc, Dotcmsbuilds.minor desc' ;
98- const query = assembleQuery ( buildQuery , ltsQuery , ltsMajVersion , ( singleVersion && ! ltsPatchVersion ) ? `+Dotcmsbuilds.minor:${ singleVersion } ` : "" , ( ltsMajVersion ? 20 : limit ) , page , sortBy ) ;
108+ // Quote minor so hyphens (e.g. 26.03.23-01) are not parsed as Lucene operators.
109+ const minorClause =
110+ singleVersion && ! ltsPatchVersion
111+ ? `+Dotcmsbuilds.minor:"${ luceneQuotedTerm ( singleVersion ) } "`
112+ : '' ;
113+ const luceneQuery = `${ buildQuery } ${ ltsQuery } ${ ltsMajVersion } ${ minorClause } ` . trim ( ) ;
114+ const query = assembleQuery ( luceneQuery , ltsMajVersion ? 20 : limit , page , sortBy ) ;
99115 const result = await logRequest ( async ( ) => graphqlResults ( query ) , 'getChangelog' ) ;
100116
101117 if ( result ?. errors && result . errors . length > 0 ) {
0 commit comments