11import path from 'node:path'
22import fsPromises from 'node:fs/promises'
3+ import { JSDOM } from 'jsdom'
34import { DateTime } from 'luxon'
45import { groupBy } from 'es-toolkit'
56import { PurpleApi } from '../../generated/purple_client/index.ts'
67import { getDOMParser , validateXml } from '../utils/dom.ts'
78import { getQueueCommon } from '../utils/queue.ts'
89import { type QueueCommon } from '../../../website/app/utils/validators.ts'
9- import { JSDOM } from 'jsdom'
1010
1111type Props = {
1212 api : PurpleApi
@@ -27,23 +27,37 @@ const XML_DECLARATION = '<?xml version="1.0" encoding="utf-8"?>'
2727 * Generates a queue.xml file aNd validate against the XSD
2828 */
2929export const renderQueueXML = async ( queue : QueueCommon ) : Promise < string > => {
30- // console.log("========")
31- // console.log(JSON.stringify(queue, null, 2))
32- // console.log("========")
30+ console . log ( "========" )
31+ console . log ( JSON . stringify ( queue , null , 2 ) )
32+ console . log ( "========" )
3333
3434 const dom = await getDOMParser ( )
3535
3636 const doc = dom . parseFromString ( `<rfc-editor-queue xmlns="${ NAMESPACE } "></rfc-editor-queue>` , 'text/xml' )
3737
38- const itemsbyGroup = groupBy ( queue . items , ( item ) => item . stream ?? 'NO STREAM' )
38+ const itemsbyGroup = groupBy ( queue . items , ( item ) => {
39+ // eg "IETF STREAM: WORKING GROUP STANDARDS TRACK"
40+ // or "IETF STREAM: NON-WORKING GROUP STANDARDS TRACK"
41+ const sectionNameParts = [
42+ item . stream ?. toUpperCase ( ) ,
43+ item . groupName ?. toUpperCase ( )
44+ ] . filter ( val => Boolean ( val ) )
45+
46+ if ( sectionNameParts . length > 0 ) {
47+ const COLON_AND_SPACE = ': '
48+ const sectionName = sectionNameParts . join ( COLON_AND_SPACE )
49+ return sectionName
50+ }
51+ return 'UNKNOWN'
52+ } )
3953 const sections = Object . keys ( itemsbyGroup )
4054
4155 sections . forEach ( section => {
4256 // eg <section name="IETF STREAM: WORKING GROUP STANDARDS TRACK">
4357 // or <section name="IETF STREAM: NON-WORKING GROUP STANDARDS TRACK">
4458 const sectionEl = doc . createElementNS ( NAMESPACE , 'section' )
4559 doc . documentElement . append ( sectionEl )
46- sectionEl . setAttribute ( 'name' , section . toUpperCase ( ) )
60+ sectionEl . setAttribute ( 'name' , section )
4761
4862 const items = itemsbyGroup [ section ]
4963 items . forEach ( item => {
@@ -77,9 +91,19 @@ export const renderQueueXML = async (queue: QueueCommon): Promise<string> => {
7791 } )
7892 }
7993
80- // TODO
8194 // eg <normRef><ref-name>draft-ietf-ecrit-lost-planned-changes</ref-name><ref-state>NOT-RECEIVED</ref-state></normRef>
82- // TODO
95+ item . references ?. forEach ( reference => {
96+ const normRefEl = doc . createElementNS ( NAMESPACE , 'normRef' )
97+ entryEl . append ( normRefEl )
98+
99+ const refNameEl = doc . createElementNS ( NAMESPACE , 'ref-name' )
100+ normRefEl . append ( refNameEl )
101+ refNameEl . textContent = reference . targetDraftName
102+
103+ const refStateEl = doc . createElementNS ( NAMESPACE , 'ref-state' )
104+ normRefEl . append ( refStateEl )
105+ refStateEl . textContent = reference . relationship . toUpperCase ( )
106+ } )
83107
84108 // eg <authors>B. Rosen, R. Marshall, J. Martin</authors>
85109 const authorsEl = doc . createElementNS ( NAMESPACE , 'authors' )
@@ -94,12 +118,12 @@ export const renderQueueXML = async (queue: QueueCommon): Promise<string> => {
94118 entryEl . append ( titleEl )
95119 titleEl . textContent = item . title
96120
97- // TODO
98- // eg <source>Emergency Context Resolution with Internet Technologies</source>
99- // const sourceEl = doc.createElementNS(NS , 'source')
100- // entryEl.append(sourceEl)
101- // titleEl .textContent = item.source
102- // TODO
121+ if ( item . groupName ) {
122+ // eg <source>Emergency Context Resolution with Internet Technologies</source>
123+ const sourceEl = doc . createElementNS ( NAMESPACE , 'source' )
124+ entryEl . append ( sourceEl )
125+ sourceEl . textContent = item . groupName
126+ }
103127
104128 // eg <consensus>yes</consensus>
105129 const consensusEl = doc . createElementNS ( NAMESPACE , 'consensus' )
0 commit comments