@hexonet/semantic-release-whmcs 4.0.4 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/.github/dependabot.yml +7 -7
  2. package/.github/workflows/release.yml +29 -0
  3. package/.github/workflows/{pull-request.yml → test.yml} +13 -16
  4. package/.releaserc.json +1 -5
  5. package/HISTORY.md +12 -0
  6. package/index.js +23 -24
  7. package/lib/definitions/errors.js +19 -10
  8. package/lib/delete-marketplace-version.js +48 -48
  9. package/lib/get-error.js +6 -6
  10. package/lib/get-github-releases.js +17 -18
  11. package/lib/publish.js +10 -13
  12. package/lib/puppet.js +73 -74
  13. package/lib/resolve-config.js +5 -6
  14. package/lib/scrape-marketplace-versions.js +30 -28
  15. package/lib/set-compatible-versions.js +42 -41
  16. package/lib/verify.js +4 -4
  17. package/package.json +32 -28
  18. package/whmcs.js +81 -53
  19. package/.eslintignore +0 -3
  20. package/.eslintrc.js +0 -14
  21. package/.github/workflows/push.yml +0 -79
  22. package/coverage/base.css +0 -224
  23. package/coverage/block-navigation.js +0 -87
  24. package/coverage/coverage-final.json +0 -11
  25. package/coverage/favicon.png +0 -0
  26. package/coverage/index.html +0 -131
  27. package/coverage/lib/definitions/errors.js.html +0 -148
  28. package/coverage/lib/definitions/index.html +0 -116
  29. package/coverage/lib/delete-marketplace-version.js.html +0 -343
  30. package/coverage/lib/get-error.js.html +0 -106
  31. package/coverage/lib/get-github-releases.js.html +0 -184
  32. package/coverage/lib/index.html +0 -236
  33. package/coverage/lib/publish.js.html +0 -370
  34. package/coverage/lib/puppet.js.html +0 -424
  35. package/coverage/lib/resolve-config.js.html +0 -118
  36. package/coverage/lib/scrape-marketplace-versions.js.html +0 -220
  37. package/coverage/lib/set-compatible-versions.js.html +0 -298
  38. package/coverage/lib/verify.js.html +0 -157
  39. package/coverage/prettify.css +0 -1
  40. package/coverage/prettify.js +0 -2
  41. package/coverage/sort-arrow-sprite.png +0 -0
  42. package/coverage/sorter.js +0 -196
@@ -1,9 +1,9 @@
1
1
  version: 2
2
2
  updates:
3
- - package-ecosystem: npm
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- open-pull-requests-limit: 10
8
- commit-message:
9
- prefix: chore
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
8
+ commit-message:
9
+ prefix: chore
@@ -0,0 +1,29 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+
7
+ jobs:
8
+ release:
9
+ name: Release @ NodeJS LTS - x86 - ubuntu-latest
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ persist-credentials: false
17
+ - name: Setup NodeJS LTS
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: lts/*
21
+ cache: npm
22
+ - name: Install dependencies
23
+ run: npm ci
24
+ - name: Release
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
27
+ GITHUB_REPO: ${{ secrets.GH_REPO }}
28
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
29
+ run: npx semantic-release
@@ -1,24 +1,21 @@
1
- # This workflow handle pull requests
2
- name: Receive pull_request
3
- on: [pull_request_target]
1
+ name: Lint codebase & Execute tests
2
+ on:
3
+ push:
4
+ branches:
5
+ - dependabot/** #branches are generated by https://github.com/dependabot
6
+
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - synchronize
11
+
4
12
  jobs:
5
- approve: # to approve a workflow run(through github environment)
6
- name: Approve Job
7
- runs-on: ubuntu-latest
8
- steps:
9
- - name: Approve
10
- run: |
11
- echo For security reasons, all pull requests need to be approved first before running any automated CI.
12
- echo Thank you for your patience.
13
13
  test:
14
14
  name: Test @ NodeJS - x86 - ubuntu-latest
15
15
  runs-on: ubuntu-latest
16
- needs: [approve]
17
16
  strategy:
18
17
  matrix:
19
18
  node-version: [lts/*]
20
- environment:
21
- name: pr-reviews
22
19
  steps:
23
20
  - name: Checkout
24
21
  uses: actions/checkout@v3
@@ -26,7 +23,7 @@ jobs:
26
23
  uses: actions/setup-node@v3
27
24
  with:
28
25
  node-version: ${{ matrix.node-version }}
29
- check-latest: true
26
+ cache: npm
30
27
  - name: Install dependencies
31
28
  run: npm ci
32
29
  - name: Linting
@@ -40,7 +37,7 @@ jobs:
40
37
  WHMCSMP_PRODUCTID: ${{ secrets.WHMCSMP_PRODUCTID }}
41
38
  WHMCSMP_MINVERSION: ${{ secrets.WHMCSMP_MINVERSION }}
42
39
  DEBUG: ${{ secrets.DEBUG }}
43
- run: npm run coverage
40
+ run: npm run test
44
41
  - name: Initialize CodeQL
45
42
  uses: github/codeql-action/init@v2
46
43
  with:
package/.releaserc.json CHANGED
@@ -12,11 +12,7 @@
12
12
  [
13
13
  "@semantic-release/git",
14
14
  {
15
- "assets": [
16
- "HISTORY.md",
17
- "package?(-lock).json",
18
- "coverage"
19
- ],
15
+ "assets": ["HISTORY.md", "package?(-lock).json"],
20
16
  "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
21
17
  }
22
18
  ],
package/HISTORY.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [5.0.0](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs/compare/v4.0.4...v5.0.0) (2023-01-18)
2
+
3
+
4
+ ### chore
5
+
6
+ * **node:** Refactored SemanticRelease to make it compatible with ESM ([f5a3640](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs/commit/f5a36404e978d072f60497787074301d34255633))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * **node:** Ported to ESM
12
+
1
13
  ## [4.0.4](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-whmcs/compare/v4.0.3...v4.0.4) (2023-01-04)
2
14
 
3
15
 
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const verifyWHMCS = require('./lib/verify')
2
- const publishWHMCS = require('./lib/publish')
3
- const deleteVersion = require('./lib/delete-marketplace-version')
4
- const setCompatibleVersions = require('./lib/set-compatible-versions')
5
- const githubReleases = require('./lib/get-github-releases.js')
6
- const marketplaceVersions = require('./lib/scrape-marketplace-versions.js')
1
+ import verifyWHMCS from "./lib/verify.js";
2
+ import publishWHMCS from "./lib/publish.js";
3
+ import deleteVersion from "./lib/delete-marketplace-version.js";
4
+ import setCompatibleVersions from "./lib/set-compatible-versions.js";
5
+ import githubReleases from "./lib/get-github-releases.js";
6
+ import marketplaceVersions from "./lib/scrape-marketplace-versions.js";
7
7
 
8
8
  let verified;
9
9
 
@@ -25,46 +25,45 @@ async function verifyConditions(pluginConfig, context) {
25
25
  * @param {*} context The context provided by semantic-release
26
26
  */
27
27
  async function publish(pluginConfig, context) {
28
- await verifyConditions(pluginConfig, context)
29
- return publishWHMCS(pluginConfig, context)
28
+ await verifyConditions(pluginConfig, context);
29
+ return publishWHMCS(pluginConfig, context);
30
30
  }
31
31
 
32
32
  async function syncVersions(pluginConfig, context) {
33
- await verifyConditions(pluginConfig, context)
34
- const releases = await githubReleases(pluginConfig, context)
33
+ await verifyConditions(pluginConfig, context);
34
+ const releases = await githubReleases(pluginConfig, context);
35
35
 
36
36
  if (releases && releases.length) {
37
- const versions = await marketplaceVersions(pluginConfig, context)
37
+ const versions = await marketplaceVersions(pluginConfig, context);
38
38
  for (const release of releases) {
39
39
  if (!versions.includes(release.name.substring(1))) {
40
40
  context.nextRelease = {
41
41
  version: release.name.substring(1),
42
42
  notes: release.body,
43
- releaseDate: release.published_at
44
- }
45
- console.log(`Adding missing version ${context.nextRelease.version}`)
46
- await publish(pluginConfig, context)
43
+ releaseDate: release.published_at,
44
+ };
45
+ console.log(`Adding missing version ${context.nextRelease.version}`);
46
+ await publish(pluginConfig, context);
47
47
  }
48
48
  }
49
49
  }
50
50
  }
51
51
 
52
-
53
52
  async function delVersion(pluginConfig, context) {
54
- await verifyConditions(pluginConfig, context)
55
- await deleteVersion(pluginConfig, context)
53
+ await verifyConditions(pluginConfig, context);
54
+ await deleteVersion(pluginConfig, context);
56
55
  }
57
56
 
58
57
  async function updateCompatibility(pluginConfig, context) {
59
- await verifyConditions(pluginConfig, context)
60
- await setCompatibleVersions(pluginConfig, context)
58
+ await verifyConditions(pluginConfig, context);
59
+ await setCompatibleVersions(pluginConfig, context);
61
60
  }
62
61
 
63
62
  async function fail(pluginConfig, context) {
64
- await verifyConditions(pluginConfig, context)
63
+ await verifyConditions(pluginConfig, context);
65
64
  }
66
65
 
67
- module.exports = {
66
+ export default {
68
67
  verifyConditions,
69
68
  publish,
70
69
  fail,
@@ -72,5 +71,5 @@ module.exports = {
72
71
  delVersion,
73
72
  githubReleases,
74
73
  marketplaceVersions,
75
- updateCompatibility
76
- }
74
+ updateCompatibility,
75
+ };
@@ -1,21 +1,30 @@
1
- module.exports = {
2
- ENOGHTOKEN: () => ({
1
+ export function ENOGHTOKEN() {
2
+ return {
3
3
  message: "No Github Token specified.",
4
4
  details: "Please create a `GH_TOKEN` in repository secrets.",
5
- }),
6
- EWHMCSNOCREDENTIALS: () => ({
5
+ };
6
+ }
7
+
8
+ export function EWHMCSNOCREDENTIALS() {
9
+ return {
7
10
  message: "No WHMCS Marketplace credentials specified.",
8
11
  details:
9
12
  "WHMCS Marketplace credentails have to be set in the `WHMCS_LOGIN` and `WHMCS_PASSWORD` environment variables on your CI environment.",
10
- }),
11
- EWHMCSNOPRODUCTID: () => ({
13
+ };
14
+ }
15
+
16
+ export function EWHMCSNOPRODUCTID() {
17
+ return {
12
18
  message: "No WHMCS Marketplace Product ID specified.",
13
19
  details:
14
20
  "The product id of your listed product at the WHMCS Marketplace has to be set in the `WHMCS_PRODUCTID` environment variable on your CI environment. You'll find that number in url when visiting the product page in WHMCS Marketplace.",
15
- }),
16
- EWHMCSINVALIDPRODUCTID: () => ({
21
+ };
22
+ }
23
+
24
+ export function EWHMCSINVALIDPRODUCTID() {
25
+ return {
17
26
  message: "Invalid WHMCS Marketplace Product ID specified.",
18
27
  details:
19
28
  "The product id of your listed product at the WHMCS Marketplace has to be set in the `WHMCS_PRODUCTID` environment variable on your CI environment. You'll find that number in url when visiting the product page in WHMCS Marketplace.",
20
- }),
21
- };
29
+ };
30
+ }
@@ -1,40 +1,40 @@
1
- const debug = require('debug')('semantic-release:whmcs')
2
- const puppet = require('./puppet')
3
- const path = require('path')
4
-
1
+ import puppet from "./puppet.js";
2
+ import debugConfig from "debug";
3
+ import { fileURLToPath } from "node:url";
4
+ const debug = debugConfig("semantic-release:whmcs");
5
+ const __filename = fileURLToPath(import.meta.url);
5
6
  /**
6
7
  * A method to publish the module update on whmcs market place
7
8
  */
8
- module.exports = async (pluginConfig, context) => {
9
+ export default async (pluginConfig, context) => {
9
10
  // if (!context.logger) {
10
11
  // context.logger = console;
11
12
  // }
12
13
 
13
- const sep = '+++++++++++++++++++++++++++++++++++++++++++++++++++'
14
- const out = `\n${sep}\n${path.basename(__filename)}\n${sep}\n`
14
+ const sep = "+++++++++++++++++++++++++++++++++++++++++++++++++++";
15
+ const out = `\n${sep}\n${__filename}\n${sep}\n`;
15
16
 
16
- const { version } = context
17
+ const { version } = context;
17
18
  if (!version || !version.length) {
18
- debug(`${out}Deleting product version failed. No input data available.`)
19
- return false
19
+ debug(`${out}Deleting product version failed. No input data available.`);
20
+ return false;
20
21
  }
21
22
 
22
- debug(`${out}Delete Version: ${version}`)
23
+ debug(`${out}Delete Version: ${version}`);
23
24
 
24
- const püppi = await puppet(context)
25
- const result = await püppi.login()
25
+ const püppi = await puppet(context);
26
+ const result = await püppi.login();
26
27
  if (!result) {
27
- return result
28
+ return result;
28
29
  }
29
- const { page, navOpts, gotoOpts, selectorOpts, productid, urlbase } =
30
- püppi.config
30
+ const { page, navOpts, gotoOpts, selectorOpts, productid, urlbase } = püppi.config;
31
31
 
32
32
  // strip markdown links from notes as not allowed to keep
33
33
  try {
34
34
  // navigate to product administration
35
- const url = `${urlbase}/product/${productid}/edit#versions`
36
- await page.goto(url, gotoOpts)
37
- debug('product page loaded at %s', url)
35
+ const url = `${urlbase}/product/${productid}/edit#versions`;
36
+ await page.goto(url, gotoOpts);
37
+ debug("product page loaded at %s", url);
38
38
  // open versions tab (instead of doing it via url)
39
39
  // let selector = '#nav-tabs li a[href="#versions"]';
40
40
  // await page.waitForSelector(selector, selectorOpts);
@@ -44,43 +44,43 @@ module.exports = async (pluginConfig, context) => {
44
44
  // xpath improvements / changes with v16.1.0
45
45
  // -> https://github.com/puppeteer/puppeteer/pull/8730
46
46
  // https://github.com/puppeteer/puppeteer/blob/d1681ec06b7c3db4b51c20b17b3339f852efbd4d/test/src/queryhandler.spec.ts
47
- let elements = []
47
+ let elements = [];
48
48
  do {
49
- const xpath = `xpath/.//td[contains(., "Version ${version}")]/following-sibling::td/a[contains(@class, "btn-styled-red")]`
50
- await page.waitForSelector(xpath, selectorOpts)
51
- debug('XPath found.')
52
- const nav = page.waitForNavigation(navOpts)
53
- elements = await page.$$(xpath)
49
+ const xpath = `xpath/.//td[contains(., "Version ${version}")]/following-sibling::td/a[contains(@class, "btn-styled-red")]`;
50
+ await page.waitForSelector(xpath, selectorOpts);
51
+ debug("XPath found.");
52
+ const nav = page.waitForNavigation(navOpts);
53
+ elements = await page.$$(xpath);
54
54
  if (elements.length) {
55
- debug('Delete Button - click.')
56
- await elements[0].hover()
57
- await elements[0].click()
58
- debug('Delete Button - clicked.')
59
- await nav
60
- debug('Navigation finished.')
55
+ debug("Delete Button - click.");
56
+ await elements[0].hover();
57
+ await elements[0].click();
58
+ debug("Delete Button - clicked.");
59
+ await nav;
60
+ debug("Navigation finished.");
61
61
  // confirm deletion
62
- const selector = 'button.btn-styled-red'
63
- await page.waitForSelector(selector, selectorOpts)
64
- debug('deletion confirmation button available')
65
- debug('click confirmation button')
66
- await page.clickAndNavigate(selector)
67
- debug('clicked confirmation button')
68
- await nav
69
- debug('WHMCS Marketplace deleting product version succeeded.')
62
+ const selector = "button.btn-styled-red";
63
+ await page.waitForSelector(selector, selectorOpts);
64
+ debug("deletion confirmation button available");
65
+ debug("click confirmation button");
66
+ await page.clickAndNavigate(selector);
67
+ debug("clicked confirmation button");
68
+ await nav;
69
+ debug("WHMCS Marketplace deleting product version succeeded.");
70
70
  }
71
- } while (elements.length)
71
+ } while (elements.length);
72
72
  } catch (error) {
73
73
  // while loop and having all versions deleted
74
74
  if (!/waiting for selector `.\/\//i.test(error.message)) {
75
- debug('Deleting product version failed.', error.message)
76
- await page.browser().close()
77
- return false
75
+ debug("Deleting product version failed.", error.message);
76
+ await page.browser().close();
77
+ return false;
78
78
  }
79
79
  }
80
80
 
81
- await page.browser().close()
81
+ await page.browser().close();
82
82
  return {
83
- name: 'WHMCS Marketplace Product Version',
84
- url: `${urlbase}/product/${productid}`
85
- }
86
- }
83
+ name: "WHMCS Marketplace Product Version",
84
+ url: `${urlbase}/product/${productid}`,
85
+ };
86
+ };
package/lib/get-error.js CHANGED
@@ -1,7 +1,7 @@
1
- const SemanticReleaseError = require('@semantic-release/error')
2
- const ERROR_DEFINITIONS = require('./definitions/errors.js')
1
+ import SemanticReleaseError from "@semantic-release/error";
2
+ import * as ERROR_DEFINITIONS from "./definitions/errors.js";
3
3
 
4
- module.exports = (code) => {
5
- const { message, details } = ERROR_DEFINITIONS[code]()
6
- return new SemanticReleaseError(message, code, details)
7
- }
4
+ export default (code) => {
5
+ const { message, details } = ERROR_DEFINITIONS[code]();
6
+ return new SemanticReleaseError(message, code, details);
7
+ };
@@ -1,6 +1,7 @@
1
- const debug = require('debug')('semantic-release:whmcs')
2
- const resolveConfig = require('./resolve-config')
3
- const GitHub = require('github-api')
1
+ import resolveConfig from "./resolve-config.js";
2
+ import GitHub from "github-api";
3
+ import debugConfig from "debug";
4
+ const debug = debugConfig("semantic-release:whmcs");
4
5
 
5
6
  // https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
6
7
  // Rate limits to 60 requests/hour per IP for anonymous requests, 5000/hour with authentication
@@ -8,26 +9,24 @@ const GitHub = require('github-api')
8
9
  /**
9
10
  * A method to get releases from github repository
10
11
  */
11
- module.exports = async (pluginConfig, context) => {
12
- debug('Getting releases from GitHub')
12
+ export default async (pluginConfig, context) => {
13
+ debug("Getting releases from GitHub");
13
14
 
14
- const { ghrepo, ghtoken } = resolveConfig(context)
15
+ const { ghrepo, ghtoken } = resolveConfig(context);
15
16
 
16
17
  const gh = new GitHub({
17
- token: ghtoken
18
- })
18
+ token: ghtoken,
19
+ });
19
20
  if (ghrepo) {
20
21
  // optional by default false
21
- const repo = ghrepo.split('/')
22
- const githubReleases = await gh.getRepo(repo[0], repo[1]).listReleases()
22
+ const repo = ghrepo.split("/");
23
+ const githubReleases = await gh.getRepo(repo[0], repo[1]).listReleases();
23
24
  if (githubReleases.status === 200) {
24
- githubReleases.data.forEach((r) =>
25
- debug(`Detected GitHub release ${r.name.substring(1)}`)
26
- )
27
- githubReleases.data.reverse()
28
- return githubReleases.data
25
+ githubReleases.data.forEach((r) => debug(`Detected GitHub release ${r.name.substring(1)}`));
26
+ githubReleases.data.reverse();
27
+ return githubReleases.data;
29
28
  }
30
- debug('Failed to get releases from GitHub')
29
+ debug("Failed to get releases from GitHub");
31
30
  }
32
- return false
33
- }
31
+ return false;
32
+ };
package/lib/publish.js CHANGED
@@ -1,22 +1,21 @@
1
- const debug = require("debug")("semantic-release:whmcs");
2
- const puppet = require("./puppet");
3
- const setCompatibleVersions = require("./set-compatible-versions");
4
- const path = require("path");
1
+ import puppet from "./puppet.js";
2
+ import setCompatibleVersions from "./set-compatible-versions.js";
3
+ import debugConfig from "debug";
4
+ import { fileURLToPath } from "node:url";
5
+ const debug = debugConfig("semantic-release:whmcs");
6
+ const __filename = fileURLToPath(import.meta.url);
5
7
 
6
8
  /**
7
9
  * A method to publish the module update on whmcs market place
8
10
  */
9
- module.exports = async (pluginConfig, context) => {
11
+ export default async (pluginConfig, context) => {
10
12
  const sep = "+++++++++++++++++++++++++++++++++++++++++++++++++++";
11
- const out = `\n${sep}\n${path.basename(__filename)}\n${sep}\n`;
12
-
13
+ const out = `\n${sep}\n${__filename}\n${sep}\n`;
13
14
  const {
14
15
  nextRelease: { notes, version, releaseDate },
15
16
  } = context;
16
17
  if (!notes || !notes.length || !version || !version.length) {
17
- debug(
18
- `${out}Publishing new product version failed. No input data available.`
19
- );
18
+ debug(`${out}Publishing new product version failed. No input data available.`);
20
19
  return false;
21
20
  }
22
21
  // strip markdown links from notes as not allowed to keep (taken from remove-markdown and cleaned up)
@@ -76,9 +75,7 @@ module.exports = async (pluginConfig, context) => {
76
75
  );
77
76
  debug("form input for description finished.");
78
77
 
79
- await page.clickAndNavigate(
80
- 'div.listing-edit-container form button[type="submit"]'
81
- );
78
+ await page.clickAndNavigate('div.listing-edit-container form button[type="submit"]');
82
79
  await setCompatibleVersions(pluginConfig, context);
83
80
  } catch (error) {
84
81
  debug("Publishing new product version failed.", error.message);