@@ -23,22 +23,56 @@ const main = async (...args) => {
23
23
const addURL = url => {
24
24
const fileName = url . replace ( / .* \/ / , '' )
25
25
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 } ) ` )
27
27
else if ( match [ 1 ] ) urls . installers . push ( { url, cpu : cpus [ match [ 2 ] ] } )
28
28
else if ( match [ 3 ] ) urls . portableGits . push ( { url, cpu : cpus [ match [ 4 ] ] } )
29
29
else if ( match [ 5 ] ) urls . busyBoxMinGits . push ( { url, cpu : cpus [ match [ 6 ] ] } )
30
30
else if ( match [ 7 ] ) urls . minGits . push ( { url, cpu : cpus [ match [ 8 ] ] } )
31
31
else throw new Error ( `Cannot parse URL: ${ url } ` )
32
32
}
33
33
34
+ let mode = 'append-to-top'
34
35
let date
35
36
let commit
36
37
while ( args . length > 0 ) {
37
38
const arg = args . shift ( )
38
39
if ( arg . startsWith ( '--date=' ) ) date = arg . replace ( / .* ?= / , '' )
39
40
else if ( arg . startsWith ( '--commit=' ) ) commit = arg . replace ( / .* ?= / , '' )
40
41
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 {
42
76
throw new Error ( `Unhandled argument '${ arg } ` )
43
77
}
44
78
}
@@ -87,7 +121,12 @@ const main = async (...args) => {
87
121
'</ul>'
88
122
] . join ( '' )
89
123
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
+
91
130
fs . writeFileSync ( 'index.html' , sections . join ( '' ) )
92
131
}
93
132
0 commit comments