From 62cb25293386ce6fd1947bae824d08e08799225d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 19 Sep 2018 14:30:48 +0300 Subject: [PATCH 1/7] Fix website repository name --- scripts/changelog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index e32541f4..01b8aefe 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -151,7 +151,7 @@ ${printList(items.documentation)}` } ${_.isEmpty(items.websiteDocumentation) ? "" : - `On the [website repository](https://github.com/thelounge/thelounge.chat): + `On the [website repository](https://github.com/thelounge/thelounge.github.io): ${printList(items.websiteDocumentation)}` } @@ -654,7 +654,7 @@ async function generateChangelogEntry(targetVersion) { items.milestone = await codeRepo.fetchMilestone(targetVersion); contributors = extractContributors(codeCommitsAndPullRequests); - const websiteRepo = new RepositoryFetcher(client, "thelounge.chat"); + const websiteRepo = new RepositoryFetcher(client, "thelounge.github.io"); items.websiteDocumentation = await websiteRepo.fetchCommitsAndPullRequestsSince("v" + previousVersion); } From d326435fe7f874db6e016edadb17340fef5c04f7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 19 Sep 2018 14:31:25 +0300 Subject: [PATCH 2/7] Split pull request query into chunks Otherwise github api chokes when asking about too many pull requests at once --- scripts/changelog.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 01b8aefe..5e1d8b41 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -340,13 +340,25 @@ class RepositoryFetcher { return data.repository.milestones.nodes.find(({title}) => title === targetVersion); } + async fetchChunkedPullRequests(numbers) { + const chunks = _.chunk(numbers, 100); + let result = {}; + + for (const chunk of chunks) { + const data = await this.fetchPullRequests(chunk); + result = _.merge(result, data); + } + + return result; + } + // Given a list of PR numbers, retrieve information for all those PRs. They // are returned as a hash whose keys are `PR`. // This is a bit wonky (generating a dynamic GraphQL query) but the GitHub API // does not have a way to retrieve multiple PRs given a list of IDs. async fetchPullRequests(numbers) { if (numbers.length === 0) { - return []; + return {}; } const prQuery = `query fetchPullRequests($repositoryName: String!) { @@ -386,7 +398,7 @@ class RepositoryFetcher { const taggedCommit = await this.fetchTaggedCommit(tag); const commits = await this.fetchCommitsSince(taggedCommit); const pullRequestIds = pullRequestNumbersInCommits(commits); - const pullRequests = await this.fetchPullRequests(pullRequestIds); + const pullRequests = await this.fetchChunkedPullRequests(pullRequestIds); return combine(commits, pullRequests); } } From 557d4c4dddfa5bba8008870bb25dcc5a9f89537c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 19 Sep 2018 14:42:37 +0300 Subject: [PATCH 3/7] Use website repo last tag because it can differ --- scripts/changelog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 5e1d8b41..4c5e67c6 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -667,7 +667,8 @@ async function generateChangelogEntry(targetVersion) { contributors = extractContributors(codeCommitsAndPullRequests); const websiteRepo = new RepositoryFetcher(client, "thelounge.github.io"); - items.websiteDocumentation = await websiteRepo.fetchCommitsAndPullRequestsSince("v" + previousVersion); + const previousWebsiteVersion = await websiteRepo.fetchPreviousVersion(targetVersion); + items.websiteDocumentation = await websiteRepo.fetchCommitsAndPullRequestsSince("v" + previousWebsiteVersion); } items.version = targetVersion; From 05482e952bca1d3cd6abb89c17c9aadf33c2a1f5 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 19 Sep 2018 14:46:55 +0300 Subject: [PATCH 4/7] Update package title extraction for renovate bot --- scripts/changelog.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 4c5e67c6..d0f89439 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -497,11 +497,12 @@ ${printList(items)} const dependencies = Object.keys(packageJson.dependencies); const devDependencies = Object.keys(packageJson.devDependencies); +const optionalDependencies = Object.keys(packageJson.optionalDependencies); // Returns the package.json section in which that package exists, or undefined // if that package is not listed there. function whichDependencyType(packageName) { - if (dependencies.includes(packageName)) { + if (dependencies.includes(packageName) || optionalDependencies.includes(packageName)) { return "dependencies"; } else if (devDependencies.includes(packageName)) { return "devDependencies"; @@ -562,8 +563,20 @@ function isFeature({labels}) { // Update `stylelint` to v1.2.3 // Update `express` and `ua-parser-js` to latest versions // Update `express`, `chai`, and `ua-parser-js` to ... +// Update @fortawesome/fontawesome-free-webfonts to the latest version +// Update dependency request to v2.87.0 +// chore(deps): update dependency mini-css-extract-plugin to v0.4.3 +// fix(deps): update dependency web-push to v3.3.3 +// chore(deps): update babel monorepo to v7.1.0 function extractPackages(title) { - return /^Update ([\w-,`. ]+) to /.exec(title)[1] + const extracted = /(?:U|u)pdate(?: dependency)? ([\w-,` ./@]+?) (?:monorepo )?to /.exec(title); + + if (!extracted) { + log.warn(`Failed to extract package from: ${title}`); + return []; + } + + return extracted[1] .replace(/`/g, "") .split(/, and |, | and /); } @@ -572,10 +585,12 @@ function extractPackages(title) { // based on different information that describes them. function parse(entries) { return entries.reduce((result, entry) => { + let deps; + if (isSkipped(entry)) { result.skipped.push(entry); - } else if (isDependency(entry)) { - extractPackages(entry.title).forEach((packageName) => { + } else if (isDependency(entry) && (deps = extractPackages(entry.title))) { + deps.forEach((packageName) => { const dependencyType = whichDependencyType(packageName); if (dependencyType) { From 8e2b64d8b1c2b3eadd7dccdadf012208e6f39dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 10 Dec 2018 01:16:58 -0500 Subject: [PATCH 5/7] Skip all commits for version bumps or changelog entries --- scripts/changelog.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index d0f89439..befe1dac 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -78,7 +78,11 @@ if (!version) { version = semver.inc(packageJson.version, process.argv[2]); } -if (!/^[0-9]+\.[0-9]+\.[0-9]+(-(pre|rc)+\.[0-9]+)?$/.test(version)) { +function isValidVersion(str) { + return (/^[0-9]+\.[0-9]+\.[0-9]+(-(pre|rc)+\.[0-9]+)?$/.test(str)); +} + +if (!isValidVersion(version)) { log.error(`Argument ${colors.bold("version")} is incorrect It must be either:`); log.error(`- A keyword among: ${colors.green("major")}, ${colors.green("minor")}, ${colors.green("patch")}, ${colors.green("prerelease")}, ${colors.green("pre")}`); log.error(`- An explicit version of format ${colors.green("x.y.z")} (stable) or ${colors.green("x.y.z-(pre|rc).n")} (pre-release).`); @@ -526,7 +530,15 @@ function hasAnnotatedComment(comments, expected) { } function isSkipped(entry) { - return hasLabelOrAnnotatedComment(entry, "Meta: Skip Changelog"); + return ( + (entry.messageHeadline && ( + // Version bump commits created by `yarn version` + isValidVersion(entry.messageHeadline) || + // Commit message suggested by this script + entry.messageHeadline.startsWith("Add changelog entry for v") + )) || + hasLabelOrAnnotatedComment(entry, "Meta: Skip Changelog") + ); } // Dependency update PRs are listed in a special, more concise way in the changelog. From f832f8e65b03c2934b6654c084acc1c2955cbfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 10 Dec 2018 01:17:19 -0500 Subject: [PATCH 6/7] Fix a bug in comment meta tag detection --- scripts/changelog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index befe1dac..493e7bb2 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -525,7 +525,7 @@ function hasLabel(labels, expected) { function hasAnnotatedComment(comments, expected) { return comments && comments.nodes.some(({authorAssociation, body}) => ["OWNER", "MEMBER"].includes(authorAssociation) && - body.split("\n").includes(`[${expected}]`) + body.split("\r\n").includes(`[${expected}]`) ); } From 74b7d22a441ce7b484e0209890d9c700250c71b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 10 Dec 2018 01:17:47 -0500 Subject: [PATCH 7/7] Add a couple URLs in changelog output to make it easier to track skipped commits/PRs --- scripts/changelog.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 493e7bb2..7fb705c0 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -580,11 +580,11 @@ function isFeature({labels}) { // chore(deps): update dependency mini-css-extract-plugin to v0.4.3 // fix(deps): update dependency web-push to v3.3.3 // chore(deps): update babel monorepo to v7.1.0 -function extractPackages(title) { +function extractPackages({title, url}) { const extracted = /(?:U|u)pdate(?: dependency)? ([\w-,` ./@]+?) (?:monorepo )?to /.exec(title); if (!extracted) { - log.warn(`Failed to extract package from: ${title}`); + log.warn(`Failed to extract package from: ${title} ${colors.gray(url)}`); return []; } @@ -601,7 +601,7 @@ function parse(entries) { if (isSkipped(entry)) { result.skipped.push(entry); - } else if (isDependency(entry) && (deps = extractPackages(entry.title))) { + } else if (isDependency(entry) && (deps = extractPackages(entry))) { deps.forEach((packageName) => { const dependencyType = whichDependencyType(packageName); @@ -612,7 +612,7 @@ function parse(entries) { result[dependencyType][packageName].push(entry); } else { - log.info(`${colors.bold(packageName)} was updated in ${colors.green("#" + entry.number)} then removed since last release. Skipping.`); + log.info(`${colors.bold(packageName)} was updated in ${colors.green("#" + entry.number)} then removed since last release. Skipping. ${colors.gray(entry.url)}`); } }); } else if (isDocumentation(entry)) {