Skip to content

Commit

Permalink
first commit for mergeq (#6107)
Browse files Browse the repository at this point in the history
Signed-off-by: Dj Walker-Morgan <[email protected]>
  • Loading branch information
djw-m authored Sep 30, 2024
1 parent e82fd24 commit 9933d26
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/user/mergeq/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.envrc
node_modules
15 changes: 15 additions & 0 deletions tools/user/mergeq/README.md
Original file line number Diff line number Diff line change
@@ -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.


62 changes: 62 additions & 0 deletions tools/user/mergeq/mergeq.js
Original file line number Diff line number Diff line change
@@ -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();
100 changes: 100 additions & 0 deletions tools/user/mergeq/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tools/user/mergeq/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

1 comment on commit 9933d26

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.