diff --git a/tools/user/mergeq/.gitignore b/tools/user/mergeq/.gitignore new file mode 100644 index 00000000000..e120fec43e8 --- /dev/null +++ b/tools/user/mergeq/.gitignore @@ -0,0 +1,2 @@ +.envrc +node_modules diff --git a/tools/user/mergeq/README.md b/tools/user/mergeq/README.md new file mode 100644 index 00000000000..b8b33f7c8e6 --- /dev/null +++ b/tools/user/mergeq/README.md @@ -0,0 +1,15 @@ +# Mergeq + +Utility which reads the docs github repo and finds any PRs which have been merged but not yet published in production release. It then generates a list of PRs with their titles, to assist generating the PR for a production release. + +## Usage + +From the docs root: + +```bash +$ tools/user/mergeq/mergeq.js +``` + +This will output a list of PRs which have been merged but not yet published in a production release. + + diff --git a/tools/user/mergeq/mergeq.js b/tools/user/mergeq/mergeq.js new file mode 100755 index 00000000000..619bb92ab72 --- /dev/null +++ b/tools/user/mergeq/mergeq.js @@ -0,0 +1,62 @@ +#! /usr/bin/env node +import fetch from "node-fetch"; + +// Replace with your details +const owner = "enterprisedb"; +const repo = "docs"; +const token = ""; /*process.env.GITHUB_TOKEN*/ // Optional - if we ever need to make authenticated requests + +async function getLatestReleaseDate(owner, repo, token) { + const url = `https://api.github.com/repos/${owner}/${repo}/releases/latest`; + const headers = token ? { Authorization: `token ${token}` } : {}; + const response = await fetch(url, { headers }); + if (!response.ok) { + throw new Error(`Error fetching latest release: ${response.statusText}`); + } + const data = await response.json(); + return new Date(data.published_at); +} + +async function getMergedPullRequestsSince(owner, repo, sinceDate, token) { + const url = `https://api.github.com/repos/${owner}/${repo}/pulls`; + const headers = token ? { Authorization: `token ${token}` } : {}; + const params = new URLSearchParams({ + state: "closed", + base: "develop", + sort: "updated", + direction: "desc", + }); + const response = await fetch(`${url}?${params.toString()}`, { headers }); + if (!response.ok) { + throw new Error(`Error fetching pull requests: ${response.statusText}`); + } + const pulls = await response.json(); + const mergedPulls = pulls.filter( + (pr) => pr.merged_at && new Date(pr.merged_at) > sinceDate, + ); + var finalpulls = mergedPulls.map((pr) => `#${pr.number} : ${pr.title}`); + return finalpulls; +} + +async function main() { + try { + const latestReleaseDate = await getLatestReleaseDate(owner, repo, token); + const pulls = await getMergedPullRequestsSince( + owner, + repo, + latestReleaseDate, + token, + ); + for (const pull of pulls) { + console.log(pull); + } + console.log(); + console.log( + `Number of merged pull requests since the last release: ${pulls.length}`, + ); + } catch (error) { + console.error("Error fetching data from GitHub API:", error); + } +} + +main(); diff --git a/tools/user/mergeq/package-lock.json b/tools/user/mergeq/package-lock.json new file mode 100644 index 00000000000..e9870f74b03 --- /dev/null +++ b/tools/user/mergeq/package-lock.json @@ -0,0 +1,100 @@ +{ + "name": "mergeq", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "mergeq", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "node-fetch": "^3.3.2" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "engines": { + "node": ">= 8" + } + } + } +} diff --git a/tools/user/mergeq/package.json b/tools/user/mergeq/package.json new file mode 100644 index 00000000000..b664db45360 --- /dev/null +++ b/tools/user/mergeq/package.json @@ -0,0 +1,15 @@ +{ + "name": "mergeq", + "version": "1.0.0", + "description": "Calculate the backlog of Merged PRs since last production builds", + "main": "mergeq.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "node-fetch": "^3.3.2" + } +}