@@ -23,22 +23,56 @@ const main = async (...args) => {
2323 const addURL = url => {
2424 const fileName = url . replace ( / .* \/ / , '' )
2525 const match = fileName . match ( fileNameRegex )
26- if ( ! match ) throw new Error ( `Cannot parse URL: ${ url } ` )
26+ if ( ! match ) throw new Error ( `Cannot parse URL: ${ url } (fileName: ${ fileName } ) ` )
2727 else if ( match [ 1 ] ) urls . installers . push ( { url, cpu : cpus [ match [ 2 ] ] } )
2828 else if ( match [ 3 ] ) urls . portableGits . push ( { url, cpu : cpus [ match [ 4 ] ] } )
2929 else if ( match [ 5 ] ) urls . busyBoxMinGits . push ( { url, cpu : cpus [ match [ 6 ] ] } )
3030 else if ( match [ 7 ] ) urls . minGits . push ( { url, cpu : cpus [ match [ 8 ] ] } )
3131 else throw new Error ( `Cannot parse URL: ${ url } ` )
3232 }
3333
34+ let mode = 'append-to-top'
3435 let date
3536 let commit
3637 while ( args . length > 0 ) {
3738 const arg = args . shift ( )
3839 if ( arg . startsWith ( '--date=' ) ) date = arg . replace ( / .* ?= / , '' )
3940 else if ( arg . startsWith ( '--commit=' ) ) commit = arg . replace ( / .* ?= / , '' )
4041 else if ( arg . startsWith ( 'https://' ) ) addURL ( arg )
41- else {
42+ else if ( arg . startsWith ( '--backfill-release=' ) ) {
43+ if ( args . length ) throw new Error ( `--backfill-release cannot be combined with other arguments!` )
44+ const tagName = arg . replace ( / .* ?= / , '' )
45+ . replace ( / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ g i t - f o r - w i n d o w s \/ g i t \/ r e l e a s e s \/ t a g \/ / , '' )
46+ if ( ! tagName . match ( / ^ v [ 1 - 9 ] [ 0 - 9 ] * ( \. \d + ) { 2 } ( - r c \d + ) ? \. w i n d o w s \. \d + $ / ) ) {
47+ throw new Error ( `Unexpected tag format: '${ tagName } '!` )
48+ }
49+
50+ const gh = async ( path ) =>
51+ ( await fetch ( `https://api.github.com/repos/git-for-windows/git/${ path } ` ) ) . json ( )
52+ const { object : { sha : tagSHA } } = await gh ( `git/ref/tags/${ tagName } ` )
53+ const { object : { sha : commitSHA } } = await gh ( `git/tags/${ tagSHA } ` )
54+ commit = commitSHA
55+ const { committer : { date : commitDate } } = await gh ( `git/commits/${ commitSHA } ` )
56+ date = ( new Date ( commitDate ) ) . toLocaleString ( 'en-US' , {
57+ weekday : 'short' ,
58+ month : 'short' ,
59+ day : 'numeric' ,
60+ year : 'numeric' ,
61+ hour : '2-digit' ,
62+ hourCycle : "h24" ,
63+ minute : '2-digit' ,
64+ second : '2-digit' ,
65+ timeZoneName : 'longOffset' ,
66+ timeZone : "Etc/UTC"
67+ } )
68+
69+ const { assets } = await gh ( `releases/tags/${ tagName } ` )
70+ assets . forEach ( asset => {
71+ if ( ! asset . name . endsWith ( '.tar.bz2' ) && ! asset . name . startsWith ( 'pdbs' ) ) addURL ( asset . browser_download_url )
72+ } )
73+
74+ mode = 'insert-by-date'
75+ } else {
4276 throw new Error ( `Unhandled argument '${ arg } ` )
4377 }
4478 }
@@ -87,7 +121,12 @@ const main = async (...args) => {
87121 '</ul>'
88122 ] . join ( '' )
89123
90- sections [ 1 ] = `${ insert } \n\n${ sections [ 1 ] } `
124+ let index = 1
125+ if ( mode === 'insert-by-date' ) {
126+ while ( index + 2 < sections . length && insert . localeCompare ( sections [ index ] ) < 0 ) index += 2
127+ } else if ( mode !== 'append-to-top' ) throw new Error ( `Unhandled mode: '${ mode } '` )
128+ sections [ index ] = `${ insert } \n\n${ sections [ index ] } `
129+
91130 fs . writeFileSync ( 'index.html' , sections . join ( '' ) )
92131}
93132
0 commit comments