-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a66906e
commit 2c6f6bc
Showing
1 changed file
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/bin/bash | ||
|
||
# Define the source and target repositories | ||
TARGET_REPOS=("https://github.com/nammayatri/nammayatri") | ||
|
||
# Function to create a Pull Request | ||
create_pull_request() { | ||
local target_repo="$TARGET_REPOS" | ||
local target_repo_name="$(basename "$target_repo")" | ||
local staged_files="$(git diff --cached --name-only)" | ||
declare -a staged_files_array | ||
|
||
# Read each line from the staged_files variable and add it to the array | ||
while IFS= read -r line; do | ||
staged_files_array+=("$line") | ||
done <<< "$staged_files" | ||
echo $target_repo_name | ||
if [ -d "$target_repo_name" ]; then | ||
# If the directory already exists, update the existing clone | ||
cd "$target_repo_name" || exit | ||
git pull origin adding-script | ||
else | ||
# If the directory doesn't exist, clone the repository | ||
git clone "$target_repo" | ||
cd "$target_repo_name" || exit | ||
fi | ||
echo "Current working directory: $(pwd)" | ||
# Create a new branch | ||
branch_name="feature/update-from-asset-stor" | ||
git checkout -b "$branch_name" | ||
|
||
# Pull changes from the source repository | ||
git pull origin --rebase adding-script # --allow-unrelated-histories | ||
|
||
# echo "$staged_files" | ||
|
||
#!/bin/bash | ||
#!/bin/bash | ||
|
||
# Get the list of staged files | ||
# Convert the newline-separated string into an array | ||
# Initialize an empty array | ||
|
||
|
||
allowed_extensions=("png" "jpg" "xml" "json") | ||
filestobeadded=() | ||
# Loop through the array of staged files and print each element | ||
for file in "${staged_files_array[@]}"; do | ||
extension="${file##*.}" | ||
# Check if the file's extension is allowed | ||
if [[ " ${allowed_extensions[@]} " =~ " $extension " ]]; then | ||
# Replace occurrences of '../' with an empty string | ||
# echo "$file" | ||
source_path="$file" | ||
# Save the current value of IFS | ||
OLD_IFS=$IFS | ||
|
||
# Set the delimiter to "/" | ||
IFS="/" | ||
|
||
# Split the path into an array | ||
read -ra path_components <<< "$source_path" | ||
|
||
# Restore the value of IFS | ||
IFS=$OLD_IFS | ||
# echo "directory ${path_components[1]} , subdirectory ${path_components[2]} , image/lottie -> ${path_components[3]}, assetName -> ${path_components[4]}}" | ||
|
||
|
||
|
||
if [[ ${path_components[3]} == "images" ]]; then | ||
file_type="drawable" | ||
else | ||
file_type="raw" | ||
fi | ||
|
||
if [[ ${path_components[2]} == "driver" ]]; then | ||
sub_dir="${path_components[1]}Partner" | ||
else | ||
sub_dir="${path_components[1]}" | ||
fi | ||
updated_path="Frontend/android-native/app/src/${path_components[2]}/$sub_dir/res/$file_type/${path_components[4]}" | ||
# echo "Inside filesTiBeAdded $updated_path" | ||
filestobeadded+=("$source_path:$updated_path") | ||
|
||
fi | ||
# Print the components of the path | ||
done | ||
|
||
|
||
|
||
# Loop through the filestobeadded array and print each element | ||
|
||
# Define the source path | ||
|
||
|
||
# echo "fileToBeAdde -> $filestobeadded" | ||
# Copy the asset to the local directory | ||
# cp "$staged_files" . | ||
# Stage and commit the changes | ||
echo "PWD :: $(pwd)" | ||
for item in "${filestobeadded[@]}"; do | ||
source_path="${item%:*}" | ||
updated_path="${item#*:}" | ||
echo "updated path $updated_path" | ||
cp "../$source_path" "$updated_path" | ||
done | ||
git add . | ||
git commit -m "Add new asset from asset store" | ||
|
||
# # Push changes to the target repository | ||
git push origin "$branch_name" | ||
# # Open the GitHub page to create a pull request | ||
pull_request_url="${target_repo}/compare/adding-script...${branch_name}" | ||
echo "Pull request URL: $pull_request_url" | ||
# xdg-open "$pull_request_url" # Open in browser | ||
} | ||
|
||
|
||
# Loop through target repositories and create pull requests | ||
for target_repo in "${TARGET_REPOS[@]}"; do | ||
create_pull_request "$target_repo" "$target_repo" | ||
done | ||
|
||
echo "Pull requests created successfully." |