From 9fe5c600508b5701ceb75dac61f30615a58870f5 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Wed, 9 Aug 2023 21:43:00 +0300
Subject: [PATCH 01/20] devops: Add ci warning for swizzled docusaurus
components
Add new action and workflow that runs on new dependabot PR.
The action checks changes in components of docusaurus-theme-openapi that are swizzled and warns maintainers to review those changes.
For more info see badges/shields#9287
Solves badges/shields#9287
---
.../docusaurus-swizzled-warning/action.yml | 12 +
.../docusaurus-swizzled-warning/helpers.js | 63 +++++
.../docusaurus-swizzled-warning/index.js | 105 ++++++++
.../package-lock.json | 236 ++++++++++++++++++
.../docusaurus-swizzled-warning/package.json | 17 ++
.../workflows/docusaurus-swizzled-warning.yml | 22 ++
6 files changed, 455 insertions(+)
create mode 100644 .github/actions/docusaurus-swizzled-warning/action.yml
create mode 100644 .github/actions/docusaurus-swizzled-warning/helpers.js
create mode 100644 .github/actions/docusaurus-swizzled-warning/index.js
create mode 100644 .github/actions/docusaurus-swizzled-warning/package-lock.json
create mode 100644 .github/actions/docusaurus-swizzled-warning/package.json
create mode 100644 .github/workflows/docusaurus-swizzled-warning.yml
diff --git a/.github/actions/docusaurus-swizzled-warning/action.yml b/.github/actions/docusaurus-swizzled-warning/action.yml
new file mode 100644
index 0000000000000..a08a369338d92
--- /dev/null
+++ b/.github/actions/docusaurus-swizzled-warning/action.yml
@@ -0,0 +1,12 @@
+name: 'Docusaurus swizzled component changes warning'
+description: 'Check for changes in Docusaurus components which are swizzled and prints out a warning'
+branding:
+ icon: 'alert-triangle'
+ color: 'yellow'
+inputs:
+ github-token:
+ description: 'The GITHUB_TOKEN secret'
+ required: true
+runs:
+ using: 'node16'
+ main: 'index.js'
diff --git a/.github/actions/docusaurus-swizzled-warning/helpers.js b/.github/actions/docusaurus-swizzled-warning/helpers.js
new file mode 100644
index 0000000000000..480c38db701b9
--- /dev/null
+++ b/.github/actions/docusaurus-swizzled-warning/helpers.js
@@ -0,0 +1,63 @@
+'use strict'
+
+/**
+ * Returns info about all files changed in a PR (max 3000 results)
+ *
+ * @param {object} client hydrated octokit ready to use for GitHub Actions
+ * @param {string} owner repo owner
+ * @param {string} repo repo name
+ * @param {number} pullNumber pull request number
+ * @returns {object[]} array of object that describe pr changed files - see https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files
+ */
+async function getAllFilesForPullRequest(client, owner, repo, pullNumber) {
+ const perPage = 100 // Max number of items per page
+ let page = 1 // Start with the first page
+ let allFiles = []
+ while (true) {
+ const response = await client.rest.pulls.listFiles({
+ owner,
+ repo,
+ pull_number: pullNumber,
+ per_page: perPage,
+ page,
+ })
+
+ if (response.data.length === 0) {
+ // Break the loop if no more results
+ break
+ }
+
+ allFiles = allFiles.concat(response.data)
+ page++ // Move to the next page
+ }
+ return allFiles
+}
+
+/**
+ * Get a list of files changed betwen two tags for a github repo
+ *
+ * @param {object} client hydrated octokit ready to use for GitHub Actions
+ * @param {string} owner repo owner
+ * @param {string} repo repo name
+ * @param {string} baseTag base tag
+ * @param {string} headTag head tag
+ * @returns {string[]} Array listing all changed files betwen the base tag and the head tag
+ */
+async function getChangedFilesBetweenTags(
+ client,
+ owner,
+ repo,
+ baseTag,
+ headTag,
+) {
+ const response = await client.rest.repos.compareCommits({
+ owner,
+ repo,
+ base: baseTag,
+ head: headTag,
+ })
+
+ return response.data.files.map(file => file.filename)
+}
+
+module.exports = { getAllFilesForPullRequest, getChangedFilesBetweenTags }
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
new file mode 100644
index 0000000000000..4763910d0dda8
--- /dev/null
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -0,0 +1,105 @@
+'use strict'
+
+const core = require('@actions/core')
+const github = require('@actions/github')
+const {
+ getAllFilesForPullRequest,
+ getChangedFilesBetweenTags,
+} = require('./helpers')
+
+async function run() {
+ try {
+ const token = core.getInput('github-token', { required: true })
+
+ const { pull_request: pr } = github.context.payload
+ if (!pr) {
+ throw new Error('Event payload missing `pull_request`')
+ }
+
+ const client = github.getOctokit(token)
+ const packageName = 'docusaurus-preset-openapi'
+ const overideComponents = ['Curl', 'Response']
+ const messageTemplate = `
+ | :large_orange_diamond:This PR contains changes to components of ${packageName} we've overridden |
+ ---------------------------------------------------------------------------------------------------
+ | We need to watch out for changes to the Curl and Response components |
+ `
+
+ if (
+ ['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login)
+ ) {
+ const files = await getAllFilesForPullRequest(
+ client,
+ github.context.repo.owner,
+ github.context.repo.repo,
+ pr.number,
+ )
+
+ for (const file of files) {
+ if (!['package.json', 'package-lock.json'].includes(file.filename)) {
+ continue
+ }
+
+ const patchLines = file.patch.split('\n')
+ const versionRegex = /\d+\.\d+\.\d+/
+
+ let oldVersion
+ let newVersion
+
+ for (let i = 0; i < patchLines.length; i++) {
+ if (
+ ['+', '-'].includes(patchLines[i][0]) &&
+ patchLines[i].includes(packageName)
+ ) {
+ const match = patchLines[i].match(versionRegex)
+ if (patchLines[i][0] === '+') {
+ newVersion = match[0]
+ } else {
+ oldVersion = match[0]
+ }
+ }
+ }
+
+ if (newVersion) {
+ const pkgChangedFiles = await getChangedFilesBetweenTags(
+ client,
+ 'cloud-annotations',
+ 'docusaurus-openapi',
+ `v${newVersion}`,
+ `v${oldVersion}`,
+ )
+ const changedComponents = overideComponents.filter(
+ componenet =>
+ pkgChangedFiles.filter(
+ path =>
+ path.includes('docusaurus-theme-openapi/src/theme') &&
+ path.includes(componenet),
+ ).length > 0,
+ )
+ const versionReport = `| Old version | ${oldVersion} |
+ | New version | ${newVersion} |
+ `
+ const changedComponentsReport = `| Overide components changed | ${changedComponents.join(
+ ', ',
+ )} |
+ `
+ const body = messageTemplate + versionReport + changedComponentsReport
+ await client.rest.issues.createComment({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ issue_number: pr.number,
+ body,
+ })
+ }
+
+ core.debug('Found changes and posted comment, done.')
+ return
+ }
+ core.debug('No changes found, done.')
+ }
+ } catch (error) {
+ core.setFailed(error.message)
+ }
+}
+
+run()
diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json
new file mode 100644
index 0000000000000..5511c01825be6
--- /dev/null
+++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json
@@ -0,0 +1,236 @@
+{
+ "name": "docusaurus-swizzled-warning",
+ "version": "0.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "docusaurus-swizzled-warning",
+ "version": "0.0.0",
+ "license": "CC0",
+ "dependencies": {
+ "@actions/core": "^1.10.0",
+ "@actions/github": "^5.1.1"
+ }
+ },
+ "node_modules/@actions/core": {
+ "version": "1.10.0",
+ "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
+ "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
+ "dependencies": {
+ "@actions/http-client": "^2.0.1",
+ "uuid": "^8.3.2"
+ }
+ },
+ "node_modules/@actions/github": {
+ "version": "5.1.1",
+ "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.1.tgz",
+ "integrity": "sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==",
+ "dependencies": {
+ "@actions/http-client": "^2.0.1",
+ "@octokit/core": "^3.6.0",
+ "@octokit/plugin-paginate-rest": "^2.17.0",
+ "@octokit/plugin-rest-endpoint-methods": "^5.13.0"
+ }
+ },
+ "node_modules/@actions/http-client": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.1.tgz",
+ "integrity": "sha512-qhrkRMB40bbbLo7gF+0vu+X+UawOvQQqNAA/5Unx774RS8poaOhThDOG6BGmxvAnxhQnDp2BG/ZUm65xZILTpw==",
+ "dependencies": {
+ "tunnel": "^0.0.6"
+ }
+ },
+ "node_modules/@octokit/auth-token": {
+ "version": "2.5.0",
+ "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz",
+ "integrity": "sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==",
+ "dependencies": {
+ "@octokit/types": "^6.0.3"
+ }
+ },
+ "node_modules/@octokit/core": {
+ "version": "3.6.0",
+ "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz",
+ "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==",
+ "dependencies": {
+ "@octokit/auth-token": "^2.4.4",
+ "@octokit/graphql": "^4.5.8",
+ "@octokit/request": "^5.6.3",
+ "@octokit/request-error": "^2.0.5",
+ "@octokit/types": "^6.0.3",
+ "before-after-hook": "^2.2.0",
+ "universal-user-agent": "^6.0.0"
+ }
+ },
+ "node_modules/@octokit/endpoint": {
+ "version": "6.0.12",
+ "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz",
+ "integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==",
+ "dependencies": {
+ "@octokit/types": "^6.0.3",
+ "is-plain-object": "^5.0.0",
+ "universal-user-agent": "^6.0.0"
+ }
+ },
+ "node_modules/@octokit/graphql": {
+ "version": "4.8.0",
+ "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz",
+ "integrity": "sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==",
+ "dependencies": {
+ "@octokit/request": "^5.6.0",
+ "@octokit/types": "^6.0.3",
+ "universal-user-agent": "^6.0.0"
+ }
+ },
+ "node_modules/@octokit/openapi-types": {
+ "version": "12.11.0",
+ "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz",
+ "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ=="
+ },
+ "node_modules/@octokit/plugin-paginate-rest": {
+ "version": "2.21.3",
+ "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz",
+ "integrity": "sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==",
+ "dependencies": {
+ "@octokit/types": "^6.40.0"
+ },
+ "peerDependencies": {
+ "@octokit/core": ">=2"
+ }
+ },
+ "node_modules/@octokit/plugin-rest-endpoint-methods": {
+ "version": "5.16.2",
+ "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz",
+ "integrity": "sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==",
+ "dependencies": {
+ "@octokit/types": "^6.39.0",
+ "deprecation": "^2.3.1"
+ },
+ "peerDependencies": {
+ "@octokit/core": ">=3"
+ }
+ },
+ "node_modules/@octokit/request": {
+ "version": "5.6.3",
+ "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz",
+ "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==",
+ "dependencies": {
+ "@octokit/endpoint": "^6.0.1",
+ "@octokit/request-error": "^2.1.0",
+ "@octokit/types": "^6.16.1",
+ "is-plain-object": "^5.0.0",
+ "node-fetch": "^2.6.7",
+ "universal-user-agent": "^6.0.0"
+ }
+ },
+ "node_modules/@octokit/request-error": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz",
+ "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==",
+ "dependencies": {
+ "@octokit/types": "^6.0.3",
+ "deprecation": "^2.0.0",
+ "once": "^1.4.0"
+ }
+ },
+ "node_modules/@octokit/types": {
+ "version": "6.41.0",
+ "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz",
+ "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==",
+ "dependencies": {
+ "@octokit/openapi-types": "^12.11.0"
+ }
+ },
+ "node_modules/before-after-hook": {
+ "version": "2.2.3",
+ "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz",
+ "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ=="
+ },
+ "node_modules/deprecation": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",
+ "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ=="
+ },
+ "node_modules/is-plain-object": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
+ "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/node-fetch": {
+ "version": "2.6.12",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
+ "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/once": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
+ "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
+ "dependencies": {
+ "wrappy": "1"
+ }
+ },
+ "node_modules/tr46": {
+ "version": "0.0.3",
+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
+ },
+ "node_modules/tunnel": {
+ "version": "0.0.6",
+ "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
+ "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
+ "engines": {
+ "node": ">=0.6.11 <=0.7.0 || >=0.7.3"
+ }
+ },
+ "node_modules/universal-user-agent": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz",
+ "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w=="
+ },
+ "node_modules/uuid": {
+ "version": "8.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
+ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
+ "bin": {
+ "uuid": "dist/bin/uuid"
+ }
+ },
+ "node_modules/webidl-conversions": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
+ },
+ "node_modules/whatwg-url": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
+ "dependencies": {
+ "tr46": "~0.0.3",
+ "webidl-conversions": "^3.0.0"
+ }
+ },
+ "node_modules/wrappy": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
+ }
+ }
+}
diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json
new file mode 100644
index 0000000000000..a6417219cb8da
--- /dev/null
+++ b/.github/actions/docusaurus-swizzled-warning/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "docusaurus-swizzled-warning",
+ "version": "0.0.0",
+ "description": "",
+ "main": "index.js",
+ "private": true,
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "jNullj",
+ "license": "CC0",
+ "dependencies": {
+ "@actions/core": "^1.10.0",
+ "@actions/github": "^5.1.1"
+ }
+ }
+
\ No newline at end of file
diff --git a/.github/workflows/docusaurus-swizzled-warning.yml b/.github/workflows/docusaurus-swizzled-warning.yml
new file mode 100644
index 0000000000000..17f779862ae94
--- /dev/null
+++ b/.github/workflows/docusaurus-swizzled-warning.yml
@@ -0,0 +1,22 @@
+name: Docusaurus swizzled component changes warning
+on:
+ pull_request_target:
+ types: [opened]
+
+permissions:
+ pull-requests: write
+
+jobs:
+ docusaurus-swizzled-warning:
+ runs-on: ubuntu-latest
+ if: github.actor == 'dependabot[bot]'
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Install action dependencies
+ run: cd .github/actions/docusaurus-swizzled-warning && npm ci
+
+ - uses: ./.github/actions/docusaurus-swizzled-warning
+ with:
+ github-token: '${{ secrets.GITHUB_TOKEN }}'
From afd5505226097f7570ca08d92fa9ae2cf46ef604 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Thu, 10 Aug 2023 19:28:29 +0300
Subject: [PATCH 02/20] Fix table formating
---
.../docusaurus-swizzled-warning/index.js | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 4763910d0dda8..55a064ecdfb34 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -19,10 +19,12 @@ async function run() {
const client = github.getOctokit(token)
const packageName = 'docusaurus-preset-openapi'
const overideComponents = ['Curl', 'Response']
- const messageTemplate = `
- | :large_orange_diamond:This PR contains changes to components of ${packageName} we've overridden |
- ---------------------------------------------------------------------------------------------------
- | We need to watch out for changes to the Curl and Response components |
+ const messageTemplate = `
+ ⚠️ This PR contains changes to components of ${packageName} we've overridden
+ |
+
+ We need to watch out for changes to the Curl and Response components
+ |
`
if (
@@ -76,12 +78,12 @@ async function run() {
path.includes(componenet),
).length > 0,
)
- const versionReport = `| Old version | ${oldVersion} |
- | New version | ${newVersion} |
+ const versionReport = ` Old version | ${oldVersion} |
+ New version | ${newVersion} |
`
- const changedComponentsReport = `| Overide components changed | ${changedComponents.join(
+ const changedComponentsReport = ` Overide components changed | ${changedComponents.join(
', ',
- )} |
+ )} |
---|
`
const body = messageTemplate + versionReport + changedComponentsReport
await client.rest.issues.createComment({
From 4e158d242a8018100bba7101cda1f1ad27846ff3 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Thu, 10 Aug 2023 19:53:37 +0300
Subject: [PATCH 03/20] Fix order
---
.github/actions/docusaurus-swizzled-warning/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 55a064ecdfb34..12db2b310208b 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -67,8 +67,8 @@ async function run() {
client,
'cloud-annotations',
'docusaurus-openapi',
- `v${newVersion}`,
`v${oldVersion}`,
+ `v${newVersion}`,
)
const changedComponents = overideComponents.filter(
componenet =>
From 82f66ecdce3dc7bbb1770885ccd0d50ca340d722 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Thu, 10 Aug 2023 22:43:29 +0300
Subject: [PATCH 04/20] handle missing patch cases
---
.../docusaurus-swizzled-warning/index.js | 19 +++++++++++++++++++
.../package-lock.json | 8 +++++++-
.../docusaurus-swizzled-warning/package.json | 10 +++++-----
3 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 12db2b310208b..01ec874d3f8f9 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -2,6 +2,7 @@
const core = require('@actions/core')
const github = require('@actions/github')
+const diffParse = require('parse-diff')
const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
@@ -42,6 +43,24 @@ async function run() {
continue
}
+ if (file.patch === undefined) {
+ // patch is not rquired by api response and might not allways return the field
+ // patch can be extracted from pr diff
+ const url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/pull/${pr.number}.diff`
+ const diff = await (await fetch(url)).text()
+ const diffFiles = diffParse(diff)
+ for (const df in diffFiles) {
+ if (df.to !== file.filename) {
+ continue
+ }
+ for (const chunk in df.chunks) {
+ for (const change in chunk.changes) {
+ file.patch += `${change}\n`
+ }
+ }
+ }
+ }
+
const patchLines = file.patch.split('\n')
const versionRegex = /\d+\.\d+\.\d+/
diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json
index 5511c01825be6..ce0d6c11f4341 100644
--- a/.github/actions/docusaurus-swizzled-warning/package-lock.json
+++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json
@@ -10,7 +10,8 @@
"license": "CC0",
"dependencies": {
"@actions/core": "^1.10.0",
- "@actions/github": "^5.1.1"
+ "@actions/github": "^5.1.1",
+ "parse-diff": "^0.11.1"
}
},
"node_modules/@actions/core": {
@@ -187,6 +188,11 @@
"wrappy": "1"
}
},
+ "node_modules/parse-diff": {
+ "version": "0.11.1",
+ "resolved": "https://registry.npmjs.org/parse-diff/-/parse-diff-0.11.1.tgz",
+ "integrity": "sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA=="
+ },
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json
index a6417219cb8da..d119b3fad45a8 100644
--- a/.github/actions/docusaurus-swizzled-warning/package.json
+++ b/.github/actions/docusaurus-swizzled-warning/package.json
@@ -5,13 +5,13 @@
"main": "index.js",
"private": true,
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jNullj",
"license": "CC0",
"dependencies": {
- "@actions/core": "^1.10.0",
- "@actions/github": "^5.1.1"
+ "@actions/core": "^1.10.0",
+ "@actions/github": "^5.1.1",
+ "parse-diff": "^0.11.1"
}
- }
-
\ No newline at end of file
+}
From 438a1e6cc2487c7068c05cefb6942991f69b11a3 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 12:56:56 +0300
Subject: [PATCH 05/20] fix missing fetch in node16
---
.github/actions/docusaurus-swizzled-warning/index.js | 1 +
.github/actions/docusaurus-swizzled-warning/package-lock.json | 1 +
.github/actions/docusaurus-swizzled-warning/package.json | 1 +
3 files changed, 3 insertions(+)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 01ec874d3f8f9..fb34a1eea24b4 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -3,6 +3,7 @@
const core = require('@actions/core')
const github = require('@actions/github')
const diffParse = require('parse-diff')
+const fetch = require('node-fetch')
const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json
index ce0d6c11f4341..b6c300f782fa5 100644
--- a/.github/actions/docusaurus-swizzled-warning/package-lock.json
+++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json
@@ -11,6 +11,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
+ "node-fetch": "^2.6.12",
"parse-diff": "^0.11.1"
}
},
diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json
index d119b3fad45a8..afd44fd6a83c7 100644
--- a/.github/actions/docusaurus-swizzled-warning/package.json
+++ b/.github/actions/docusaurus-swizzled-warning/package.json
@@ -12,6 +12,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
+ "node-fetch": "^2.6.12",
"parse-diff": "^0.11.1"
}
}
From 8677c5298cdd1b5cdbf3fc23ff6a55d841561851 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 13:20:49 +0300
Subject: [PATCH 06/20] fix typo
---
.github/actions/docusaurus-swizzled-warning/index.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index fb34a1eea24b4..944c33fe55745 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -50,12 +50,12 @@ async function run() {
const url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/pull/${pr.number}.diff`
const diff = await (await fetch(url)).text()
const diffFiles = diffParse(diff)
- for (const df in diffFiles) {
+ for (const df of diffFiles) {
if (df.to !== file.filename) {
continue
}
- for (const chunk in df.chunks) {
- for (const change in chunk.changes) {
+ for (const chunk of df.chunks) {
+ for (const change of chunk.changes) {
file.patch += `${change}\n`
}
}
From 6354ba2e182fd9f8cec4e2f6311371e82fdc9775 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 13:24:14 +0300
Subject: [PATCH 07/20] fix typo
---
.github/actions/docusaurus-swizzled-warning/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 944c33fe55745..e85f7ef5a6466 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -56,7 +56,7 @@ async function run() {
}
for (const chunk of df.chunks) {
for (const change of chunk.changes) {
- file.patch += `${change}\n`
+ file.patch += `${change.content}\n`
}
}
}
From d16d9873b1d340b4a7c81181f9823ebc321cb513 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 16:03:10 +0300
Subject: [PATCH 08/20] changed from diff parse to json usage
---
.../docusaurus-swizzled-warning/index.js | 64 ++++++-------------
.../package-lock.json | 8 +--
.../docusaurus-swizzled-warning/package.json | 3 +-
3 files changed, 21 insertions(+), 54 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index e85f7ef5a6466..332f5e13fd27e 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -2,7 +2,6 @@
const core = require('@actions/core')
const github = require('@actions/github')
-const diffParse = require('parse-diff')
const fetch = require('node-fetch')
const {
getAllFilesForPullRequest,
@@ -19,13 +18,15 @@ async function run() {
}
const client = github.getOctokit(token)
- const packageName = 'docusaurus-preset-openapi'
+ const packageName = 'docusaurus-theme-openapi'
const overideComponents = ['Curl', 'Response']
const messageTemplate = `
⚠️ This PR contains changes to components of ${packageName} we've overridden
|
- We need to watch out for changes to the Curl and Response components
+ We need to watch out for changes to the ${overideComponents.join(
+ ', ',
+ )}components
|
`
@@ -40,49 +41,22 @@ async function run() {
)
for (const file of files) {
- if (!['package.json', 'package-lock.json'].includes(file.filename)) {
+ if (file.filename !== 'package-lock.json') {
continue
}
- if (file.patch === undefined) {
- // patch is not rquired by api response and might not allways return the field
- // patch can be extracted from pr diff
- const url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/pull/${pr.number}.diff`
- const diff = await (await fetch(url)).text()
- const diffFiles = diffParse(diff)
- for (const df of diffFiles) {
- if (df.to !== file.filename) {
- continue
- }
- for (const chunk of df.chunks) {
- for (const change of chunk.changes) {
- file.patch += `${change.content}\n`
- }
- }
- }
- }
-
- const patchLines = file.patch.split('\n')
- const versionRegex = /\d+\.\d+\.\d+/
-
- let oldVersion
- let newVersion
-
- for (let i = 0; i < patchLines.length; i++) {
- if (
- ['+', '-'].includes(patchLines[i][0]) &&
- patchLines[i].includes(packageName)
- ) {
- const match = patchLines[i].match(versionRegex)
- if (patchLines[i][0] === '+') {
- newVersion = match[0]
- } else {
- oldVersion = match[0]
- }
- }
- }
+ const pkgLockNewJson = await (await fetch(file.raw_url)).json()
+ const pkgLockOldJson = await (
+ await fetch(
+ `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/master/${file.filename}`,
+ )
+ ).json()
+ const oldVersion =
+ pkgLockOldJson.packages[`node_modules/${packageName}`].version
+ const newVersion =
+ pkgLockNewJson.packages[`node_modules/${packageName}`].version
- if (newVersion) {
+ if (newVersion !== oldVersion) {
const pkgChangedFiles = await getChangedFilesBetweenTags(
client,
'cloud-annotations',
@@ -112,10 +86,10 @@ async function run() {
issue_number: pr.number,
body,
})
- }
- core.debug('Found changes and posted comment, done.')
- return
+ core.debug('Found changes and posted comment, done.')
+ return
+ }
}
core.debug('No changes found, done.')
}
diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json
index b6c300f782fa5..21ba9a338d902 100644
--- a/.github/actions/docusaurus-swizzled-warning/package-lock.json
+++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json
@@ -11,8 +11,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
- "node-fetch": "^2.6.12",
- "parse-diff": "^0.11.1"
+ "node-fetch": "^2.6.12"
}
},
"node_modules/@actions/core": {
@@ -189,11 +188,6 @@
"wrappy": "1"
}
},
- "node_modules/parse-diff": {
- "version": "0.11.1",
- "resolved": "https://registry.npmjs.org/parse-diff/-/parse-diff-0.11.1.tgz",
- "integrity": "sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA=="
- },
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json
index afd44fd6a83c7..e201afddfeb68 100644
--- a/.github/actions/docusaurus-swizzled-warning/package.json
+++ b/.github/actions/docusaurus-swizzled-warning/package.json
@@ -12,7 +12,6 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
- "node-fetch": "^2.6.12",
- "parse-diff": "^0.11.1"
+ "node-fetch": "^2.6.12"
}
}
From 7f9f94e4794afa981d04db94480b115e2f1f5169 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 16:27:20 +0300
Subject: [PATCH 09/20] fix keys issues
---
.../docusaurus-swizzled-warning/helpers.js | 14 +++++++++++++-
.../actions/docusaurus-swizzled-warning/index.js | 15 +++++++++++----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/helpers.js b/.github/actions/docusaurus-swizzled-warning/helpers.js
index 480c38db701b9..3fe2229e84684 100644
--- a/.github/actions/docusaurus-swizzled-warning/helpers.js
+++ b/.github/actions/docusaurus-swizzled-warning/helpers.js
@@ -60,4 +60,16 @@ async function getChangedFilesBetweenTags(
return response.data.files.map(file => file.filename)
}
-module.exports = { getAllFilesForPullRequest, getChangedFilesBetweenTags }
+function findKeyEndingWith(obj, ending) {
+ for (const key in obj) {
+ if (key.endsWith(ending)) {
+ return key
+ }
+ }
+}
+
+module.exports = {
+ getAllFilesForPullRequest,
+ getChangedFilesBetweenTags,
+ findKeyEndingWith,
+}
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 332f5e13fd27e..17c324fecb824 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -6,6 +6,7 @@ const fetch = require('node-fetch')
const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
+ findKeyEndingWith,
} = require('./helpers')
async function run() {
@@ -51,10 +52,16 @@ async function run() {
`https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/master/${file.filename}`,
)
).json()
- const oldVersion =
- pkgLockOldJson.packages[`node_modules/${packageName}`].version
- const newVersion =
- pkgLockNewJson.packages[`node_modules/${packageName}`].version
+ const oldVesionModuleKey = findKeyEndingWith(
+ pkgLockOldJson.packages,
+ `node_modules/${packageName}`,
+ )
+ const newVesionModuleKey = findKeyEndingWith(
+ pkgLockNewJson.packages,
+ `node_modules/${packageName}`,
+ )
+ const oldVersion = pkgLockOldJson.packages[oldVesionModuleKey].version
+ const newVersion = pkgLockNewJson.packages[newVesionModuleKey].version
if (newVersion !== oldVersion) {
const pkgChangedFiles = await getChangedFilesBetweenTags(
From 2a0573a779071a2c9cfa4e9c8a18c989296b8a89 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 11 Aug 2023 17:30:52 +0300
Subject: [PATCH 10/20] fix parent dependency version check
---
.../docusaurus-swizzled-warning/index.js | 31 +++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 17c324fecb824..ace2c9e9c36de 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -20,6 +20,7 @@ async function run() {
const client = github.getOctokit(token)
const packageName = 'docusaurus-theme-openapi'
+ const packageParentName = 'docusaurus-preset-openapi'
const overideComponents = ['Curl', 'Response']
const messageTemplate = `
⚠️ This PR contains changes to components of ${packageName} we've overridden
@@ -60,8 +61,34 @@ async function run() {
pkgLockNewJson.packages,
`node_modules/${packageName}`,
)
- const oldVersion = pkgLockOldJson.packages[oldVesionModuleKey].version
- const newVersion = pkgLockNewJson.packages[newVesionModuleKey].version
+ let oldVersion = pkgLockOldJson.packages[oldVesionModuleKey].version
+ let newVersion = pkgLockNewJson.packages[newVesionModuleKey].version
+
+ const oldVesionModuleKeyParent = findKeyEndingWith(
+ pkgLockOldJson.packages,
+ `node_modules/${packageParentName}`,
+ )
+ const newVesionModuleKeyParent = findKeyEndingWith(
+ pkgLockNewJson.packages,
+ `node_modules/${packageParentName}`,
+ )
+ const oldVersionParent =
+ pkgLockOldJson.packages[oldVesionModuleKeyParent].dependencies[
+ packageName
+ ].substring(1)
+ const newVersionParent =
+ pkgLockNewJson.packages[newVesionModuleKeyParent].dependencies[
+ packageName
+ ].substring(1)
+
+ // if parent dependency is higher version then existing
+ // npm install will retrive the newer version from the parent dependency
+ if (oldVersionParent > oldVersion) {
+ oldVersion = oldVersionParent
+ }
+ if (newVersionParent > newVersion) {
+ newVersion = newVersionParent
+ }
if (newVersion !== oldVersion) {
const pkgChangedFiles = await getChangedFilesBetweenTags(
From 372d18ff133067fdd002873c851dbdecf9889fa1 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 15:35:53 +0300
Subject: [PATCH 11/20] Apply suggestions from code review - Improve
description and text format
Co-authored-by: chris48s
---
.github/actions/docusaurus-swizzled-warning/action.yml | 4 ++--
.github/actions/docusaurus-swizzled-warning/index.js | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/action.yml b/.github/actions/docusaurus-swizzled-warning/action.yml
index a08a369338d92..f02fcc942c673 100644
--- a/.github/actions/docusaurus-swizzled-warning/action.yml
+++ b/.github/actions/docusaurus-swizzled-warning/action.yml
@@ -1,5 +1,5 @@
-name: 'Docusaurus swizzled component changes warning'
-description: 'Check for changes in Docusaurus components which are swizzled and prints out a warning'
+name: 'docusaurus-theme-openapi swizzled component changes warning'
+description: 'Check for changes in docusaurus-theme-openapi components which are swizzled and prints out a warning'
branding:
icon: 'alert-triangle'
color: 'yellow'
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index ace2c9e9c36de..cb292e9a55679 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -28,7 +28,7 @@ async function run() {
We need to watch out for changes to the ${overideComponents.join(
', ',
- )}components
+ )} components
|
`
From c4a41f65dd0c482f494c6f9fd598d4c2d5494248 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 15:51:18 +0300
Subject: [PATCH 12/20] Fix comment table format
---
.../actions/docusaurus-swizzled-warning/index.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index cb292e9a55679..1f393e904c068 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -22,14 +22,14 @@ async function run() {
const packageName = 'docusaurus-theme-openapi'
const packageParentName = 'docusaurus-preset-openapi'
const overideComponents = ['Curl', 'Response']
- const messageTemplate = `
+ const messageTemplate = `
⚠️ This PR contains changes to components of ${packageName} we've overridden
-
-
+ |
+
We need to watch out for changes to the ${overideComponents.join(
', ',
)} components
- |
+
`
if (
@@ -106,12 +106,12 @@ async function run() {
path.includes(componenet),
).length > 0,
)
- const versionReport = ` Old version | ${oldVersion} |
- New version | ${newVersion} |
+ const versionReport = ` Old version | ${oldVersion} |
+ New version | ${newVersion} |
`
- const changedComponentsReport = ` Overide components changed | ${changedComponents.join(
+ const changedComponentsReport = ` |
---|
Overide components changed | ${changedComponents.join(
', ',
- )} |
+ )} |
---|
`
const body = messageTemplate + versionReport + changedComponentsReport
await client.rest.issues.createComment({
From da3cf2e4d70469c51a817e06d461369a5849cafb Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 16:09:41 +0300
Subject: [PATCH 13/20] fix type
---
.github/actions/docusaurus-swizzled-warning/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 1f393e904c068..91ae51cd3c7db 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -22,7 +22,7 @@ async function run() {
const packageName = 'docusaurus-theme-openapi'
const packageParentName = 'docusaurus-preset-openapi'
const overideComponents = ['Curl', 'Response']
- const messageTemplate = `
+ const messageTemplate = `
⚠️ This PR contains changes to components of ${packageName} we've overridden
|
From c77af690195f3e2eb05ee04c828d1de204e6319b Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 16:14:50 +0300
Subject: [PATCH 14/20] Add docusaurus-swizzled-warning to dependabot
---
.github/dependabot.yml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index f58f90be40e1c..246bbe87d7a14 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -34,3 +34,13 @@ updates:
interval: weekly
open-pull-requests-limit: 99
rebase-strategy: disabled
+
+ # docusaurus-swizzled-warning package dependencies
+ - package-ecosystem: npm
+ directory: '/.github/actions/docusaurus-swizzled-warning'
+ schedule:
+ interval: weekly
+ day: friday
+ time: '12:00'
+ open-pull-requests-limit: 99
+ rebase-strategy: disabled
From db2e03c72368ba629098e9cb1474566b8dfd15ed Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 17:55:29 +0300
Subject: [PATCH 15/20] refactor: remove node-fetch and use octokit insted
---
.../docusaurus-swizzled-warning/index.js | 44 ++++++++++++++++---
.../package-lock.json | 3 +-
.../docusaurus-swizzled-warning/package.json | 3 +-
3 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 91ae51cd3c7db..43e09ce987db4 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -2,7 +2,6 @@
const core = require('@actions/core')
const github = require('@actions/github')
-const fetch = require('node-fetch')
const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
@@ -47,12 +46,43 @@ async function run() {
continue
}
- const pkgLockNewJson = await (await fetch(file.raw_url)).json()
- const pkgLockOldJson = await (
- await fetch(
- `https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/master/${file.filename}`,
- )
- ).json()
+ const pkgLockNewSha = (
+ await client.rest.repos.getContent({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ path: file.filename,
+ ref: file.contents_url.split('ref=')[1],
+ })
+ ).data.sha
+ const pkgLockNewBlob = (
+ await client.rest.git.getBlob({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ file_sha: pkgLockNewSha,
+ })
+ ).data.content
+ const pkgLockNewJson = JSON.parse(
+ Buffer.from(pkgLockNewBlob, 'base64').toString(),
+ )
+ const pkgLockOldSha = (
+ await client.rest.repos.getContent({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ path: file.filename,
+ ref: 'master',
+ })
+ ).data.sha
+ const pkgLockOldBlob = (
+ await client.rest.git.getBlob({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ file_sha: pkgLockOldSha,
+ })
+ ).data.content
+ const pkgLockOldJson = JSON.parse(
+ Buffer.from(pkgLockOldBlob, 'base64').toString(),
+ )
+
const oldVesionModuleKey = findKeyEndingWith(
pkgLockOldJson.packages,
`node_modules/${packageName}`,
diff --git a/.github/actions/docusaurus-swizzled-warning/package-lock.json b/.github/actions/docusaurus-swizzled-warning/package-lock.json
index 21ba9a338d902..5511c01825be6 100644
--- a/.github/actions/docusaurus-swizzled-warning/package-lock.json
+++ b/.github/actions/docusaurus-swizzled-warning/package-lock.json
@@ -10,8 +10,7 @@
"license": "CC0",
"dependencies": {
"@actions/core": "^1.10.0",
- "@actions/github": "^5.1.1",
- "node-fetch": "^2.6.12"
+ "@actions/github": "^5.1.1"
}
},
"node_modules/@actions/core": {
diff --git a/.github/actions/docusaurus-swizzled-warning/package.json b/.github/actions/docusaurus-swizzled-warning/package.json
index e201afddfeb68..7fdf1a43a163f 100644
--- a/.github/actions/docusaurus-swizzled-warning/package.json
+++ b/.github/actions/docusaurus-swizzled-warning/package.json
@@ -11,7 +11,6 @@
"license": "CC0",
"dependencies": {
"@actions/core": "^1.10.0",
- "@actions/github": "^5.1.1",
- "node-fetch": "^2.6.12"
+ "@actions/github": "^5.1.1"
}
}
From 81f020f69639a63f0c1a4a03b31c4add3b2db0a6 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 19:58:14 +0300
Subject: [PATCH 16/20] improve code readability
---
.../docusaurus-swizzled-warning/helpers.js | 30 +++
.../docusaurus-swizzled-warning/index.js | 213 ++++++++----------
2 files changed, 127 insertions(+), 116 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/helpers.js b/.github/actions/docusaurus-swizzled-warning/helpers.js
index 3fe2229e84684..038d8412809f1 100644
--- a/.github/actions/docusaurus-swizzled-warning/helpers.js
+++ b/.github/actions/docusaurus-swizzled-warning/helpers.js
@@ -68,8 +68,38 @@ function findKeyEndingWith(obj, ending) {
}
}
+/**
+ * Get large (>1MB) JSON file from git repo on at ref as a json object
+ *
+ * @param {object} client Hydrated octokit ready to use for GitHub Actions
+ * @param {string} owner Repo owner
+ * @param {string} repo Repo name
+ * @param {string} path Path of the file in repo relative to root directory
+ * @param {string} ref Git refrence (commit, branch, tag)
+ * @returns {string[]} Array listing all changed files betwen the base tag and the head tag
+ */
+async function getLargeJsonAtRef(client, owner, repo, path, ref) {
+ const fileSha = (
+ await client.rest.repos.getContent({
+ owner,
+ repo,
+ path,
+ ref,
+ })
+ ).data.sha
+ const fileBlob = (
+ await client.rest.git.getBlob({
+ owner,
+ repo,
+ file_sha: fileSha,
+ })
+ ).data.content
+ return JSON.parse(Buffer.from(fileBlob, 'base64').toString())
+}
+
module.exports = {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
findKeyEndingWith,
+ getLargeJsonAtRef,
}
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 43e09ce987db4..7becab34869ed 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -6,6 +6,7 @@ const {
getAllFilesForPullRequest,
getChangedFilesBetweenTags,
findKeyEndingWith,
+ getLargeJsonAtRef,
} = require('./helpers')
async function run() {
@@ -32,131 +33,111 @@ async function run() {
`
if (
- ['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login)
+ !['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login)
) {
- const files = await getAllFilesForPullRequest(
- client,
- github.context.repo.owner,
- github.context.repo.repo,
- pr.number,
- )
+ return
+ }
+ const files = await getAllFilesForPullRequest(
+ client,
+ github.context.repo.owner,
+ github.context.repo.repo,
+ pr.number,
+ )
- for (const file of files) {
- if (file.filename !== 'package-lock.json') {
- continue
- }
+ const file = files.filter(f => f.filename !== 'package-lock.json')[0]
+ if (file === undefined) {
+ return
+ }
- const pkgLockNewSha = (
- await client.rest.repos.getContent({
- owner: github.context.repo.owner,
- repo: github.context.repo.repo,
- path: file.filename,
- ref: file.contents_url.split('ref=')[1],
- })
- ).data.sha
- const pkgLockNewBlob = (
- await client.rest.git.getBlob({
- owner: github.context.repo.owner,
- repo: github.context.repo.repo,
- file_sha: pkgLockNewSha,
- })
- ).data.content
- const pkgLockNewJson = JSON.parse(
- Buffer.from(pkgLockNewBlob, 'base64').toString(),
- )
- const pkgLockOldSha = (
- await client.rest.repos.getContent({
- owner: github.context.repo.owner,
- repo: github.context.repo.repo,
- path: file.filename,
- ref: 'master',
- })
- ).data.sha
- const pkgLockOldBlob = (
- await client.rest.git.getBlob({
- owner: github.context.repo.owner,
- repo: github.context.repo.repo,
- file_sha: pkgLockOldSha,
- })
- ).data.content
- const pkgLockOldJson = JSON.parse(
- Buffer.from(pkgLockOldBlob, 'base64').toString(),
- )
+ const prCommitRefForFile = file.contents_url.split('ref=')[1]
+ const pkgLockNewJson = await getLargeJsonAtRef(
+ client,
+ github.context.repo.owner,
+ github.context.repo.repo,
+ file.filename,
+ prCommitRefForFile,
+ )
+ const pkgLockOldJson = await getLargeJsonAtRef(
+ client,
+ github.context.repo.owner,
+ github.context.repo.repo,
+ file.filename,
+ 'master',
+ )
- const oldVesionModuleKey = findKeyEndingWith(
- pkgLockOldJson.packages,
- `node_modules/${packageName}`,
- )
- const newVesionModuleKey = findKeyEndingWith(
- pkgLockNewJson.packages,
- `node_modules/${packageName}`,
- )
- let oldVersion = pkgLockOldJson.packages[oldVesionModuleKey].version
- let newVersion = pkgLockNewJson.packages[newVesionModuleKey].version
+ const oldVesionModuleKey = findKeyEndingWith(
+ pkgLockOldJson.packages,
+ `node_modules/${packageName}`,
+ )
+ const newVesionModuleKey = findKeyEndingWith(
+ pkgLockNewJson.packages,
+ `node_modules/${packageName}`,
+ )
+ let oldVersion = pkgLockOldJson.packages[oldVesionModuleKey].version
+ let newVersion = pkgLockNewJson.packages[newVesionModuleKey].version
- const oldVesionModuleKeyParent = findKeyEndingWith(
- pkgLockOldJson.packages,
- `node_modules/${packageParentName}`,
- )
- const newVesionModuleKeyParent = findKeyEndingWith(
- pkgLockNewJson.packages,
- `node_modules/${packageParentName}`,
- )
- const oldVersionParent =
- pkgLockOldJson.packages[oldVesionModuleKeyParent].dependencies[
- packageName
- ].substring(1)
- const newVersionParent =
- pkgLockNewJson.packages[newVesionModuleKeyParent].dependencies[
- packageName
- ].substring(1)
+ const oldVesionModuleKeyParent = findKeyEndingWith(
+ pkgLockOldJson.packages,
+ `node_modules/${packageParentName}`,
+ )
+ const newVesionModuleKeyParent = findKeyEndingWith(
+ pkgLockNewJson.packages,
+ `node_modules/${packageParentName}`,
+ )
+ const oldVersionParent =
+ pkgLockOldJson.packages[oldVesionModuleKeyParent].dependencies[
+ packageName
+ ].substring(1)
+ const newVersionParent =
+ pkgLockNewJson.packages[newVesionModuleKeyParent].dependencies[
+ packageName
+ ].substring(1)
- // if parent dependency is higher version then existing
- // npm install will retrive the newer version from the parent dependency
- if (oldVersionParent > oldVersion) {
- oldVersion = oldVersionParent
- }
- if (newVersionParent > newVersion) {
- newVersion = newVersionParent
- }
+ // if parent dependency is higher version then existing
+ // npm install will retrive the newer version from the parent dependency
+ if (oldVersionParent > oldVersion) {
+ oldVersion = oldVersionParent
+ }
+ if (newVersionParent > newVersion) {
+ newVersion = newVersionParent
+ }
- if (newVersion !== oldVersion) {
- const pkgChangedFiles = await getChangedFilesBetweenTags(
- client,
- 'cloud-annotations',
- 'docusaurus-openapi',
- `v${oldVersion}`,
- `v${newVersion}`,
- )
- const changedComponents = overideComponents.filter(
- componenet =>
- pkgChangedFiles.filter(
- path =>
- path.includes('docusaurus-theme-openapi/src/theme') &&
- path.includes(componenet),
- ).length > 0,
- )
- const versionReport = ` |
---|
Old version | ${oldVersion} |
- New version | ${newVersion} |
- `
- const changedComponentsReport = ` Overide components changed | ${changedComponents.join(
- ', ',
- )} |
- `
- const body = messageTemplate + versionReport + changedComponentsReport
- await client.rest.issues.createComment({
- owner: github.context.repo.owner,
- repo: github.context.repo.repo,
- issue_number: pr.number,
- body,
- })
+ if (newVersion !== oldVersion) {
+ const pkgChangedFiles = await getChangedFilesBetweenTags(
+ client,
+ 'cloud-annotations',
+ 'docusaurus-openapi',
+ `v${oldVersion}`,
+ `v${newVersion}`,
+ )
+ const changedComponents = overideComponents.filter(
+ componenet =>
+ pkgChangedFiles.filter(
+ path =>
+ path.includes('docusaurus-theme-openapi/src/theme') &&
+ path.includes(componenet),
+ ).length > 0,
+ )
+ const versionReport = ` Old version | ${oldVersion} |
+ New version | ${newVersion} |
+ `
+ const changedComponentsReport = ` Overide components changed | ${changedComponents.join(
+ ', ',
+ )} |
+ `
+ const body = messageTemplate + versionReport + changedComponentsReport
+ await client.rest.issues.createComment({
+ owner: github.context.repo.owner,
+ repo: github.context.repo.repo,
+ issue_number: pr.number,
+ body,
+ })
- core.debug('Found changes and posted comment, done.')
- return
- }
- }
- core.debug('No changes found, done.')
+ core.debug('Found changes and posted comment, done.')
+ return
}
+
+ core.debug('No changes found, done.')
} catch (error) {
core.setFailed(error.message)
}
From 9e1c2e43b7f4be4f361c316b132359fa9bfb4439 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Sun, 13 Aug 2023 20:13:09 +0300
Subject: [PATCH 17/20] fix type
---
.github/actions/docusaurus-swizzled-warning/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 7becab34869ed..0ae1640444dbc 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -44,7 +44,7 @@ async function run() {
pr.number,
)
- const file = files.filter(f => f.filename !== 'package-lock.json')[0]
+ const file = files.filter(f => f.filename === 'package-lock.json')[0]
if (file === undefined) {
return
}
From 640567d89defc418918a8e2614289b971dc9f7b6 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 18 Aug 2023 23:23:12 +0300
Subject: [PATCH 18/20] change pull_request_target to pull_request
---
.github/workflows/docusaurus-swizzled-warning.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/docusaurus-swizzled-warning.yml b/.github/workflows/docusaurus-swizzled-warning.yml
index 17f779862ae94..203b4e28aa57a 100644
--- a/.github/workflows/docusaurus-swizzled-warning.yml
+++ b/.github/workflows/docusaurus-swizzled-warning.yml
@@ -1,6 +1,6 @@
name: Docusaurus swizzled component changes warning
on:
- pull_request_target:
+ pull_request:
types: [opened]
permissions:
From 78551fffbe5c6884663a5309ffb18b98359d78b3 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 18 Aug 2023 23:32:29 +0300
Subject: [PATCH 19/20] Improve action log
Change core.debug to core.info so it always shows and not only when in debug.
---
.github/actions/docusaurus-swizzled-warning/index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 0ae1640444dbc..657c30bda8216 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -133,11 +133,11 @@ async function run() {
body,
})
- core.debug('Found changes and posted comment, done.')
+ core.info('Found changes and posted comment, done.')
return
}
- core.debug('No changes found, done.')
+ core.info('No changes found, done.')
} catch (error) {
core.setFailed(error.message)
}
From 5311d0326573056d08cce2639cec430063a57ad3 Mon Sep 17 00:00:00 2001
From: jNullj <15849761+jNullj@users.noreply.github.com>
Date: Fri, 18 Aug 2023 23:38:42 +0300
Subject: [PATCH 20/20] Log old and new version
Log old and new versions for the Docusaurus swizzled component changes warning workflow.
---
.github/actions/docusaurus-swizzled-warning/index.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/actions/docusaurus-swizzled-warning/index.js b/.github/actions/docusaurus-swizzled-warning/index.js
index 657c30bda8216..c5eb4c434c967 100644
--- a/.github/actions/docusaurus-swizzled-warning/index.js
+++ b/.github/actions/docusaurus-swizzled-warning/index.js
@@ -101,6 +101,8 @@ async function run() {
if (newVersionParent > newVersion) {
newVersion = newVersionParent
}
+ core.info(`oldVersion=${oldVersion}`)
+ core.info(`newVersion=${newVersion}`)
if (newVersion !== oldVersion) {
const pkgChangedFiles = await getChangedFilesBetweenTags(
|
---|