Skip to content

Commit 414c8e1

Browse files
authored
Merge d305d52 into 6d5b4cc
2 parents 6d5b4cc + d305d52 commit 414c8e1

File tree

9 files changed

+229
-13
lines changed

9 files changed

+229
-13
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": ["@changesets/changelog-github", { "repo": "firebase/firebase-js-sdk"}],
3+
"changelog": ["../repo-scripts/changelog-generator", { "repo": "firebase/firebase-js-sdk"}],
44
"commit": false,
55
"linked": [],
66
"access": "public",

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"lint": "lerna run --scope @firebase/* --scope rxfire lint",
4949
"size-report": "node scripts/report_binary_size.js",
5050
"api-report": "lerna run --scope @firebase/*-exp api-report",
51-
"docgen:exp": "node scripts/exp/docgen.js"
51+
"docgen:exp": "node scripts/exp/docgen.js",
52+
"postinstall": "yarn --cwd repo-scripts/changelog-generator build"
5253
},
5354
"repository": {
5455
"type": "git",
@@ -57,7 +58,8 @@
5758
"workspaces": [
5859
"packages/*",
5960
"packages-exp/*",
60-
"integration/*"
61+
"integration/*",
62+
"repo-scripts/*"
6163
],
6264
"devDependencies": {
6365
"@changesets/changelog-github": "0.2.6",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
}
26+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @firebase/changelog-generator
2+
3+
It works as a plugin for @changesets/cli to generate changelog entries(via running `changeset version`).
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { ChangelogFunctions } from '@changesets/types';
19+
import { getInfo } from '@changesets/get-github-info';
20+
import fetch from 'node-fetch';
21+
22+
const changelogFunctions: ChangelogFunctions = {
23+
getDependencyReleaseLine: async (
24+
changesets,
25+
dependenciesUpdated,
26+
options
27+
) => {
28+
if (!options.repo) {
29+
throw new Error(
30+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
31+
);
32+
}
33+
if (dependenciesUpdated.length === 0) return '';
34+
35+
const changesetLink = `- Updated dependencies [${(
36+
await Promise.all(
37+
changesets.map(async cs => {
38+
if (cs.commit) {
39+
let { links } = await getInfo({
40+
repo: options.repo,
41+
commit: cs.commit
42+
});
43+
return links.commit;
44+
}
45+
})
46+
)
47+
)
48+
.filter(_ => _)
49+
.join(', ')}]:`;
50+
51+
const updatedDepenenciesList = dependenciesUpdated.map(
52+
dependency => ` - ${dependency.name}@${dependency.newVersion}`
53+
);
54+
55+
return [changesetLink, ...updatedDepenenciesList].join('\n');
56+
},
57+
getReleaseLine: async (changeset, type, options) => {
58+
if (!options || !options.repo) {
59+
throw new Error(
60+
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]'
61+
);
62+
}
63+
const [firstLine, ...futureLines] = changeset.summary
64+
.split('\n')
65+
.map(l => l.trimRight());
66+
67+
if (changeset.commit) {
68+
let { pull: pullNumber, links } = await getInfo({
69+
repo: options.repo,
70+
commit: changeset.commit
71+
});
72+
73+
let fixedIssueLink = null;
74+
// If the summary didn't mention any issue, we will look at the PR body to try to generate one automatically
75+
if (!/issues\/[\d+]/i.test(changeset.summary) && pullNumber) {
76+
fixedIssueLink = await getFixedIssueLink(pullNumber, options.repo);
77+
}
78+
79+
return `\n\n- ${links.commit}${
80+
links.pull === null ? '' : ` ${links.pull}`
81+
}${
82+
fixedIssueLink === null ? '' : ` ${fixedIssueLink}`
83+
} - ${firstLine}\n${futureLines.map(l => ` ${l}`).join('\n')}`;
84+
} else {
85+
return `\n\n- ${firstLine}\n${futureLines.map(l => ` ${l}`).join('\n')}`;
86+
}
87+
}
88+
};
89+
90+
const fixedIssueRegex = /(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved) [^\s]*(#|issues\/)([\d]+)/i;
91+
async function getFixedIssueLink(
92+
prNumber: number,
93+
repo: string
94+
): Promise<string> {
95+
const { body }: { body: string } = await fetch(
96+
`https://api.github.com/repos/${repo}/pulls/${prNumber}?access_token=${process.env.GITHUB_TOKEN}`,
97+
{
98+
method: 'GET'
99+
}
100+
).then(data => data.json());
101+
102+
const match = fixedIssueRegex.exec(body);
103+
if (!match) {
104+
return '';
105+
}
106+
const issueNumber = match[3];
107+
return `(fixes [#${issueNumber}](https://github.com/firebase/firebase-js-sdk/issues/${issueNumber}))`;
108+
}
109+
110+
exports.default = changelogFunctions;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@firebase/changelog-generator",
3+
"version": "0.1.0",
4+
"private": true,
5+
"description": "A package for generating changelog",
6+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
7+
"main": "dist/index.js",
8+
"files": [
9+
"dist"
10+
],
11+
"scripts": {
12+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
13+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
14+
"build": "tsc",
15+
"build:dev": "tsc -w",
16+
"test": "yarn type-check",
17+
"prepare": "yarn build"
18+
},
19+
"dependencies": {
20+
"@changesets/types": "3.1.0",
21+
"@changesets/get-github-info": "0.4.3",
22+
"node-fetch": "2.6.0",
23+
"@types/node-fetch": "2.5.7"
24+
},
25+
"license": "Apache-2.0",
26+
"devDependencies": {
27+
"typescript": "3.9.6"
28+
},
29+
"repository": {
30+
"directory": "repo-scripts/changelog-generator",
31+
"type": "git",
32+
"url": "https://github.com/firebase/firebase-js-sdk.git"
33+
},
34+
"bugs": {
35+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
36+
},
37+
"nyc": {
38+
"extension": [
39+
".ts"
40+
],
41+
"reportDir": "./coverage/node"
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"outDir": "dist",
5+
"lib": [
6+
"ESNext"
7+
],
8+
"module": "CommonJS",
9+
"moduleResolution": "node",
10+
"esModuleInterop": true,
11+
"resolveJsonModule": true,
12+
"target": "es5",
13+
"typeRoots": [
14+
"../../node_modules/@types"
15+
]
16+
}
17+
}

scripts/exp/docgen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function generateDocs() {
3838
fs.mkdirSync(tmpDir);
3939
}
4040

41-
// TODO: Throw error if path doesn't exist, once all packages add markdown support.
41+
// TODO: Throw error if path doesn't exist once all packages add markdown support.
4242
const apiJsonDirectories = (
4343
await mapWorkspaceToPackages([
4444
`${projectRoot}/packages/*`,

yarn.lock

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@
11411141
fs-extra "^7.0.1"
11421142
semver "^5.4.1"
11431143

1144-
"@changesets/get-github-info@^0.4.3":
1144+
"@changesets/get-github-info@0.4.3", "@changesets/get-github-info@^0.4.3":
11451145
version "0.4.3"
11461146
resolved "https://registry.npmjs.org/@changesets/get-github-info/-/get-github-info-0.4.3.tgz#ed3c3ca76dcbaf4c98aa950a20fc5438da1a2f2c"
11471147
integrity sha512-hMtNDn4Kp2wDUohYipBIH3qGMxONZ3wEoaGtrflXHCSu57iulBcOSQ1oHRYSCJ9pO87dYQHA2XRUfrZUnqRfKA==
@@ -1219,16 +1219,16 @@
12191219
fs-extra "^7.0.1"
12201220
p-filter "^2.1.0"
12211221

1222+
"@changesets/[email protected]", "@changesets/types@^3.1.0":
1223+
version "3.1.0"
1224+
resolved "https://registry.npmjs.org/@changesets/types/-/types-3.1.0.tgz#68957af45a0be29f0908e20a990ecf382282e1f1"
1225+
integrity sha512-czOfaaxr5aGnNwVRgWr3n2CKoc3iRTfrHM4wUHQ+rBlLKKk9NzGwZ2EPsXkp4CUw4hWHGEOi8hdeIfDTWKrWgg==
1226+
12221227
"@changesets/types@^3.0.0":
12231228
version "3.0.0"
12241229
resolved "https://registry.npmjs.org/@changesets/types/-/types-3.0.0.tgz#3804662aa455c1622282ec3253cf6ddd309eee65"
12251230
integrity sha512-9Mh/JqkX3nkjfu53ESM3UjFmR2meOo4Zw+Tp4vnon0XYtMurk7KjZG5L+J0fD3+Qx0A2FFTZrgydPwiHR4GrXQ==
12261231

1227-
"@changesets/types@^3.1.0":
1228-
version "3.1.0"
1229-
resolved "https://registry.npmjs.org/@changesets/types/-/types-3.1.0.tgz#68957af45a0be29f0908e20a990ecf382282e1f1"
1230-
integrity sha512-czOfaaxr5aGnNwVRgWr3n2CKoc3iRTfrHM4wUHQ+rBlLKKk9NzGwZ2EPsXkp4CUw4hWHGEOi8hdeIfDTWKrWgg==
1231-
12321232
"@changesets/write@^0.1.3":
12331233
version "0.1.3"
12341234
resolved "https://registry.npmjs.org/@changesets/write/-/write-0.1.3.tgz#00ae575af50274773d7493e77fb96838a08ad8ad"
@@ -2620,6 +2620,14 @@
26202620
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz#b17f16cf933597e10d6d78eae3251e692ce8b0ce"
26212621
integrity sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==
26222622

2623+
2624+
version "2.5.7"
2625+
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
2626+
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
2627+
dependencies:
2628+
"@types/node" "*"
2629+
form-data "^3.0.0"
2630+
26232631
"@types/node@*", "@types/node@>= 8":
26242632
version "13.11.0"
26252633
resolved "https://registry.npmjs.org/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
@@ -4858,7 +4866,7 @@ combine-source-map@^0.8.0, combine-source-map@~0.8.0:
48584866
lodash.memoize "~3.0.3"
48594867
source-map "~0.5.3"
48604868

4861-
combined-stream@^1.0.6, combined-stream@~1.0.6:
4869+
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
48624870
version "1.0.8"
48634871
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
48644872
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
@@ -7090,6 +7098,15 @@ form-data@^2.5.0:
70907098
combined-stream "^1.0.6"
70917099
mime-types "^2.1.12"
70927100

7101+
form-data@^3.0.0:
7102+
version "3.0.0"
7103+
resolved "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
7104+
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
7105+
dependencies:
7106+
asynckit "^0.4.0"
7107+
combined-stream "^1.0.8"
7108+
mime-types "^2.1.12"
7109+
70937110
form-data@~2.3.2:
70947111
version "2.3.3"
70957112
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
@@ -14195,7 +14212,6 @@ symbol-observable@^1.1.0:
1419514212

1419614213
"sync-promise@git+https://github.com/brettz9/sync-promise.git#full-sync-missing-promise-features":
1419714214
version "1.0.1"
14198-
uid "25845a49a00aa2d2c985a5149b97c86a1fcdc75a"
1419914215
resolved "git+https://github.com/brettz9/sync-promise.git#25845a49a00aa2d2c985a5149b97c86a1fcdc75a"
1420014216

1420114217
syntax-error@^1.1.1:
@@ -15509,7 +15525,6 @@ websocket-extensions@>=0.1.1:
1550915525

1551015526
"websql@git+https://github.com/brettz9/node-websql.git#configurable-secure2":
1551115527
version "1.0.0"
15512-
uid "5149bc0763376ca757fc32dc74345ada0467bfbb"
1551315528
resolved "git+https://github.com/brettz9/node-websql.git#5149bc0763376ca757fc32dc74345ada0467bfbb"
1551415529
dependencies:
1551515530
argsarray "^0.0.1"

0 commit comments

Comments
 (0)