feat(gitea,download): allow attachments filtering with regex

This commit is contained in:
wpetit 2023-03-29 14:35:00 +02:00
parent 199b0bf5d1
commit 21c7fb0e61
1 changed files with 10 additions and 2 deletions

View File

@ -9,6 +9,7 @@ GITEA_DOWNLOAD_USERNAME=${GITEA_DOWNLOAD_USERNAME}
GITEA_DOWNLOAD_PASSWORD=${GITEA_DOWNLOAD_PASSWORD}
GITEA_DOWNLOAD_RELEASE_NAME=${GITEA_DOWNLOAD_RELEASE_NAME:-latest}
GITEA_DOWNLOAD_TARGET_DIRECTORY=${GITEA_DOWNLOAD_TARGET_DIRECTORY:-gitea-dl}
GITEA_DOWNLOAD_ATTACHMENTS_FILTER="${GITEA_DOWNLOAD_ATTACHMENTS_FILTER:-.*}"
function check_dependencies {
assert_command_available 'curl'
@ -106,6 +107,7 @@ function gitea_api {
curl -L \
--fail \
--ipv4 \
-k \
-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" \
${args} \
"$GITEA_DOWNLOAD_BASE_URL/api/v1$path"
@ -120,6 +122,7 @@ function gitea_download {
--ipv4 \
-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" \
--output "$output" \
$GITEA_DOWNLOAD_CURL_ARGS \
"$GITEA_DOWNLOAD_BASE_URL/attachments/$attachment_id"
}
@ -141,10 +144,15 @@ function download_release_files {
mkdir -p "$GITEA_DOWNLOAD_TARGET_DIRECTORY"
local attachment_uuids=$(echo $assets | jq -r '.[].uuid')
for uuid in $attachment_uuids; do
local filename=$(echo $assets | jq -r --arg uuid "$uuid" '. | map(select( .uuid == $uuid)) | .[0].name')
if [[ "$filename" =~ $GITEA_DOWNLOAD_ATTACHMENTS_FILTER ]]; then
echo "Downloading attachment '$filename'"
gitea_download "$uuid" "$GITEA_DOWNLOAD_TARGET_DIRECTORY/$filename"
else
echo "Ignoring attachment '$filename'"
fi
done
}