From 3bb63ccac5f6fbbefdc848df1ada1a365c0c9cd9 Mon Sep 17 00:00:00 2001 From: Petar Nikov Date: Thu, 10 Oct 2024 19:09:49 +0300 Subject: [PATCH 1/2] Fixing find_log_errors.js to incorporate the changes from the bash script. Deleting unused bash scripts and updating the documentation. --- README.md | 4 +- check_migrations.js | 1 + check_migrations.sh | 95 --------------------------------------------- find_log_errors.js | 13 ++++--- find_log_errors.sh | 82 -------------------------------------- package-lock.json | 5 +-- package.json | 5 +-- 7 files changed, 15 insertions(+), 190 deletions(-) mode change 100644 => 100755 check_migrations.js delete mode 100755 check_migrations.sh delete mode 100755 find_log_errors.sh diff --git a/README.md b/README.md index 2621481..75c757b 100644 --- a/README.md +++ b/README.md @@ -1214,7 +1214,7 @@ Checks the downloaded migration log files to see which ones completed successful #### Usage ``` -./check_migrations.sh [-d [directory]] [-l [log_file]] +npx check_migrations.js [-d [directory]] [-l [log_file]] ``` #### Arguments @@ -1229,7 +1229,7 @@ Examines a directory containing all the log files after starting migrations with #### Usage ``` -./find_log_errors.sh [-d [directory]] [-l [log_file]] +npx find_log_errors.js [-d [directory]] [-l [log_file]] ``` #### Arguments diff --git a/check_migrations.js b/check_migrations.js old mode 100644 new mode 100755 index 3effe47..5bda881 --- a/check_migrations.js +++ b/check_migrations.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node import fs from 'fs'; import path from 'path'; diff --git a/check_migrations.sh b/check_migrations.sh deleted file mode 100755 index 092afa9..0000000 --- a/check_migrations.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash - -# Function to print usage -print_usage() { - echo "Usage: $0 [-d log_directory] [-l log_file]" - echo "This script checks the downloaded migration log files to see which ones completed successfully and how long the migration took." - echo "-d [log_directory] Log directory path (optional, default: current working directory)" - echo "-l [log_file] Log file path (optional, default: check_migrations.log)" -} - -# Check if a directory is provided -LOG_DIRECTORY="${1:-$PWD}" - -# Check options -while getopts "d:l:h" opt; do - case "${opt}" in - d) - LOG_DIRECTORY=${OPTARG} - ;; - l) - LOG_FILE=${OPTARG} - ;; - h) - print_usage - exit 0 - ;; - *) - print_usage - exit 1 - ;; - esac -done - -# Set the log directory to the current working directory if not provided -LOG_DIRECTORY="${LOG_DIRECTORY:-$PWD}" -# Log file -LOG_FILE_NAME="check_migrations.log" -LOG_FILE="${LOG_FILE:-LOG_FILE_NAME}" - -# Function to log messages -log() { - local message="$1" - - # Log to the log file - echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" >> "$LOG_FILE" - - # Log to the console - echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" -} - -# Check if log files directory exists -if [ ! -d "$LOG_DIRECTORY" ]; then - log "Error: Directory '$LOG_DIRECTORY' not found." - print_usage - exit 1 -fi - -# Check if log files exist in the specified directory -if [ ! "$(ls "${LOG_DIRECTORY}"/migration-log-*.log 2>/dev/null)" ]; then - log "Error: No migration log files found in the directory '${LOG_DIRECTORY}'." - print_usage - exit 1 -fi - -log "Checking migration logs in '${LOG_DIRECTORY}' for completion status..." - -# Count the number of migrations started -MIGRATION_STARTED_COUNT=$(grep "Migration started" "${LOG_DIRECTORY}"/migration-log-*.log | wc -l) -if [ "${MIGRATION_STARTED_COUNT}" -eq 0 ]; then - log "Error: No migrations started found in the log files." - exit 1 -fi - -# Count the number of migrations completed -MIGRATION_COMPLETED_COUNT=$(grep "Migration complete" "${LOG_DIRECTORY}"/migration-log-*.log | wc -l) - -log "${MIGRATION_COMPLETED_COUNT}/${MIGRATION_STARTED_COUNT} migrations completed." - -if [ "${MIGRATION_STARTED_COUNT}" -ne "${MIGRATION_COMPLETED_COUNT}" ]; then - log "Error: Not all migrations completed." - exit 1 -fi - -log "Checking migration duration..." - -# Get the start and end times of the migration -MIGRATION_STARTED_TIME=$(sed -n "s/^\[\(.*\)\] INFO -- Migration started.\+$/\1/p" "${LOG_DIRECTORY}"/migration-log-*.log | sort | head -1) -MIGRATION_ENDED_TIME=$(sed -n "s/^\[\(.*\)\] INFO -- Migration complete/\1/p" "${LOG_DIRECTORY}"/migration-log-*.log | sort | tail -n 1) - -if [ -z "${MIGRATION_STARTED_TIME}" ] || [ -z "${MIGRATION_ENDED_TIME}" ]; then - log "Error: Unable to determine migration start or end time." - exit 1 -fi - -log "Migration started at ${MIGRATION_STARTED_TIME} and ended at ${MIGRATION_ENDED_TIME}" diff --git a/find_log_errors.js b/find_log_errors.js index 625c741..6ccd82a 100755 --- a/find_log_errors.js +++ b/find_log_errors.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node import fs from 'fs'; import path from 'path'; @@ -77,10 +78,12 @@ logFiles.forEach(logFile => { const errorMatch = verboseLogFileContent.match(/\[ERROR\] (.*)/); const error = errorMatch ? errorMatch[1] : ''; - const sourceOrg = logFileContent.match(/GITHUB SOURCE ORG: ([^\s]*)/)?.[1] || ''; - const sourceRepo = logFileContent.match(/SOURCE REPO: ([^\s]*)/)?.[1] || ''; - const destinationOrg = logFileContent.match(/GITHUB TARGET ORG: ([^\s]*)/)?.[1] || ''; - const destinationRepo = logFileContent.match(/TARGET REPO: ([^\s]*)/)?.[1] || ''; + if (error) { + const sourceOrg = logFileContent.match(/GITHUB SOURCE ORG: ([^\s]*)/)?.[1] || ''; + const sourceRepo = logFileContent.match(/SOURCE REPO: ([^\s]*)/)?.[1] || ''; + const destinationOrg = logFileContent.match(/GITHUB TARGET ORG: ([^\s]*)/)?.[1] || ''; + const destinationRepo = logFileContent.match(/TARGET REPO: ([^\s]*)/)?.[1] || ''; - log(`${sourceOrg},${sourceRepo},${destinationOrg},${destinationRepo},"${error}"`); + log(`${sourceOrg},${sourceRepo},${destinationOrg},${destinationRepo},"${error}"`); + } }); diff --git a/find_log_errors.sh b/find_log_errors.sh deleted file mode 100755 index 267ba14..0000000 --- a/find_log_errors.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash - -# Function to print usage -print_usage() { - echo "Usage: $0 [-d log_directory] [-l log_file]" - echo "This script examines a directory containing all the log files after starting migrations with the GEI tool, and finds which ones failed with errors." - echo "It outputs a list of the source org, source repo, destination org, destination repo, and the error message." - echo "-d log_directory Log directory path (optional, default: current working directory)" - echo "-l log_file Log file path (optional, default: find_log_errors.log)" -} - -# Check options -while getopts "d:l:h" opt; do - case "${opt}" in - d) - LOG_DIRECTORY=${OPTARG} - ;; - l) - LOG_FILE=${OPTARG} - ;; - h) - print_usage - exit 0 - ;; - *) - print_usage - exit 1 - ;; - esac -done - -# Set the log directory to the current working directory if not provided -LOG_DIRECTORY="${LOG_DIRECTORY:-$PWD}" -# Log file -LOG_FILE_NAME="find_log_errors.log" -LOG_FILE="${LOG_FILE:-LOG_FILE_NAME}" - -# Function to log messages -log() { - local message="$1" - - # Log to the log file - echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" >> "$LOG_FILE" - - # Log to the console - echo "[$(date +'%Y-%m-%d %H:%M:%S')] $message" -} - -# Check if the log directory exists -if [ ! -d "${LOG_DIRECTORY}" ]; then - log "Error: Log directory '${LOG_DIRECTORY}' does not exist." - exit 1 -fi - -# Check if log files exist in the specified directory -if [ ! "$(ls "${LOG_DIRECTORY}"/*.octoshift.log 2>/dev/null)" ]; then - log "Error: No log files found in the directory '${LOG_DIRECTORY}'." - print_usage - exit 1 -fi - -log "Searching for errors in log files in '${LOG_DIRECTORY}'..." - -# Print the header -echo "source_org,source_repo,destination_org,destination_repo,error_message" - -for LOGFILE in $(grep -l "\[ERROR\]" ${LOG_DIRECTORY}/*.octoshift.log); do - # Get the verbose log file name - VERBOSE_LOGFILE=$(echo "${LOGFILE}" | sed "s/\.octoshift\.log/\.octoshift\.verbose\.log/") - - # Extract the error message - ERROR=$(grep "\[ERROR\]" "${VERBOSE_LOGFILE}" | sed "s/^.*\[ERROR\] \(.*\)/\1/") - - # Extract the source org, source repo, destination org, and destination repo - SOURCE_ORG=$(grep "GITHUB SOURCE ORG:" "${LOGFILE}" | sed "s/^.*GITHUB SOURCE ORG: \([^ ]*\).*$/\1/") - SOURCE_REPO=$(grep "SOURCE REPO:" "${LOGFILE}" | sed "s/^.*SOURCE REPO: \([^ ]*\).*$/\1/") - DESTINATION_ORG=$(grep "GITHUB TARGET ORG:" "${LOGFILE}" | sed "s/^.*GITHUB TARGET ORG: \([^ ]*\).*$/\1/") - DESTINATION_REPO=$(grep "TARGET REPO:" "${LOGFILE}" | sed "s/^.*TARGET REPO: \([^ ]*\).*$/\1/") - - # Print the output - log "${SOURCE_ORG},${SOURCE_REPO},${DESTINATION_ORG},${DESTINATION_REPO},\"${ERROR}\"" -done diff --git a/package-lock.json b/package-lock.json index e6e131b..361586e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,10 +26,9 @@ "prompts": "^2.4.2" }, "bin": { - "check-migrations": "check_migrations.sh", + "check-migrations": "node check_migrations.js", "compare-migrations": "compare_migrations.sh", - "find-log-errors": "find_log_errors.sh", - "find-log-errors-js": "find_log_errors.js", + "find-log-errors": "node find_log_errors.js", "git-migrator": "src/index.js", "migrate-secrets": "migrate_secrets.sh" }, diff --git a/package.json b/package.json index 4ce861c..186688d 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,10 @@ }, "bin": { "git-migrator": "src/index.js", - "check-migrations": "./check_migrations.sh", "compare-migrations": "./compare_migrations.sh", - "find-log-errors": "./find_log_errors.sh", "migrate-secrets": "./migrate_secrets.sh", - "find-log-errors-js": "./find_log_errors.js" + "find-log-errors": "node find_log_errors.js", + "check-migrations": "node check_migrations.js" }, "keywords": [], "author": "ModusCreate", From f4490afe6e582dca26fcaa7534ab25a7397a0153 Mon Sep 17 00:00:00 2001 From: Petar Nikov Date: Thu, 10 Oct 2024 19:12:01 +0300 Subject: [PATCH 2/2] Updating documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75c757b..8c3f2ce 100644 --- a/README.md +++ b/README.md @@ -1214,7 +1214,7 @@ Checks the downloaded migration log files to see which ones completed successful #### Usage ``` -npx check_migrations.js [-d [directory]] [-l [log_file]] +npx check-migrations [-d [directory]] [-l [log_file]] ``` #### Arguments @@ -1229,7 +1229,7 @@ Examines a directory containing all the log files after starting migrations with #### Usage ``` -npx find_log_errors.js [-d [directory]] [-l [log_file]] +npx find-log-errors [-d [directory]] [-l [log_file]] ``` #### Arguments