fix: Replace slugify in deploy-preview-netlify with simple regex
continuous-integration/drone/pr Build is passing Details

This commit removes the direct dependency on the "slugify" package, since it produces slugs, which are still invalid to be used as subdomain names.

We now use a custom RegEx scheme which just replaces all white spaces, dots and slashes with a "-" sign for readability and removes all otherwise invalid characters.

To account for specific language characters or unicode variants we first normalize it using the String.prototype.normalize() function, so we can preserve as much characters as possible. 

Additionally, we now make sure that our alias is not longer than 37 characters, which is the maximum alias length according to Netlify's documentation [0]

[0]: https://cli.netlify.com/commands/deploy
This commit is contained in:
saibotk 2022-02-14 14:58:20 +01:00
parent ede8bc5015
commit a33e1e45bc
Signed by untrusted user: saibotk
GPG Key ID: 67585F0065E261D5
4 changed files with 9 additions and 11 deletions

View File

@ -83,7 +83,6 @@
"rollup": "2.67.2",
"rollup-plugin-visualizer": "5.5.4",
"sass": "1.49.7",
"slugify": "1.6.5",
"typescript": "4.5.5",
"vite": "2.7.13",
"vite-plugin-pwa": "0.11.13",

View File

@ -1,20 +1,24 @@
const slugify = require('slugify')
const {exec} = require('child_process')
const axios = require('axios')
const BOT_USER_ID = 513
const giteaToken = process.env.GITEA_TOKEN
const siteId = process.env.NETLIFY_SITE_ID
const branchSlug = slugify(process.env.DRONE_SOURCE_BRANCH)
const branchSlug = String(process.env.DRONE_SOURCE_BRANCH)
.trim()
.normalize('NFKD')
.toLowerCase()
.replace(/[.\s/]/g, '-')
.replace(/[^A-Za-z\d-]/g, '')
const prNumber = process.env.DRONE_PULL_REQUEST
const prIssueCommentsUrl = `https://kolaente.dev/api/v1/repos/vikunja/frontend/issues/${prNumber}/comments`
const alias = `${prNumber}-${branchSlug}`
const alias = `${prNumber}-${branchSlug}`.substring(0,37)
const fullPreviewUrl = `https://${alias}--vikunja-frontend-preview.netlify.app`
const promiseExec = cmd => {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
exec(cmd, (error, stdout) => {
if (error) {
reject(error)
return

View File

@ -1 +1 @@
55ce0faaa2c1919341617ccfaeccbb6029ac12107964ff488985cff13dd952f1a991df3ab0d4b0705deb761e508e6434 ./scripts/deploy-preview-netlify.js
bb46342a0a08105b340ba7976cff9d80ef89901120ec0639669caa70bb7d2dbc43e78b1f635a7654ab2456e8358c98a4 ./scripts/deploy-preview-netlify.js

View File

@ -11663,11 +11663,6 @@ slice-ansi@^5.0.0:
ansi-styles "^6.0.0"
is-fullwidth-code-point "^4.0.0"
slugify@1.6.5:
version "1.6.5"
resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.5.tgz#c8f5c072bf2135b80703589b39a3d41451fbe8c8"
integrity sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ==
snake-case@3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c"