Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b34cf3

Browse files
authored
chore: added script to migrate apps to redis (#41373)
## Description> [!TIP] > _Add a TL;DR when the description is longer than 500 words orextremely technical (helps the content, marketing, and DevRel team)._>> _Please also include relevant motivation and context. List anydependencies that are required for this change. Add links to Notion,Figma or any other documents that might be relevant to the PR._Fixes #`Issue Number` _or_ Fixes `Issue URL`> [!WARNING] > _If no issue exists, please create an issue first, and check with themaintainers if the issue is valid._## Automation/ok-to-test tags=""### 🔍 Cypress test results<!-- This is an auto-generated comment: Cypress test results -->> [!CAUTION] > If you modify the content in this section, you are likely to disruptthe CI result for your PR.<!-- end of auto-generated comment: Cypress test results -->## CommunicationShould the DevRel and Marketing teams inform users about this change?- [ ] Yes- [ ] No<!-- This is an auto-generated comment: release notes by coderabbit.ai-->## Summary by CodeRabbit* **New Features*** Enhanced branch information management system to improve performanceand reliability of git repository operations during deployment.<!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent3788dee commit5b34cf3

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env bash
2+
3+
# Simple logging helpers
4+
log_ts() {
5+
date'+%Y-%m-%dT%H:%M:%S%z'
6+
}
7+
8+
log_info() {
9+
printf'[%s] [INFO] %s\n'"$(log_ts)""$*">&1
10+
}
11+
12+
log_warn() {
13+
printf'[%s] [WARN] %s\n'"$(log_ts)""$*">&1
14+
}
15+
16+
log_error() {
17+
printf'[%s] [ERROR] %s\n'"$(log_ts)""$*">&2
18+
}
19+
20+
upload_branches_to_redis_hash() {
21+
# get all local branches and their latest commit sha
22+
local directory_path="$1"
23+
local redis_url="$2"
24+
local key_value_pair_key="$3"
25+
26+
local failure=0
27+
local branches=$(git -C"$directory_path" for-each-ref --format='"%(refname:short)" %(objectname:short)' refs/heads/)|| failure=1
28+
29+
if [[$failure-eq 1 ]];then
30+
log_error"Failed to get branches for repository:$directory_path"
31+
return 1
32+
fi
33+
34+
log_info"Preparing to upload branch store. Current branches:$branches"
35+
redis-exec"$redis_url" DEL"$key_value_pair_key"
36+
redis-exec"$redis_url" HSET"$key_value_pair_key"$branches
37+
}
38+
39+
# Finds git repositories under a given directory (up to 4 levels deep)
40+
# Usage: find_git_repos <directory>
41+
# - cd's into the directory
42+
# - finds all ".git" folders up to 4 levels deep
43+
# - collects their repository roots into an array
44+
# - prints each repository root, one per line
45+
find_git_repos() {
46+
local search_dir="$1"
47+
local redis_url="$2"
48+
local max_depth=4
49+
50+
if [[$#-eq 3 ]];then
51+
log_info"Max depth provided:$3"
52+
max_depth="$3"
53+
fi
54+
55+
if [[-z"${search_dir:-}" ]];then
56+
log_warn"Usage: find_git_repos <directory>"
57+
return 1
58+
fi
59+
60+
if [[!-d"$search_dir" ]];then
61+
log_warn"Directory '$search_dir' does not exist"
62+
return 1
63+
fi
64+
65+
(
66+
cd"$search_dir"
67+
local found_any_repo=false
68+
69+
# Find .git directories up to depth 4 and process each one immediately
70+
while IFS=read -r gitdir;do
71+
# Strip the trailing '/.git' and leading './'
72+
local base_root="${gitdir%/.git}"
73+
base_root="${base_root#./}"
74+
75+
# Process this repository immediately
76+
local key_value_pair_key="branchStore=${base_root}"
77+
log_info"Upload sequence for repository :${base_root}"
78+
upload_branches_to_redis_hash"$base_root""$redis_url""$key_value_pair_key"
79+
80+
found_any_repo=true
81+
done<<(find. -maxdepth$max_depth -type d -name .git2>/dev/null)
82+
83+
if [["$found_any_repo"==false ]];then
84+
log_warn"No git repositories found under '$search_dir' (max depth$max_depth)"
85+
return 0
86+
fi
87+
)
88+
}
89+
90+
# Redis CLI wrapper that handles different URL schemes
91+
# Usage: redis-exec <redis-url> [redis-cli-args...]
92+
# Supports: redis://, rediss://, redis-cluster://
93+
redis-exec() {
94+
local url="$1"
95+
96+
if [[-z"$url" ]];then
97+
log_error"redis-exec: missing Redis URL"
98+
log_error"Usage: redis-exec <redis-url> [redis-cli-args...]"
99+
return 1
100+
fi
101+
102+
case"$url"in
103+
redis://*|rediss://*)
104+
# Standard Redis URL - pass directly to redis-cli -u
105+
redis-cli -u"$url""${@:2}"
106+
;;
107+
redis-cluster://*)
108+
# Cluster URL - extract components and use cluster mode
109+
local stripped="${url#redis-cluster://}"
110+
111+
# Split into authority and path parts
112+
local authority="${stripped%%/*}"
113+
local path_part="${stripped#*/}"
114+
if [["$path_part"=="$stripped" ]];then
115+
path_part=""# No path present
116+
fi
117+
118+
# Extract credentials from authority (user:pass@host:port)
119+
local credentials=""
120+
local host_port="$authority"
121+
if [["$authority"==*"@"* ]];then
122+
credentials="${authority%%@*}"
123+
host_port="${authority##*@}"
124+
fi
125+
126+
# Parse credentials
127+
local username=""
128+
local password=""
129+
if [[-n"$credentials" ]];then
130+
if [["$credentials"==*":"* ]];then
131+
username="${credentials%%:*}"
132+
password="${credentials##*:}"
133+
else
134+
password="$credentials"# Only password provided
135+
fi
136+
fi
137+
138+
# Extract host and port
139+
local host="${host_port%:*}"
140+
local port="${host_port##*:}"
141+
142+
# If no port specified, default to 6379
143+
if [["$port"=="$host" ]];then
144+
port="6379"
145+
fi
146+
147+
# Extract database number from path
148+
local database=""
149+
if [[-n"$path_part"&&"$path_part"=~ ^[0-9]+(\?.*)?$ ]];then
150+
database="${path_part%%\?*}"# Remove query params if present
151+
fi
152+
153+
# Build redis-cli command
154+
local cmd_args=("-c""-h""$host""-p""$port")
155+
156+
# Add authentication if present
157+
if [[-n"$username"&&-n"$password" ]];then
158+
cmd_args+=("--user""$username""--pass""$password")
159+
elif [[-n"$password" ]];then
160+
cmd_args+=("-a""$password")
161+
fi
162+
163+
# Add database selection if specified
164+
if [[-n"$database" ]];then
165+
cmd_args+=("-n""$database")
166+
fi
167+
168+
# Add remaining arguments
169+
cmd_args+=("${@:2}")
170+
171+
redis-cli"${cmd_args[@]}"
172+
;;
173+
*)
174+
log_error"redis-exec: unsupported URL scheme:$url"
175+
log_error"Supported schemes: redis://, rediss://, redis-cluster://"
176+
return 1
177+
;;
178+
esac
179+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp