From 518c31544747c176663f32e5927dcd2faf190d9e Mon Sep 17 00:00:00 2001 From: Collin McNeese Date: Wed, 19 Jun 2024 15:03:04 -0500 Subject: [PATCH] Bump eslint from 9.4.0 to 9.5.0, cspell from 8.8.3 to 8.8.4, and markdownlint-cli from 0.40.0 to 0.41.0 --- .eslintignore | 3 --- .eslintrc.json | 18 ------------------ .github/workflows/ci.yml | 2 +- LICENSE | 2 +- __test__/ci.sh | 2 +- action.yml | 2 +- eslint.config.js | 20 ++++++++++++++++++++ package-lock.json | 14 +------------- package.json | 2 +- src/forwarder.js | 19 ++++++++++--------- src/index.js | 2 +- 11 files changed, 37 insertions(+), 49 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 4cbc5a5..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules/ -dist/ -__test__/ diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 696e969..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "env": { - "es6": true, - "node": true - }, - "extends": "strongloop", - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" - }, - "rules": { - "max-len": 0 - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a897b2..26b80b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} diff --git a/LICENSE b/LICENSE index e3e70a1..05b513a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 github.com/collinmcneese +Copyright (c) github.com/collinmcneese Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/__test__/ci.sh b/__test__/ci.sh index 4a46a14..e3956db 100755 --- a/__test__/ci.sh +++ b/__test__/ci.sh @@ -16,7 +16,7 @@ function ci-run { cd "$(dirname "$0")/.." -ci-run npx eslint --ignore-path .eslintignore . +ci-run npx eslint ci-run npx cspell *.js *.md ci-run npx markdownlint-cli -c markdownlint.yml *.md ci-run npx jest diff --git a/action.yml b/action.yml index 32205c0..35adc4c 100644 --- a/action.yml +++ b/action.yml @@ -15,5 +15,5 @@ inputs: description: 'Location to an allow list of target URL entries.' required: false runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..d2b028b --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,20 @@ +const js = require('@eslint/js'); + +module.exports = [ + { + ignores: ['__test__/**/*', 'dist/**/*', 'node_modules/**/*'], + }, + { + languageOptions: { + ecmaVersion: 2018, + sourceType: 'commonjs', + }, + }, + js.configs.recommended, + { + rules: { + semi: "error", + "prefer-const": "error" + } + } +]; diff --git a/package-lock.json b/package-lock.json index d876cf6..878eafd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,9 +14,9 @@ "request": "^2.88.2" }, "devDependencies": { + "@eslint/js": "^9.5.0", "cspell": "^8.8.4", "eslint": "^9.5.0", - "eslint-config-strongloop": "^2.1.0", "jest": "^29.7.0", "markdownlint-cli": "^0.41.0" }, @@ -3192,12 +3192,6 @@ "url": "https://eslint.org/donate" } }, - "node_modules/eslint-config-strongloop": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-strongloop/-/eslint-config-strongloop-2.1.0.tgz", - "integrity": "sha512-mU/+gcWDlY57mWrwaNOVdaPHmqpFZ60t7tPxXPYa3kdadqawrKEYXsxU7eyhJIrJdGh4JKQxnZQ17yhMF+M3Ug==", - "dev": true - }, "node_modules/eslint-scope": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.1.tgz", @@ -8822,12 +8816,6 @@ } } }, - "eslint-config-strongloop": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-strongloop/-/eslint-config-strongloop-2.1.0.tgz", - "integrity": "sha512-mU/+gcWDlY57mWrwaNOVdaPHmqpFZ60t7tPxXPYa3kdadqawrKEYXsxU7eyhJIrJdGh4JKQxnZQ17yhMF+M3Ug==", - "dev": true - }, "eslint-scope": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.1.tgz", diff --git a/package.json b/package.json index 6d978ab..fdd0526 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ }, "homepage": "https://github.com/collinmcneese/github-actions-forwarder#readme", "devDependencies": { + "@eslint/js": "^9.5.0", "cspell": "^8.8.4", "eslint": "^9.5.0", - "eslint-config-strongloop": "^2.1.0", "jest": "^29.7.0", "markdownlint-cli": "^0.41.0" }, diff --git a/src/forwarder.js b/src/forwarder.js index 521c5f8..ef7511b 100644 --- a/src/forwarder.js +++ b/src/forwarder.js @@ -3,11 +3,12 @@ const request = require('request'); const crypto = require('crypto'); const URL = require('url').URL; +const console = require('console'); // Function to validate that passed URL is a valid URL function validateUrl(urlString) { try { - new URL(urlString); // eslint-disable-line no-new + new URL(urlString); return true; } catch (err) { throw new Error(`Invalid URL: ${urlString} \n ${err}`); @@ -47,17 +48,17 @@ async function fetchAllowListSource(allowListSource) { // Function to validate that passed target URL is in the passed allowList array via pattern matching function validateAllowList(targetUrl, allowList) { - let targetUrlObj = new URL(targetUrl); + const targetUrlObj = new URL(targetUrl); for (let i = 0; i < allowList.length; i++) { - let allowListUrlObj = new URL(allowList[i]); + const allowListUrlObj = new URL(allowList[i]); if (targetUrlObj.hostname === allowListUrlObj.hostname) { return true; } // support for wildcard partial matching in allowList if (allowListUrlObj.hostname.startsWith('*')) { - let wildcard = allowListUrlObj.hostname.replace('*', ''); + const wildcard = allowListUrlObj.hostname.replace('*', ''); if (targetUrlObj.hostname.endsWith(wildcard)) { return true; } @@ -79,11 +80,11 @@ function getWebhookSignature(payload, secret, algorithm) { // Function to return Request object with passed context, targetUrl and webhookSecret function getRequestOptions(context, targetUrl, webhookSecret) { - let payloadJson = JSON.stringify(context.payload, undefined, 2); + const payloadJson = JSON.stringify(context.payload, undefined, 2); // Build request options // Include the signature in the headers, if a webhookSecret was provided - let options = { + const options = { url: targetUrl, method: 'POST', headers: { @@ -110,7 +111,7 @@ async function forwarder({context, targetUrl, webhookSecret, allowListSource}) { // If allowListSource is provided, fetch the allowList and validate that targetUrl is in the allowList if (allowListSource) { - let allowList = await fetchAllowListSource(allowListSource); + const allowList = await fetchAllowListSource(allowListSource); if (!validateAllowList(targetUrl, allowList)) { throw new Error(`targetUrl: ${targetUrl} is not in allowListSource: ${allowListSource}`); @@ -120,11 +121,11 @@ async function forwarder({context, targetUrl, webhookSecret, allowListSource}) { } // Build request options - let options = getRequestOptions(context, targetUrl, webhookSecret); + const options = getRequestOptions(context, targetUrl, webhookSecret); // Send the request return new Promise((resolve, reject) => { - request(options, (error, response, body) => { + request(options, (error, response) => { if (error) { reject(error); } else if (response.statusCode < 200 || response.statusCode >= 300) { diff --git a/src/index.js b/src/index.js index 249ab85..f01a66a 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,7 @@ forwarder({ webhookSecret: webhookSecret, allowListSource: allowListSource, }).then((result) => { - console.log(result); + core.info(result); core.summary .addRaw(result)