|
| 1 | +# MIT License |
| 2 | +# |
| 3 | +# Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/> |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +#!/bin/bash |
| 24 | +source $GITHUB_ACTION_PATH/src/modules/errmsg.sh |
| 25 | +config=$(cat just.config.json) |
| 26 | + |
| 27 | +local redirect_config_=$(echo "$config" | jq -r '.redirect_config') |
| 28 | +if ! echo "$config" | jq -e '.redirect_config' > /dev/null; then |
| 29 | + local ERROR_MESSAGE=($(ErrorMessage "redirect/checks.sh" "0117")) |
| 30 | + echo $ERROR_MESSAGE && exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +validate_redirect_config() { |
| 34 | + local url=$(echo "$config" | jq -r '.redirect_config.url' > /dev/null) |
| 35 | + if [[ -z "$url" ]]; then |
| 36 | + local ERROR_MESSAGE=($(ErrorMessage "redirect/checks.sh" "0114")) |
| 37 | + echo $ERROR_MESSAGE && exit 1 |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +validate_paths() { |
| 42 | + local paths=$(echo "$config" | jq -c '.redirect_config.paths[]?') |
| 43 | + if [[ -n "$paths" ]]; then |
| 44 | + local countt=0 |
| 45 | + for path in $paths; do |
| 46 | + local url=$(echo "$path" | jq -r '.url') |
| 47 | + local path_=$(echo "$path" | jq -r '.path_') |
| 48 | + if [[ -z "$url"]]; then |
| 49 | + local ERROR_MESSAGE=($(customErrorMessage "Error" "0115" "Missing \"url\" in item #$countt in \"paths\" in \"redirect_config\" in \"module.exports\" at \"just.config.js\" file.")) |
| 50 | + echo $ERROR_MESSAGE && exit 1 |
| 51 | + elif [[ -z "$path_" ]]; then |
| 52 | + local ERROR_MESSAGE=($(customErrorMessage "Error" "0116" "Missing \"path_\" in item #$countt in \"paths\" in \"redirect_config\" in \"module.exports\" at \"just.config.js\" file.")) |
| 53 | + echo $ERROR_MESSAGE && exit 1 |
| 54 | + fi |
| 55 | + countt=$((countt + 1)) |
| 56 | + done |
| 57 | + fi |
| 58 | +} |
| 59 | + |
| 60 | +validate_redirect_config |
| 61 | +validate_paths |
0 commit comments