From b3d9eb961467616add15ba82c4ceda020e5e4297 Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 11:22:31 -0400 Subject: [PATCH 1/6] Remove invalid redirects --- docs/redirects.csv | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/redirects.csv b/docs/redirects.csv index 532bd4ca1752..a1a8346b4789 100644 --- a/docs/redirects.csv +++ b/docs/redirects.csv @@ -477,7 +477,6 @@ https://community.expensify.com/discussion/5321/how-to-set-up-saml-authenticatio https://community.expensify.com/discussion/5499/deep-dive-configure-coding-for-sage-intacct,https://help.expensify.com/articles/expensify-classic/connections/sage-intacct/Configure-Sage-Intacct https://community.expensify.com/discussion/5580/deep-dive-configure-advanced-settings-for-netsuite,https://help.expensify.com/articles/new-expensify/connections/netsuite/Connect-to-NetSuite#step-3-configure-advanced-settings https://community.expensify.com/discussion/5632/deep-dive-configure-coding-for-netsuite,https://help.expensify.com/articles/new-expensify/connections/netsuite/Connect-to-NetSuite#configure-netsuite-integration -https://community.expensify.com/discussion/5632/deep-dive-configure-coding-for-netsuite#tax,https://help.expensify.com/articles/new-expensify/connections/netsuite/Connect-to-NetSuite#configure-netsuite-integration https://community.expensify.com/discussion/5649/deep-dive-configure-advanced-settings-for-quickbooks-online,https://help.expensify.com/articles/expensify-classic/connections/quickbooks-online/Configure-Quickbooks-Online https://community.expensify.com/discussion/5654/deep-dive-using-expense-rules-to-vendor-match-when-exporting-to-an-accounting-package,https://help.expensify.com/articles/expensify-classic/expenses/Expense-Rules#how-can-i-use-expense-rules-to-vendor-match-when-exporting-to-an-accounting-package https://community.expensify.com/discussion/5656/deep-dive-configure-coding-for-xero/,https://help.expensify.com/articles/new-expensify/connections/xero/Connect-to-Xero#step-2-configure-import-settings @@ -490,7 +489,6 @@ https://community.expensify.com/discussion/5864/how-to-add-a-personal-bank-accou https://community.expensify.com/discussion/5941/how-to-reimburse-overseas-employees-for-us-employers/,https://help.expensify.com/articles/expensify-classic/bank-accounts-and-payments/bank-accounts/Enable-Global-Reimbursements https://community.expensify.com/discussion/6203/deep-dive-expensify-card-and-netsuite-auto-reconciliation-how-it-works,https://help.expensify.com/articles/expensify-classic/expensify-card/Expensify-Card-Reconciliation https://community.expensify.com/discussion/6698/faq-troubleshooting-bank-and-card-errors,https://help.expensify.com/articles/expensify-classic/connect-credit-cards/company-cards/Troubleshooting -https://community.expensify.com/discussion/6698/faq-troubleshooting-bank-and-card-errors#account-type-not-supported,https://help.expensify.com/articles/expensify-classic/connect-credit-cards/company-cards/Troubleshooting https://community.expensify.com/discussion/6827/what-s-happening-to-my-expensify-bill,https://help.expensify.com/articles/expensify-classic/expensify-billing/Billing-Overview https://community.expensify.com/discussion/6898/deep-dive-guide-to-billing,https://help.expensify.com/articles/expensify-classic/expensify-billing/Billing-Overview https://community.expensify.com/discussion/7231/how-to-export-invoices-to-netsuite,https://help.expensify.com/articles/new-expensify/connections/netsuite/Connect-to-NetSuite#export-invoices-to From 90900d4a75acb97c411ea7aa352f642c7cfb57e1 Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 11:53:52 -0400 Subject: [PATCH 2/6] Use a file to upload redirects --- .github/scripts/createHelpRedirects.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index 4ce3d0753f58..c352dce47a9f 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -83,6 +83,9 @@ done | jq -n '. |= [inputs]') info "Adding redirects for $PUT_JSON" +# Dump $PUT_JSON into a file otherwise the curl request below will fail with too many arguments +echo $PUT_JSON > redirects.json + # We use PUT here instead of POST so that we replace the entire list in place. This has many benefits: # 1. We don't have to check if items are already in the list, allowing this script to run faster # 2. We can support deleting redirects this way by simply removing them from the list @@ -93,7 +96,7 @@ info "Adding redirects for $PUT_JSON" PUT_RESULT=$(curl -s --request PUT --url "https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/rules/lists/$LIST_ID/items" \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer $CLOUDFLARE_LIST_TOKEN" \ - --data "$PUT_JSON") + --data-binary @redirects.json) checkCloudflareResult "$PUT_RESULT" OPERATION_ID=$(echo "$PUT_RESULT" | jq -r .result.operation_id) From 0170b04ffe2c5a0bb25e8dfb99d1ca3096ec3f67 Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 11:54:24 -0400 Subject: [PATCH 3/6] bash style --- .github/scripts/createHelpRedirects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index c352dce47a9f..0322e921755c 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -84,7 +84,7 @@ done | jq -n '. |= [inputs]') info "Adding redirects for $PUT_JSON" # Dump $PUT_JSON into a file otherwise the curl request below will fail with too many arguments -echo $PUT_JSON > redirects.json +echo "$PUT_JSON" > redirects.json # We use PUT here instead of POST so that we replace the entire list in place. This has many benefits: # 1. We don't have to check if items are already in the list, allowing this script to run faster From d145123a4dbb774c83697827cea5933a8e20eb1c Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 12:42:32 -0400 Subject: [PATCH 4/6] Move validation to verify script --- .github/scripts/createHelpRedirects.sh | 26 ---------------- .github/scripts/verifyRedirect.sh | 42 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.github/scripts/createHelpRedirects.sh b/.github/scripts/createHelpRedirects.sh index 0322e921755c..1425939ff3ec 100755 --- a/.github/scripts/createHelpRedirects.sh +++ b/.github/scripts/createHelpRedirects.sh @@ -27,32 +27,6 @@ function checkCloudflareResult { declare -a ITEMS_TO_ADD while read -r line; do - # Split each line of the file into a source and destination so we can sanity check - # and compare against the current list. - read -r -a LINE_PARTS < <(echo "$line" | tr ',' ' ') - SOURCE_URL=${LINE_PARTS[0]} - DEST_URL=${LINE_PARTS[1]} - - # Make sure the format of the line is as execpted. - if [[ "${#LINE_PARTS[@]}" -gt 2 ]]; then - error "Found a line with more than one comma: $line" - exit 1 - fi - - # Basic sanity checking to make sure that the source and destination are in expected - # subdomains. - if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]]; then - error "Found source URL that is not a communityDot or helpDot URL: $SOURCE_URL" - exit 1 - fi - - if ! [[ $DEST_URL =~ ^https://(help|use|integrations)\.expensify\.com|^https://www\.expensify\.org ]]; then - error "Found destination URL that is not a supported URL: $DEST_URL" - exit 1 - fi - - info "Source: $SOURCE_URL and destination: $DEST_URL appear to be formatted correctly." - ITEMS_TO_ADD+=("$line") # This line skips the first line in the csv because the first line is a header row. diff --git a/.github/scripts/verifyRedirect.sh b/.github/scripts/verifyRedirect.sh index b8942cd5b23d..98a1b8560f63 100755 --- a/.github/scripts/verifyRedirect.sh +++ b/.github/scripts/verifyRedirect.sh @@ -3,7 +3,10 @@ # HelpDot - Verifies that redirects.csv does not have any duplicates # Duplicate sourceURLs break redirection on cloudflare pages +source scripts/shellUtils.sh + declare -r REDIRECTS_FILE="docs/redirects.csv" +declare -a ITEMS_TO_ADD declare -r RED='\033[0;31m' declare -r GREEN='\033[0;32m' @@ -22,5 +25,44 @@ if [[ DETECT_CYCLE_EXIT_CODE -eq 1 ]]; then exit 1 fi +while read -r line; do + # Split each line of the file into a source and destination so we can sanity check + # and compare against the current list. + read -r -a LINE_PARTS < <(echo "$line" | tr ',' ' ') + SOURCE_URL=${LINE_PARTS[0]} + DEST_URL=${LINE_PARTS[1]} + + # Make sure the format of the line is as execpted. + if [[ "${#LINE_PARTS[@]}" -gt 2 ]]; then + error "Found a line with more than one comma: $line" + exit 1 + fi + + # Basic sanity checking to make sure that the source and destination are in expected + # subdomains. + if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]]; then + error "Found source URL that is not a communityDot or helpDot URL: $SOURCE_URL" + exit 1 + fi + + if ! [[ $DEST_URL =~ ^https://(help|use|integrations)\.expensify\.com|^https://www\.expensify\.org ]]; then + error "Found destination URL that is not a supported URL: $DEST_URL" + exit 1 + fi + + info "Source: $SOURCE_URL and destination: $DEST_URL appear to be formatted correctly." + + ITEMS_TO_ADD+=("$line") + +# This line skips the first line in the csv because the first line is a header row. +done <<< "$(tail +2 $REDIRECTS_FILE)" + +# Sanity check that we should actually be running this and we aren't about to delete +# every single redirect. +if [[ "${#ITEMS_TO_ADD[@]}" -lt 1 ]]; then + error "No items found to add, why are we running?" + exit 1 +fi + echo -e "${GREEN}The redirects.csv is valid!${NC}" exit 0 From aec03c3be215fd24bb0482f315ed84031e5292a8 Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 12:46:03 -0400 Subject: [PATCH 5/6] Check for # in URL --- .github/scripts/verifyRedirect.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/scripts/verifyRedirect.sh b/.github/scripts/verifyRedirect.sh index 98a1b8560f63..abc853230c35 100755 --- a/.github/scripts/verifyRedirect.sh +++ b/.github/scripts/verifyRedirect.sh @@ -40,10 +40,10 @@ while read -r line; do # Basic sanity checking to make sure that the source and destination are in expected # subdomains. - if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]]; then - error "Found source URL that is not a communityDot or helpDot URL: $SOURCE_URL" - exit 1 - fi + if ! [[ $SOURCE_URL =~ ^https://(community|help)\.expensify\.com ]] || [[ $SOURCE_URL =~ \# ]]; then + error "Found source URL that is not a communityDot or helpDot URL, or contains a '#': $SOURCE_URL" + exit 1 +fi if ! [[ $DEST_URL =~ ^https://(help|use|integrations)\.expensify\.com|^https://www\.expensify\.org ]]; then error "Found destination URL that is not a supported URL: $DEST_URL" From c41ff7ede65b945616ca08658abbb97d917b0740 Mon Sep 17 00:00:00 2001 From: Justin Persaud Date: Thu, 22 Aug 2024 16:22:40 -0400 Subject: [PATCH 6/6] Update .github/scripts/verifyRedirect.sh Co-authored-by: Carlos Martins --- .github/scripts/verifyRedirect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/verifyRedirect.sh b/.github/scripts/verifyRedirect.sh index abc853230c35..3d96ba17a799 100755 --- a/.github/scripts/verifyRedirect.sh +++ b/.github/scripts/verifyRedirect.sh @@ -32,7 +32,7 @@ while read -r line; do SOURCE_URL=${LINE_PARTS[0]} DEST_URL=${LINE_PARTS[1]} - # Make sure the format of the line is as execpted. + # Make sure the format of the line is as expected. if [[ "${#LINE_PARTS[@]}" -gt 2 ]]; then error "Found a line with more than one comma: $line" exit 1