-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_migration.sh
executable file
·113 lines (93 loc) · 3.53 KB
/
run_migration.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Default settings for start_from and Jira done ID
START_FROM="0"
JIRA_DONE_ID="3"
# Parse command line arguments
while getopts p:u:x:s:r:g:m: flag
do
case "${flag}" in
p) JIRA_PROJECT=${OPTARG};;
u) JIRA_URL=${OPTARG};;
x) XML_PATH=${OPTARG};;
s) SECURITY_REPO=${OPTARG};;
r) DEFAULT_REPO=${OPTARG};;
g) GITHUB_ACCOUNT=${OPTARG};;
m) MODE=${OPTARG};;
esac
done
# Validate and export GITHUB_ACCOUNT
if [ -z "$GITHUB_ACCOUNT" ]; then
echo "Error: GitHub account name is required. Use the -g flag to specify the account name."
exit 1
fi
export GITHUB_ACCOUNT="$GITHUB_ACCOUNT"
if [ -z "$DEFAULT_REPO" ]; then
echo "Error: Default repository name is required. Use the -r flag to specify it."
exit 1
fi
if [ -z "$SECURITY_REPO" ]; then
echo "Error: Security repository name is required. Use the -s flag to specify it."
exit 1
fi
export DEFAULT_REPO="$DEFAULT_REPO"
export SECURITY_REPO="$SECURITY_REPO"
# Validate the MODE flag
if [ "$MODE" != "simulation" ] && [ "$MODE" != "migration" ]; then
echo "Error: Invalid mode. Use -m simulation or -m migration."
exit 1
fi
# Display the selected mode
echo "Selected Mode: $MODE"
# Export the mode as an environment variable for use in main.py
export MIGRATION_MODE="$MODE"
# Check if GITHUB_ACCOUNT is missing and print an error
if [ -z "$GITHUB_ACCOUNT" ]; then
echo "Error: GitHub account name is required. Use the -g flag to specify the account name."
exit 1
fi
# If XML_PATH is not provided, auto-detect XML files in the current directory
if [ -z "$XML_PATH" ]; then
echo "No XML path provided. Searching for XML files in the current directory..."
XML_FILES=$(find "$(pwd)" -maxdepth 1 -name "*.xml")
if [ -z "$XML_FILES" ]; then
echo "No XML files found in the current directory. Please ensure the XML file is in the same directory as this script."
exit 1
fi
XML_PATH="$XML_FILES"
fi
# Display the provided values
echo "Security Repo: https://github.com/$GITHUB_ACCOUNT/$SECURITY_REPO"
echo "Default Repo: https://github.com/$GITHUB_ACCOUNT/$DEFAULT_REPO"
echo "GitHub Account: $GITHUB_ACCOUNT"
echo "Jira Project: $JIRA_PROJECT"
echo "XML Paths: $XML_PATH"
echo "Done Status ID: $JIRA_DONE_ID"
echo "Start from: $START_FROM"
# Request GitHub PAT from user input and display it for confirmation
read -p "Enter your GitHub Personal Access Token (PAT): " GITHUB_PAT
echo "GitHub PAT: $GITHUB_PAT" # Display PAT to ensure it's correctly entered
# Set environment variables
export JIRA_MIGRATION_JIRA_PROJECT_NAME="$JIRA_PROJECT"
export JIRA_MIGRATION_JIRA_DONE_ID="$JIRA_DONE_ID"
export JIRA_MIGRATION_JIRA_URL="$JIRA_URL"
export JIRA_MIGRATION_FILE_PATHS="$XML_PATH"
export SECURITY_REPO_URL="https://github.com/$GITHUB_ACCOUNT/$SECURITY_REPO"
export DEFAULT_REPO_URL="https://github.com/$GITHUB_ACCOUNT/$DEFAULT_REPO"
export JIRA_MIGRATION_GITHUB_ACCESS_TOKEN="$GITHUB_PAT"
# Print the environment variables for debugging
echo "SECURITY_REPO_URL: $SECURITY_REPO_URL"
echo "DEFAULT_REPO_URL: $DEFAULT_REPO_URL"
echo "GITHUB_ACCOUNT: $GITHUB_ACCOUNT"
# Activate or create the virtual environment
if [ ! -d "jira_migration_venv" ]; then
echo "Creating virtual environment..."
python3 -m venv jira_migration_venv
fi
echo "Activating existing virtual environment..."
source jira_migration_venv/bin/activate
# Install dependencies
echo "Installing dependencies..."
pip install -r requirements.txt
# Run the Python migration script
echo "Running migration script in $MODE mode..."
python3 main.py