Skip to content

Add: Now you can add playlists using link #1

Add: Now you can add playlists using link

Add: Now you can add playlists using link #1

name: Notify Translators on Translation Changes
on:
push:
paths:
- 'lib/localization/**'
jobs:
notify-translators:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
- name: Get the list of changed files
id: changes
run: |
# Get the number of parents for the commit
PARENT_COUNT=$(git rev-list --count ${{ github.sha }}^@ 2>/dev/null || echo 0)
if [ "$PARENT_COUNT" -eq 1 ]; then
# Single parent, perform a normal diff against the parent
git diff --name-only ${{ github.sha }}^ ${{ github.sha }} | grep 'lib/localization/' > /tmp/changed_files.txt
elif [ "$PARENT_COUNT" -gt 1 ]; then
# Merge commit, diff against all parents
git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep 'lib/localization/' > /tmp/changed_files.txt
else
# No parent (initial commit or cherry-pick without parent in current branch), list changes in the current commit
git diff --name-only ${{ github.sha }} | grep 'lib/localization/' > /tmp/changed_files.txt
fi
# Check if there are any changed files
if [ ! -s /tmp/changed_files.txt ]; then
echo "No translation files were changed."
exit 0
fi
- name: Load Translator Info
id: load_translators
run: |
# Load the translator mapping from the JSON file into a temporary file
cp translators.json /tmp/translators.json
- name: Notify Translators
run: |
# Initialize a message variable
MESSAGE="The following translations have been updated:\n"
TRANSLATORS_NOTIFIED=""
# Read the changed files from the temporary file
CHANGED_FILES=$(cat /tmp/changed_files.txt)
# Loop through each changed file
while IFS= read -r FILE; do
# Get just the filename (e.g., app_es.arb from lib/localization/app_es.arb)
FILE_BASENAME=$(basename "$FILE")
# Use jq to find the translator for the changed file
TRANSLATOR=$(jq -r ".\"$FILE_BASENAME\" // \"No translator assigned\"" /tmp/translators.json)
# If a translator exists for this file, accumulate the message
if [ "$TRANSLATOR" != "No translator assigned" ]; then
TRANSLATORS_NOTIFIED="${TRANSLATORS_NOTIFIED} @${TRANSLATOR},"
MESSAGE="${MESSAGE} - '$FILE_BASENAME'\n"
fi
done < /tmp/changed_files.txt
# Check if any translators were notified
if [ -n "$TRANSLATORS_NOTIFIED" ]; then
# Remove the trailing comma
TRANSLATORS_NOTIFIED="${TRANSLATORS_NOTIFIED%,}"
# Post a single comment on the commit
response=$(curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"body\": \"${TRANSLATORS_NOTIFIED}\n${MESSAGE}\"}" \
https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/comments)
# Check if the notification was sent successfully
if [[ "$response" == *"created_at"* ]]; then
echo "Notification sent successfully."
else
echo "Failed to send notification. Response: $response"
fi
else
echo "No translators to notify."
fi