Skip to content

Commit

Permalink
add script that gets the list of PRs since last release
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Apr 10, 2024
1 parent 08ba053 commit c8104e6
Show file tree
Hide file tree
Showing 12 changed files with 2,185 additions and 0 deletions.
96 changes: 96 additions & 0 deletions package-lock.json

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

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"node-fetch": "^3.3.2"
}
}
1 change: 1 addition & 0 deletions tools/release-scripts/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
7 changes: 7 additions & 0 deletions tools/release-scripts/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"printWidth": 120,
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
3 changes: 3 additions & 0 deletions tools/release-scripts/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
19 changes: 19 additions & 0 deletions tools/release-scripts/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run Test (current file)",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"${relativeFile}"
],
"cwd": "${workspaceRoot}",
"console": "integratedTerminal"
}
]
}
5 changes: 5 additions & 0 deletions tools/release-scripts/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.tabSize": 2
}
8 changes: 8 additions & 0 deletions tools/release-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Integration Test

## Resources

1. Integration tests are located at ./test to support the integration-test.yml GitHub Action.
1. The test configuration is located at [./test/testConfig.js](./test/testConfig.js). The test cases to be run are documented there.
1. The classes used in the integration tests are located at ./lib. Tests for those tooling classes are located at ./test/lib. Run `npm test` to test the tooling classes.
1. Sample API test calls to the production deployment can be found at ./api-test. The [Insomnia collection](./api-test/clearlydefined_prod_api_test_insomnia_collection.json) is organized by endpoints (definitions, harvest, and notices). Refer to the [Swagger UI](https://api.clearlydefined.io/api-docs/#/) for detailed documentation. The `Ping/health check` can be used as the first check to see if the service is up and running.
25 changes: 25 additions & 0 deletions tools/release-scripts/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const js = require('@eslint/js')
const globals = require('globals')
const eslintConfigPrettier = require('eslint-config-prettier')

module.exports = [
js.configs.recommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.mocha
},
parserOptions: {
sourceType: 'module'
}
},
rules: {
'no-console': 'off'
}
},
eslintConfigPrettier
]
69 changes: 69 additions & 0 deletions tools/release-scripts/lib/getPRs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// (c) Copyright ClearlyDefined. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

// Prerequisites:
// 1. Install node-fetch package by running `npm install node-fetch`

// Usage:
// node getPRs.mjs <repository> <tag1> <tag2> <gh-pat-token>

import fetch from 'node-fetch';

const owner = 'clearlydefined';
const repo = process.argv[2]; // Pass the repository name as an argument
const tag1 = process.argv[3]; // Pass the first tag as an argument
const tag2 = process.argv[4]; // Pass the second tag as an argument
const token = process.argv[5]; // Pass the GitHub token as an argument

async function getPRs(owner, repo, token) {
const url = `https://api.github.com/repos/${owner}/${repo}/pulls?state=closed`;
const headers = {
'Authorization': `token ${token}`,
'User-Agent': 'GitHub-Pull-Request-Info'
};

const response = await fetch(url, { headers });
const data = await response.json();

return data;
}

async function getTagComparison(owner, repo, tag1, tag2, token) {
const url = `https://api.github.com/repos/${owner}/${repo}/compare/${tag1}...${tag2}`;
const headers = {
'Authorization': `token ${token}`,
'User-Agent': 'GitHub-Pull-Request-Info'
};

const response = await fetch(url, { headers });
const data = await response.json();

const shas = data.commits.map(commit => commit.sha);
console.log("count shas: " + shas.length)
const basesha = data.base_commit.sha;
console.log("basesha: " + basesha)
if (!(basesha === null || typeof basesha === 'undefined')) {
shas.push(basesha);
}
console.log("count shas: " + shas.length)

return shas;
}

async function getPRDetails() {
const prs = await getPRs(owner, repo, token);
const comparison = await getTagComparison(owner, repo, tag1, tag2, token);

const mergedPRs = prs.filter(pr => pr.merged_at && comparison.includes(pr.merge_commit_sha));

const prDetails = mergedPRs.map(pr => {
const prNumber = pr.number;
const prTitle = pr.title;
const contributors = pr.user.login;
return `- ${prTitle} (#${prNumber}) (@${contributors})`;
});

console.log(prDetails.join('\n'));
}

getPRDetails();
Loading

0 comments on commit c8104e6

Please sign in to comment.