Skip to content

Commit

Permalink
Merge pull request #22 from crowdin/issue-21_fix_pr_on_schedule
Browse files Browse the repository at this point in the history
fix bug with PR on schedule
  • Loading branch information
VBeytok authored Jun 11, 2020
2 parents 5044a5d + 919701f commit b387418
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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/github-action@1.0.6
uses: crowdin/github-action@1.0.7
with:
upload_translations: true
download_translations: true
Expand Down
20 changes: 12 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ init_config_options() {

upload_sources() {
echo "UPLOAD SOURCES";
crowdin upload sources ${CONFIG_OPTIONS} ${OPTIONS};
crowdin upload sources "${CONFIG_OPTIONS}" "${OPTIONS}";
}

upload_translations() {
Expand All @@ -81,7 +81,7 @@ upload_translations() {
fi

echo "UPLOAD TRANSLATIONS";
crowdin upload translations ${CONFIG_OPTIONS} ${OPTIONS};
crowdin upload translations "${CONFIG_OPTIONS}" "${OPTIONS}";
}

download_translations() {
Expand All @@ -104,23 +104,27 @@ download_translations() {
fi

echo "DOWNLOAD TRANSLATIONS";
crowdin download ${CONFIG_OPTIONS} ${OPTIONS};
crowdin download "${CONFIG_OPTIONS}" "${OPTIONS}";
}

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

LOCALIZATION_BRANCH="${2}";
BASE_BRANCH=$(jq -r ".repository.default_branch" "$GITHUB_EVENT_PATH");

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";

PULLS_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls";
REPO_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}";
REPO_RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${REPO_URL}");
BASE_BRANCH=$(echo "${REPO_RESPONSE}" | jq --raw-output '.default_branch');

PULLS_URL="${REPO_URL}/pulls";

echo "CHECK IF ISSET SAME PULL REQUEST";
DATA="{\"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}";
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET --data "${DATA}" ${PULLS_URL});
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET --data "${DATA}" "${PULLS_URL}");

PULL_REQUESTS=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref ');

if echo "$PULL_REQUESTS " | grep -q "$LOCALIZATION_BRANCH "; then
Expand All @@ -129,7 +133,7 @@ create_pull_request() {
echo "CREATE PULL REQUEST";

DATA="{\"title\":\"${TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}";
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${DATA}" ${PULLS_URL};
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${DATA}" "${PULLS_URL}";
fi
}

Expand All @@ -144,7 +148,7 @@ push_to_branch() {
git config --global user.email "support+bot@crowdin.com";
git config --global user.name "Crowdin Bot";

git checkout -b ${LOCALIZATION_BRANCH};
git checkout -b "${LOCALIZATION_BRANCH}";

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

0 comments on commit b387418

Please sign in to comment.