Skip to content

Commit

Permalink
Merge pull request #26 from crowdin/add_commit_message_and_pr_info
Browse files Browse the repository at this point in the history
add options commit_message, pull_request_title, pull_request_body
  • Loading branch information
VBeytok authored Jul 20, 2020
2 parents 482cbf4 + 627cd5d commit bef36ad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ In case you don’t want to download translations from Crowdin (`download_transl
skip_untranslated_files: true
export_only_approved: true
push_translations: true
commit_message: 'New Crowdin translations by Github Action'
# This is the name of the git branch that Crowdin will create when opening a pull request.
# This branch does NOT need to be manually created. It will be created automatically by the action.
localization_branch_name: l10n_crowdin_action
create_pull_request: true
pull_request_title: 'New Crowdin translations'
pull_request_body: 'New Crowdin pull request with translations'
pull_request_labels: 'enhancement, good first issue'
# global options
Expand Down
33 changes: 22 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,67 @@ inputs:
upload_sources:
description: 'Upload sources to Crowdin'
default: 'true'
required: false
required: true

# upload translations options
upload_translations:
description: 'Upload translations to Crowdin'
default: 'false'
required: false
required: true
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: false
required: true
import_eq_suggestions:
description: 'Defines whether to add translation if it is equal to source string in Crowdin project'
default: 'false'
required: false
required: true

# download translations options
download_translations:
description: 'Make pull request of Crowdin translations'
default: 'false'
required: false
required: true
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: false
required: true
skip_untranslated_files:
description: 'Omit downloading not fully downloaded files'
default: 'false'
required: false
required: true
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: false
required: true
push_translations:
description: 'Download translations with pushing to branch'
default: 'true'
required: false
required: true
commit_message:
description: 'Commit message for download translations'
default: 'New Crowdin translations by Github Action'
required: true
localization_branch_name:
description: 'To download translations to the specified version branch'
default: 'l10n_crowdin_action'
required: false
required: true
create_pull_request:
description: 'Create pull request after pushing to branch'
default: 'true'
required: true
pull_request_title:
description: 'The title of the new pull request'
default: 'New Crowdin translations by Github Action'
required: true
pull_request_body:
description: 'The contents of the pull request'
required: false
pull_request_labels:
description: 'To add labels for created pull request'
Expand All @@ -79,7 +90,7 @@ inputs:
dryrun_action:
description: 'Option to preview the list of managed files'
default: 'false'
required: false
required: true

# config options
project_id:
Expand Down
16 changes: 8 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ download_translations() {
}

create_pull_request() {
TITLE="${1}"

LOCALIZATION_BRANCH="${2}"
LOCALIZATION_BRANCH="${1}"

AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json; application/vnd.github.shadow-cat-preview+json"
Expand All @@ -128,7 +126,11 @@ create_pull_request() {
else
echo "CREATE PULL REQUEST"

DATA="{\"title\":\"${TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}"
if [ -n "$INPUT_PULL_REQUEST_BODY" ]; then
BODY=",\"body\":\"${INPUT_PULL_REQUEST_BODY}\""
fi

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}")
CREATED_PULL_URL=$(echo "${PULL_RESPONSE}" | jq '.html_url')

Expand Down Expand Up @@ -159,8 +161,6 @@ create_pull_request() {
push_to_branch() {
LOCALIZATION_BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME}

COMMIT_MESSAGE="New Crowdin translations by Github Action"

REPO_URL="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

echo "CONFIGURATION GIT USER"
Expand All @@ -173,11 +173,11 @@ push_to_branch() {
echo "PUSH TO BRANCH ${LOCALIZATION_BRANCH}"

git add .
git commit -m "${COMMIT_MESSAGE}"
git commit -m "${INPUT_COMMIT_MESSAGE}"
git push --force "${REPO_URL}"

if [ "$INPUT_CREATE_PULL_REQUEST" = true ]; then
create_pull_request "${COMMIT_MESSAGE}" "${LOCALIZATION_BRANCH}"
create_pull_request "${LOCALIZATION_BRANCH}"
fi
else
echo "NOTHING TO COMMIT"
Expand Down

0 comments on commit bef36ad

Please sign in to comment.