Skip to content

Commit

Permalink
Merge pull request #63 from crowdin/improve_pull_request_body_and_loc…
Browse files Browse the repository at this point in the history
…al_branch

improve pull request body and localization branch
  • Loading branch information
VBeytok authored Mar 15, 2021
2 parents 7619cfd + 642a48e commit ea9f379
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v2

- name: crowdin action
uses: crowdin/[email protected].20
uses: crowdin/[email protected].21
with:
upload_translations: true
download_translations: true
Expand Down
28 changes: 14 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,65 @@ inputs:
upload_sources:
description: 'Upload sources to Crowdin'
default: 'true'
required: true
required: false

# upload translations options
upload_translations:
description: 'Upload translations to Crowdin'
default: 'false'
required: true
required: false
upload_language:
description: 'Use this option to upload translations for a single specified language'
required: false
auto_approve_imported:
description: 'Automatically approves uploaded translations'
default: 'false'
required: true
required: false
import_eq_suggestions:
description: 'Defines whether to add translation if it is equal to source string in Crowdin project'
default: 'false'
required: true
required: false

# download translations options
download_translations:
description: 'Make pull request of Crowdin translations'
default: 'false'
required: true
required: false
download_language:
description: 'Use this option to download translations for a single specified language'
required: false
skip_untranslated_strings:
description: 'Skip untranslated strings in exported files (does not work with .docx, .html, .md and other document files)'
default: 'false'
required: true
required: false
skip_untranslated_files:
description: 'Omit downloading not fully downloaded files'
default: 'false'
required: true
required: false
export_only_approved:
description: 'Include approved translations only in exported files. If not combined with --skip-untranslated-strings option, strings without approval are fulfilled with the source language'
default: 'false'
required: true
required: false
push_translations:
description: 'Download translations with pushing to branch'
default: 'true'
required: true
required: false
commit_message:
description: 'Commit message for download translations'
default: 'New Crowdin translations by Github Action'
required: true
required: false
localization_branch_name:
description: 'To download translations to the specified version branch'
default: 'l10n_crowdin_action'
required: true
required: false
create_pull_request:
description: 'Create pull request after pushing to branch'
default: 'true'
required: true
required: false
pull_request_title:
description: 'The title of the new pull request'
default: 'New Crowdin translations by Github Action'
required: true
required: false
pull_request_body:
description: 'The contents of the pull request'
required: false
Expand All @@ -93,7 +93,7 @@ inputs:
dryrun_action:
description: 'Option to preview the list of managed files'
default: 'false'
required: true
required: false

# config options
project_id:
Expand Down
20 changes: 12 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ create_pull_request() {
BASE_BRANCH="${GITHUB_REF#refs/heads/}"
fi

DATA="{\"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}"
PULL_REQUESTS_DATA="{\"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}"

PULL_REQUESTS=$(echo "$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET --data "${DATA}" "${PULLS_URL}")" | jq --raw-output '.[] | .head.ref ')
PULL_REQUESTS=$(echo "$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET --data "${PULL_REQUESTS_DATA}" "${PULLS_URL}")" | jq --raw-output '.[] | .head.ref ')

if echo "$PULL_REQUESTS " | grep -q "$LOCALIZATION_BRANCH "; then
echo "PULL REQUEST ALREADY EXIST"
else
echo "CREATE PULL REQUEST"

if [ -n "$INPUT_PULL_REQUEST_BODY" ]; then
BODY=",\"body\":\"${INPUT_PULL_REQUEST_BODY}\""
BODY=",\"body\":\"${INPUT_PULL_REQUEST_BODY//$'\n'/\\n}\""
fi

DATA="{\"title\":\"${INPUT_PULL_REQUEST_TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\" ${BODY}"
PULL_RESPONSE_DATA="{\"title\":\"${INPUT_PULL_REQUEST_TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\" ${BODY}}"

PULL_RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${DATA}" "${PULLS_URL}")
PULL_RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${PULL_RESPONSE_DATA}" "${PULLS_URL}")

set +x
PULL_REQUESTS_URL=$(echo "${PULL_RESPONSE}" | jq '.html_url')
Expand All @@ -153,8 +153,8 @@ create_pull_request() {

ISSUE_URL="${REPO_URL}/issues/${PULL_REQUESTS_NUMBER}"

DATA="{\"labels\":${PULL_REQUEST_LABELS}}"
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X PATCH --data "${DATA}" "${ISSUE_URL}"
LABELS_DATA="{\"labels\":${PULL_REQUEST_LABELS}}"
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X PATCH --data "${LABELS_DATA}" "${ISSUE_URL}"
else
echo "JSON OF pull_request_labels IS INVALID: ${PULL_REQUEST_LABELS}"
fi
Expand All @@ -175,7 +175,11 @@ push_to_branch() {

git checkout "${GITHUB_REF#refs/heads/}"

git checkout -b "${LOCALIZATION_BRANCH}"
if [ -n "$(git show-ref refs/heads/${LOCALIZATION_BRANCH})" ]; then
git checkout "${LOCALIZATION_BRANCH}"
else
git checkout -b "${LOCALIZATION_BRANCH}"
fi

if [ -n "$(git status -s)" ]; then
echo "PUSH TO BRANCH ${LOCALIZATION_BRANCH}"
Expand Down

0 comments on commit ea9f379

Please sign in to comment.