Skip to content

Commit 274da36

Browse files
authored
Merge pull request #44 from dscho/guess-msys2-runtime-release-notes
Nicer MSYS2 runtime release notes
2 parents 81c2bcf + d622e0d commit 274da36

3 files changed

Lines changed: 136 additions & 16 deletions

File tree

GitForWindowsHelper/component-updates.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,38 @@ const needsSeparateARM64Build = package_name => {
5555
].includes(package_name)
5656
}
5757

58+
const guessCygwinReleaseNotesURL = async (version) => {
59+
const { fetchHTML } = require('./https-request')
60+
const html = await fetchHTML('https://cygwin.com')
61+
const match = html.match(new RegExp(`The most recent version of the Cygwin DLL is[^]*?<a href=['"]?([^"' ]*)[^>]*>${version}</a>`))
62+
if (match) return match[1]
63+
64+
// Sometimes Cygwin updates the home page a bit later than we'd want, let's
65+
// find the announcement on the mailing list directly in that case:
66+
const inboxPrefix = 'https://inbox.sourceware.org/cygwin-announce/'
67+
const search = await fetchHTML(`${inboxPrefix}?q=cygwin-${version}`)
68+
const searchMatch = search.match(new RegExp(`<a\\b(?:[^>]*)\\shref=['"]?([^'" ]+)[^>]*>cygwin ${version}-1</a>`))
69+
if (searchMatch) return `${inboxPrefix}${searchMatch[1]}`
70+
71+
throw new Error(`Could not determine Cygwin Release Notes URL for version ${version}`)
72+
}
73+
5874
const guessReleaseNotes = async (context, issue) => {
5975
if (!issue.pull_request
6076
&&issue.labels.filter(label => label.name === 'component-update').length !== 1) throw new Error(`Cannot determine release note from issue ${issue.number}`)
6177
let { package_name, version } = guessComponentUpdateDetails(issue.title, issue.body)
6278

79+
if (package_name === 'msys2-runtime') {
80+
const url = await guessCygwinReleaseNotesURL(version)
81+
const message = `Comes with the MSYS2 runtime (Git for Windows flavor) based on [Cygwin v${version}](${url}).`
82+
return {
83+
type: 'feature',
84+
message,
85+
package: package_name,
86+
version
87+
}
88+
}
89+
6390
const matchURLInIssue = (issue) => {
6491
const pattern = {
6592
bash: /(?:^|\n)(https:\/\/\S+)/, // use the first URL

GitForWindowsHelper/https-request.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,23 @@ const httpsRequest = async (context, hostname, method, requestPath, body, header
6161
})
6262
}
6363

64-
const doesURLReturn404 = async url => {
64+
const parseURL = url => {
6565
const match = url.match(/^https:\/\/([^/]+?)(:\d+)?(\/.*)?$/)
6666
if (!match) throw new Error(`Could not parse URL ${url}`)
6767

68-
const https = require('https')
69-
const options = {
70-
method: 'HEAD',
68+
return {
69+
method: 'GET',
7170
host: match[1],
7271
port: Number.parseInt(match[2] || '443'),
7372
path: match[3] || '/'
7473
}
74+
}
75+
76+
const doesURLReturn404 = async url => {
77+
const options = parseURL(url)
78+
options.method = 'HEAD'
79+
80+
const https = require('https')
7581
return new Promise((resolve, reject) => {
7682
https.request(options, res => {
7783
if (res.error) reject(res.error)
@@ -82,7 +88,43 @@ const doesURLReturn404 = async url => {
8288
})
8389
}
8490

91+
const fetchHTML = async url => {
92+
const options = parseURL(url)
93+
options.headers = {
94+
'User-Agent': 'GitForWindowsHelper/0.0',
95+
Accept: 'text/html'
96+
}
97+
return new Promise((resolve, reject) => {
98+
try {
99+
const https = require('https')
100+
const req = https.request(options, res => {
101+
res.on('error', e => reject(e))
102+
103+
const chunks = []
104+
res.on('data', data => chunks.push(data))
105+
res.on('end', () => {
106+
const html = Buffer.concat(chunks).toString('utf-8')
107+
if (res.statusCode > 299) {
108+
reject({
109+
statusCode: res.statusCode,
110+
statusMessage: res.statusMessage,
111+
body: html
112+
})
113+
} else {
114+
resolve(html)
115+
}
116+
})
117+
})
118+
req.on('error', err => reject(err))
119+
req.end()
120+
} catch (e) {
121+
reject(e)
122+
}
123+
})
124+
}
125+
85126
module.exports = {
86127
httpsRequest,
87-
doesURLReturn404
128+
doesURLReturn404,
129+
fetchHTML
88130
}

__tests__/component-updates.test.js

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ jest.mock('../GitForWindowsHelper/github-api-request', () => {
5656
return mockGithubApiRequest
5757
})
5858

59+
const mockFetchHTML = {
60+
'https://cygwin.com': `<div>
61+
62+
<h2 class="cartouche">Cygwin version</h2>
63+
64+
<p>
65+
The most recent version of the Cygwin DLL is
66+
<b><a href="https://cygwin.com/pipermail/cygwin-announce/2023-September/011291.html">3.4.9</a></b>.
67+
</p>
68+
<p>
69+
The Cygwin DLL currently works with all recent, commercially released
70+
x86_64 versions of Windows, starting with Windows 7.
71+
</p>
72+
</div>`,
73+
'https://inbox.sourceware.org/cygwin-announce/?q=cygwin-3.4.7': `<html><head><title>cygwin-3.4.7 - search results</title>[... plenty of stuff...]
74+
<pre>1. <b><a
75+
href="875y7c63s1.fsf@Rainer.invalid/">Re-Released: tar-1.34-2</a></b>
76+
- by ASSI @ 2023-06-24 19:47 UTC [4%]
77+
78+
2. <b><a
79+
href="20230616162552.879387-1-corinna-cygwin@cygwin.com/">cygwin 3.4.7-1</a></b>
80+
- by Corinna Vinschen @ 2023-06-16 14:25 UTC [14%]
81+
82+
</pre>[... even more stuff...]</body></html>`
83+
}
84+
const missingURL = 'https://wingit.blob.core.windows.net/x86-64/curl-8.1.2-1-x86_64.pkg.tar.xz'
85+
const missingMinTTYURL = 'https://wingit.blob.core.windows.net/i686/mintty-1~3.6.5-1-i686.pkg.tar.xz'
86+
const bogus32BitMSYS2RuntimeURL = 'https://wingit.blob.core.windows.net/i686/msys2-runtime-3.4.9-1-i686.pkg.tar.xz'
87+
const bogus64BitMSYS2RuntimeURL = 'https://wingit.blob.core.windows.net/x86-64/msys2-runtime-3.3-3.3.7-1-x86_64.pkg.tar.xz'
88+
const mockDoesURLReturn404 = jest.fn(url => [
89+
missingURL, missingMinTTYURL, bogus32BitMSYS2RuntimeURL, bogus64BitMSYS2RuntimeURL
90+
].includes(url))
91+
jest.mock('../GitForWindowsHelper/https-request', () => {
92+
return {
93+
doesURLReturn404: mockDoesURLReturn404,
94+
fetchHTML: jest.fn(url => mockFetchHTML[url])
95+
}
96+
})
97+
98+
5999
test('guessReleaseNotes()', async () => {
60100
const context = { log: jest.fn() }
61101
expect(await guessReleaseNotes(context, {
@@ -127,20 +167,31 @@ http://www.gnutls.org/news.html#2023-02-10`
127167
package: 'openssl',
128168
version: '3.1.1'
129169
})
130-
})
131170

132-
test('getMissingDeployments()', async () => {
133-
const missingURL = 'https://wingit.blob.core.windows.net/x86-64/curl-8.1.2-1-x86_64.pkg.tar.xz'
134-
const missingMinTTYURL = 'https://wingit.blob.core.windows.net/i686/mintty-1~3.6.5-1-i686.pkg.tar.xz'
135-
const bogus32BitMSYS2RuntimeURL = 'https://wingit.blob.core.windows.net/i686/msys2-runtime-3.4.9-1-i686.pkg.tar.xz'
136-
const bogus64BitMSYS2RuntimeURL = 'https://wingit.blob.core.windows.net/x86-64/msys2-runtime-3.3-3.3.7-1-x86_64.pkg.tar.xz'
137-
const mockDoesURLReturn404 = jest.fn(url => [
138-
missingURL, missingMinTTYURL, bogus32BitMSYS2RuntimeURL, bogus64BitMSYS2RuntimeURL
139-
].includes(url))
140-
jest.mock('../GitForWindowsHelper/https-request', () => {
141-
return { doesURLReturn404: mockDoesURLReturn404 }
171+
expect(await guessReleaseNotes(context, {
172+
labels: [{ name: 'component-update' }],
173+
title: '[New cygwin version] cygwin-3.4.9',
174+
body: `\nCygwin 3.4.9 release\n\nhttps://github.com/cygwin/cygwin/releases/tag/cygwin-3.4.9`
175+
})).toEqual({
176+
type: 'feature',
177+
message: 'Comes with the MSYS2 runtime (Git for Windows flavor) based on [Cygwin v3.4.9](https://cygwin.com/pipermail/cygwin-announce/2023-September/011291.html).',
178+
package: 'msys2-runtime',
179+
version: '3.4.9'
142180
})
143181

182+
expect(await guessReleaseNotes(context, {
183+
labels: [{ name: 'component-update' }],
184+
title: '[New cygwin version] cygwin-3.4.7',
185+
body: `\nCygwin 3.4.7 release\n\nhttps://github.com/cygwin/cygwin/releases/tag/cygwin-3.4.7`
186+
})).toEqual({
187+
type: 'feature',
188+
message: 'Comes with the MSYS2 runtime (Git for Windows flavor) based on [Cygwin v3.4.7](https://inbox.sourceware.org/cygwin-announce/20230616162552.879387-1-corinna-cygwin@cygwin.com/).',
189+
package: 'msys2-runtime',
190+
version: '3.4.7'
191+
})
192+
})
193+
194+
test('getMissingDeployments()', async () => {
144195
expect(await getMissingDeployments('curl', '8.1.2')).toEqual([missingURL])
145196
expect(await getMissingDeployments('mintty', '3.6.5')).toEqual([missingMinTTYURL])
146197
expect(await getMissingDeployments('msys2-runtime', '3.4.9')).toEqual([])

0 commit comments

Comments
 (0)