Skip to content

Commit 526ecd7

Browse files
authored
Merge pull request #221 from AstrBotDevs/copilot/add-logo-to-plugin-cache
Add logo field detection and caching for plugin repositories
2 parents 7adc0f2 + cf5a01e commit 526ecd7

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

  • scripts/transform_plugin_data
    • get_github_api_info_for_repositories
    • transform_plugin_data

scripts/transform_plugin_data/get_github_api_info_for_repositories/run.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ jq -r 'to_entries[] | .value.repo // empty' original_plugins.json | while read -
182182
stars=0
183183
updated_at=""
184184
version=""
185+
logo=""
185186
status="unknown"
186187

187188
if [ "$success" = true ]; then
@@ -229,6 +230,23 @@ jq -r 'to_entries[] | .value.repo // empty' original_plugins.json | while read -
229230
fi
230231
fi
231232
done
233+
234+
# 检查logo.png是否存在
235+
logo_response=$(curl -L -s --max-time 10 --max-redirs 3 \
236+
-H "Authorization: token $PAT_TOKEN" \
237+
-H "Accept: application/vnd.github.v3+json" \
238+
-H "User-Agent: GitHub-Action-Plugin-Transformer" \
239+
"https://api.github.com/repos/$owner/$repo/contents/logo.png" 2>/dev/null || echo "{}")
240+
241+
# 检查logo.png是否存在(验证响应包含name字段且不是错误消息)
242+
# 使用单个jq调用进行验证以提高性能
243+
logo_valid=$(echo "$logo_response" | jq -r 'if .name and (.message | not) then "true" else "false" end' 2>/dev/null || echo "false")
244+
if [ "$logo_valid" = "true" ]; then
245+
# 获取默认分支
246+
default_branch=$(echo "$api_response" | jq -r '.default_branch // "main"')
247+
logo="https://raw.githubusercontent.com/$owner/$repo/$default_branch/logo.png"
248+
echo " 🖼️ 找到logo: $logo"
249+
fi
232250
fi
233251
;;
234252
301|302)
@@ -255,18 +273,20 @@ jq -r 'to_entries[] | .value.repo // empty' original_plugins.json | while read -
255273

256274
# 如果失败,尝试使用缓存数据
257275
if [ "$status" != "success" ] && [ "$HAS_EXISTING_CACHE" = "true" ]; then
258-
cached_data=$(jq -r --arg url "$repo_url" '.data // {} | to_entries[] | select(.value.repo == $url) | .value | {stars: .stars, updated_at: .updated_at, version: .version}' existing_cache.json 2>/dev/null || echo "{}")
276+
cached_data=$(jq -r --arg url "$repo_url" '.data // {} | to_entries[] | select(.value.repo == $url) | .value | {stars: .stars, updated_at: .updated_at, version: .version, logo: .logo}' existing_cache.json 2>/dev/null || echo "{}")
259277

260278
if [ "$cached_data" != "{}" ] && [ "$cached_data" != "" ]; then
261279
cached_stars=$(echo "$cached_data" | jq -r '.stars // 0')
262280
cached_updated=$(echo "$cached_data" | jq -r '.updated_at // ""')
263281
cached_version=$(echo "$cached_data" | jq -r '.version // ""')
282+
cached_logo=$(echo "$cached_data" | jq -r '.logo // ""')
264283

265284
if [ "$cached_stars" != "0" ] || [ "$cached_updated" != "" ]; then
266285
echo " 🔄 使用缓存数据: Stars: $cached_stars"
267286
stars="$cached_stars"
268287
updated_at="$cached_updated"
269288
version="$cached_version"
289+
logo="$cached_logo"
270290
status="cached"
271291
fi
272292
fi
@@ -277,8 +297,9 @@ jq -r 'to_entries[] | .value.repo // empty' original_plugins.json | while read -
277297
--arg stars "$stars" \
278298
--arg updated "$updated_at" \
279299
--arg version "$version" \
300+
--arg logo "$logo" \
280301
--arg status "$status" \
281-
'. + {($url): {stars: ($stars | tonumber), updated_at: $updated, version: $version, status: $status}}' \
302+
'. + {($url): {stars: ($stars | tonumber), updated_at: $updated, version: $version, logo: $logo, status: $status}}' \
282303
repo_info.json > temp_repo_info.json && mv temp_repo_info.json repo_info.json
283304

284305
# 添加基础延迟避免API限制

scripts/transform_plugin_data/transform_plugin_data/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ map({
3131
stars: .stars,
3232
updated_at: .updated_at,
3333
version: (if .version != "" then .version else "1.0.0" end)
34-
})
34+
} +
35+
# 仅当logo存在且不为空时添加logo字段
36+
(if .logo and .logo != "" then { logo: .logo } else {} end))
3537
else
3638
{
3739
stars: 0,

0 commit comments

Comments
 (0)