Skip to content

Commit 4064d75

Browse files
authored
Merge pull request #26 from dscho/add-a-test-suite
Add a test suite
2 parents 00796b9 + 31b1198 commit 4064d75

9 files changed

Lines changed: 8653 additions & 10 deletions

File tree

.eslintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"env": {
33
"node": true,
4-
"es6": true
4+
"es6": true,
5+
"jest/globals": true
56
},
67
"extends": "eslint:recommended",
78
"parserOptions": {
89
"ecmaVersion": 12,
910
"sourceType": "module"
1011
},
12+
"plugins": [
13+
"jest"
14+
],
1115
"rules": {
1216
"indent": ["error", 4],
1317
"no-trailing-spaces": "error"

.github/workflows/pr.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ jobs:
66
check:
77
runs-on: ubuntu-latest
88
steps:
9-
- name: install ESLint
10-
run: npm install -g eslint
119
- uses: actions/checkout@v3
10+
- name: npm install
11+
run: npm install
1212
- name: run ESLint
13-
run: eslint -c .eslintrc.json '**/*.js'
13+
run: npm run lint
14+
- name: run tests
15+
run: npm run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/host.json
22
/local.settings.json
3+
/node_modules

GitForWindowsHelper/component-updates.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const guessComponentUpdateDetails = (title, body) => {
77
if (!package_name || !version) throw new Error(`Could not guess component-update details from title '${title}'`)
88

99
if (['git-lfs'].includes(package_name)) package_name = `mingw-w64-${package_name}`
10-
else if (['gcm-core', 'gcm'].includes(package_name)) package_name = 'mingw-w64-git-credential-manager'
10+
else if (['git-credential-manager', 'gcm-core', 'gcm'].includes(package_name)) package_name = 'mingw-w64-git-credential-manager'
1111
else if (package_name === 'cygwin') package_name = 'msys2-runtime'
1212

1313
version = version
@@ -56,12 +56,12 @@ const guessReleaseNotes = async (context, issue) => {
5656
&&issue.labels.filter(label => label.name === 'component-update').length !== 1) throw new Error(`Cannot determine release note from issue ${issue.number}`)
5757
let { package_name, version } = guessComponentUpdateDetails(issue.title, issue.body)
5858

59-
package_name = prettyPackageName(package_name.replace(/^mingw-w64-/, ''))
60-
6159
const matchURLInIssue = (issue) => {
62-
const match = issue.body.match(package_name.toLowerCase() === 'bash'
63-
? /(?:^|\n)(https:\/\/\S+)/ // for `bash`, use the first URL
64-
: /(?:^|\n)(https:\/\/\S+)$/)
60+
const pattern = {
61+
bash: /(?:^|\n)(https:\/\/\S+)/, // use the first URL
62+
gnutls: /(https:\/\/[^\s)]+)/
63+
}[package_name.toLowerCase()] || /(?:^|\n)(https:\/\/\S+)$/
64+
const match = issue.body.match(pattern)
6565
return match && match[1]
6666
}
6767

@@ -86,6 +86,9 @@ const guessReleaseNotes = async (context, issue) => {
8686

8787
const url = await matchURL()
8888
if (!url) throw new Error(`Could not determine URL from issue ${issue.number}`)
89+
90+
package_name = prettyPackageName(package_name.replace(/^mingw-w64-/, ''))
91+
8992
return {
9093
type: 'feature',
9194
message: `Comes with [${package_name} v${version}](${url}).`
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const {
2+
guessComponentUpdateDetails,
3+
guessReleaseNotes
4+
} = require('../GitForWindowsHelper/component-updates')
5+
6+
const bashTicketBody = `# [New bash version] Bash-5.2 patch 15: fix too-aggressive optimizing forks out of subshell commands
7+
8+
<div type="text"/>
9+
10+
https://git.savannah.gnu.org/cgit/bash.git/commit/?id=ec8113b9861375e4e17b3307372569d429dec814
11+
12+
# [New bash version] Bash-5.2 patch 14: process additional terminating signals when running the EXIT trap after a terminating signal
13+
14+
<div type="text"/>
15+
16+
https://git.savannah.gnu.org/cgit/bash.git/commit/?id=6647917a43dd987c5564cc20d0943213b39e748b
17+
18+
# [New bash version] Bash-5.2 patch 13: fix memory leak referencing a nonexistent associative array element
19+
20+
<div type="text"/>
21+
22+
https://git.savannah.gnu.org/cgit/bash.git/commit/?id=52f2cda1a2156c8532f2f49391470cf2f66a1bd0`
23+
24+
test('guessComponentUpdateDetails()', () => {
25+
const titles = [
26+
['[New cygwin version] cygwin-3.4.4', 'msys2-runtime', '3.4.4'],
27+
['[New libcbor version] v0.10.2', 'libcbor', '0.10.2'],
28+
['[New openssl version] OpenSSL 1.1.1s', 'openssl', '1.1.1s'],
29+
['[New openssh version] V_9_2_P1', 'openssh', '9.2.P1'],
30+
['[New tig version] tig-2.5.8', 'tig', '2.5.8'],
31+
['[New curl version] 7.87.0', 'curl', '7.87.0'],
32+
['[New mintty version] 3.6.3', 'mintty', '3.6.3'],
33+
['[New pcre2 version] PCRE2-10.42', 'pcre2', '10.42'],
34+
['[New git-lfs version] v3.3.0', 'mingw-w64-git-lfs', '3.3.0'],
35+
['[New heimdal version] Heimdal 7.7.1 - Security Fix Release', 'heimdal', '7.7.1'],
36+
['[New gnutls version] GnuTLS 3.8.0', 'gnutls', '3.8.0'],
37+
['[New git-credential-manager version] GCM 2.0.886', 'mingw-w64-git-credential-manager', '2.0.886']
38+
]
39+
for (const [title, package_name, version] of titles) {
40+
expect(guessComponentUpdateDetails(title)).toEqual({ package_name, version })
41+
}
42+
43+
expect(guessComponentUpdateDetails('[New bash version] 3 new items', bashTicketBody)).toEqual({
44+
package_name: 'bash',
45+
version: '5.2.15'
46+
})
47+
})
48+
49+
let mockGithubApiRequest = jest.fn(() => {
50+
return {
51+
}
52+
})
53+
jest.mock('../GitForWindowsHelper/github-api-request', () => {
54+
return mockGithubApiRequest
55+
})
56+
57+
test('guessReleaseNotes()', async () => {
58+
const context = { log: jest.fn() }
59+
expect(await guessReleaseNotes(context, {
60+
labels: [{ name: 'component-update' }],
61+
title: '[New bash version] 3 new items',
62+
body: bashTicketBody
63+
})).toEqual({
64+
type: 'feature',
65+
message: 'Comes with [Bash v5.2.15](https://git.savannah.gnu.org/cgit/bash.git/commit/?id=ec8113b9861375e4e17b3307372569d429dec814).'
66+
})
67+
68+
expect(await guessReleaseNotes(context, {
69+
labels: [{ name: 'component-update' }],
70+
title: '[New gnutls version] GnuTLS 3.8.0',
71+
body: `Released a bug-fix and enhancement release on the 3.8.x branch.[GnuTLS 3.8.0](https://lists.gnupg.org/pipermail/gnutls-help/2023-February/004816.html)
72+
73+
Added the security advisory.[GNUTLS-SA-2020-07-14](security-new.html#GNUTLS-SA-2020-07-14)
74+
75+
http://www.gnutls.org/news.html#2023-02-10`
76+
})).toEqual({
77+
type: 'feature',
78+
message: 'Comes with [GNU TLS v3.8.0](https://lists.gnupg.org/pipermail/gnutls-help/2023-February/004816.html).'
79+
})
80+
})

0 commit comments

Comments
 (0)